diff options
Diffstat (limited to 'hicn-light')
-rw-r--r-- | hicn-light/src/hicn/cli/hicns.c | 2 | ||||
-rw-r--r-- | hicn-light/src/hicn/config/configuration.c | 23 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connection_table.c | 38 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/connection_table.h | 3 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/forwarder.c | 11 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/listener_table.c | 38 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/listener_table.h | 3 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/packet_cache.c | 61 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/packet_cache.h | 14 | ||||
-rw-r--r-- | hicn-light/src/hicn/test/test-configuration.cc | 1 | ||||
-rw-r--r-- | hicn-light/src/hicn/test/test-connection_table.cc | 8 | ||||
-rw-r--r-- | hicn-light/src/hicn/test/test-listener_table.cc | 8 | ||||
-rw-r--r-- | hicn-light/src/hicn/test/test-packet_cache.cc | 33 |
13 files changed, 144 insertions, 99 deletions
diff --git a/hicn-light/src/hicn/cli/hicns.c b/hicn-light/src/hicn/cli/hicns.c index fa668062d..c03fa8599 100644 --- a/hicn-light/src/hicn/cli/hicns.c +++ b/hicn-light/src/hicn/cli/hicns.c @@ -58,7 +58,7 @@ int shell(hc_sock_t *s) { hc_command_t command = {0}; char *pos; - if ((pos = strchr(line, '\n')) != NULL) { + if (line != NULL && (pos = strchr(line, '\n')) != NULL) { *pos = '\0'; } else { fprintf(stderr, "Error while reading command.\n"); diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c index f38c4f22f..b7e931e53 100644 --- a/hicn-light/src/hicn/config/configuration.c +++ b/hicn-light/src/hicn/config/configuration.c @@ -46,6 +46,8 @@ #include <hicn/utils/punting.h> #include <hicn/util/log.h> #include <hicn/face.h> +#include <hicn/util/slab.h> +#include <hicn/util/sstrncpy.h> #include "configuration.h" @@ -63,6 +65,10 @@ (msg)->header.seq_num = (seq_number); \ } while (0); +typedef struct { + char prefix[MAXSZ_HICN_PREFIX]; +} prefix_key_t; + struct configuration_s { const char *fn_config; uint16_t port; @@ -72,7 +78,10 @@ struct configuration_s { const char *logfile; int logfile_fd; bool daemon; + kh_strategy_map_t *strategy_map; + slab_t *prefix_keys; + size_t n_suffixes_per_split; int_manifest_split_strategy_t split_strategy; }; @@ -95,6 +104,7 @@ configuration_t *configuration_create() { #endif configuration_set_loglevel(config, loglevel_from_str(DEFAULT_LOGLEVEL)); config->strategy_map = kh_init_strategy_map(); + config->prefix_keys = slab_create(prefix_key_t, SLAB_INIT_SIZE); config->n_suffixes_per_split = DEFAULT_N_SUFFIXES_PER_SPLIT; config->split_strategy = DEFAULT_DISAGGREGATION_STRATEGY; @@ -104,13 +114,8 @@ configuration_t *configuration_create() { void configuration_free(configuration_t *config) { assert(config); - const char *k_prefix; - unsigned _; - (void)_; - - // Free the strategy hashmap - kh_foreach(config->strategy_map, k_prefix, _, { free((char *)k_prefix); }); kh_destroy_strategy_map(config->strategy_map); + slab_free(config->prefix_keys); free(config); } @@ -202,7 +207,11 @@ bool configuration_get_daemon(const configuration_t *config) { void configuration_set_strategy(configuration_t *config, const char *prefix, strategy_type_t strategy_type) { int res; - khiter_t k = kh_put_strategy_map(config->strategy_map, strdup(prefix), &res); + prefix_key_t *prefix_copy = slab_get(prefix_key_t, config->prefix_keys); + strcpy_s(prefix_copy->prefix, sizeof(prefix_key_t), prefix); + + khiter_t k = + kh_put_strategy_map(config->strategy_map, prefix_copy->prefix, &res); kh_value(config->strategy_map, k) = strategy_type; } diff --git a/hicn-light/src/hicn/core/connection_table.c b/hicn-light/src/hicn/core/connection_table.c index 7bc0e2f4c..a6b114c01 100644 --- a/hicn-light/src/hicn/core/connection_table.c +++ b/hicn-light/src/hicn/core/connection_table.c @@ -19,6 +19,7 @@ */ #include <hicn/util/log.h> +#include <hicn/util/sstrncpy.h> #include "connection.h" #include "connection_table.h" @@ -27,6 +28,10 @@ */ #define DEFAULT_CONNECTION_TABLE_SIZE 64 +typedef struct { + char name[SYMBOLIC_NAME_LEN]; +} name_key_t; + connection_table_t *_connection_table_create(size_t init_size, size_t max_size) { if (init_size == 0) init_size = DEFAULT_CONNECTION_TABLE_SIZE; @@ -38,7 +43,9 @@ connection_table_t *_connection_table_create(size_t init_size, /* Initialize indices */ table->id_by_pair = kh_init_ct_pair(); + table->pair_keys = slab_create(address_pair_t, SLAB_INIT_SIZE); table->id_by_name = kh_init_ct_name(); + table->name_keys = slab_create(name_key_t, SLAB_INIT_SIZE); /* * We start by allocating a reasonably-sized pool, as this will eventually @@ -50,26 +57,20 @@ connection_table_t *_connection_table_create(size_t init_size, } void connection_table_free(connection_table_t *table) { - const char *k_name; - const address_pair_t *k_pair; - unsigned v_conn_id; + unsigned conn_id; + kh_foreach_value(table->id_by_name, conn_id, { + connection_t *connection = connection_table_get_by_id(table, conn_id); + const char *name = connection_get_name(connection); - connection_t *connection; - const char *name; - kh_foreach(table->id_by_name, k_name, v_conn_id, { - connection = connection_table_get_by_id(table, v_conn_id); - name = connection_get_name(connection); INFO("Removing connection %s [%d]", name, connection->fd); connection_finalize(connection); }); - (void)v_conn_id; - kh_foreach(table->id_by_name, k_name, v_conn_id, { free((char *)k_name); }); - kh_foreach(table->id_by_pair, k_pair, v_conn_id, - { free((address_pair_t *)k_pair); }); - kh_destroy_ct_pair(table->id_by_pair); + slab_free(table->pair_keys); kh_destroy_ct_name(table->id_by_name); + slab_free(table->name_keys); + pool_free(table->connections); free(table); } @@ -93,12 +94,15 @@ connection_t *connection_table_allocate(const connection_table_t *table, int rc; // Add in name hash table - khiter_t k = kh_put_ct_name(table->id_by_name, strdup(name), &rc); + name_key_t *name_copy = slab_get(name_key_t, table->name_keys); + strcpy_s(name_copy->name, sizeof(name_key_t), name); + + khiter_t k = kh_put_ct_name(table->id_by_name, name_copy->name, &rc); assert(rc == KH_ADDED || rc == KH_RESET); kh_value(table->id_by_name, k) = (unsigned int)id; // Add in pair hash table - address_pair_t *pair_copy = (address_pair_t *)malloc(sizeof(address_pair_t)); + address_pair_t *pair_copy = slab_get(address_pair_t, table->pair_keys); memcpy(pair_copy, pair, sizeof(address_pair_t)); k = kh_put_ct_pair(table->id_by_pair, pair_copy, &rc); @@ -125,14 +129,14 @@ void connection_table_deallocate(const connection_table_t *table, // Remove from name hash table khiter_t k = kh_get_ct_name(table->id_by_name, name); assert(k != kh_end(table->id_by_name)); - free((char *)kh_key(table->id_by_name, k)); kh_del_ct_name(table->id_by_name, k); + slab_put(table->name_keys, kh_key(table->id_by_name, k)); // Remove from pair hash table k = kh_get_ct_pair(table->id_by_pair, pair); assert(k != kh_end(table->id_by_pair)); - free((address_pair_t *)kh_key(table->id_by_pair, k)); kh_del_ct_pair(table->id_by_pair, k); + slab_put(table->pair_keys, kh_key(table->id_by_pair, k)); assert(kh_size(table->id_by_name) == kh_size(table->id_by_pair)); pool_put(table->connections, conn); diff --git a/hicn-light/src/hicn/core/connection_table.h b/hicn-light/src/hicn/core/connection_table.h index 566443d93..dcfb1e1dd 100644 --- a/hicn-light/src/hicn/core/connection_table.h +++ b/hicn-light/src/hicn/core/connection_table.h @@ -32,6 +32,7 @@ #include <hicn/util/khash.h> #include <hicn/util/hash.h> +#include <hicn/util/slab.h> #include "address_pair.h" #include "connection.h" #include <hicn/util/pool.h> @@ -48,7 +49,9 @@ typedef struct { size_t max_size; kh_ct_pair_t *id_by_pair; + slab_t *pair_keys; kh_ct_name_t *id_by_name; + slab_t *name_keys; connection_t *connections; // pool } connection_table_t; diff --git a/hicn-light/src/hicn/core/forwarder.c b/hicn-light/src/hicn/core/forwarder.c index 72bb22118..d148f845d 100644 --- a/hicn-light/src/hicn/core/forwarder.c +++ b/hicn-light/src/hicn/core/forwarder.c @@ -805,7 +805,7 @@ int _forwarder_forward_aggregated_interest( assert(msgbuf_id_is_valid(msgbuf_id) && msgbuf_get_type(msgbuf) == HICN_PACKET_TYPE_INTEREST); - bool ret = -1; + int ret = -1; fib_entry_t *fib_entry = fib_match_msgbuf(forwarder->fib, msgbuf); if (!fib_entry) goto END; @@ -843,9 +843,8 @@ int _forwarder_forward_aggregated_interest( BITMAP_SIZE * sizeof(hicn_uword)); size_t suffix_index = 0; // Position of suffix in initial manifest - interest_manifest_header_t *manifest; + interest_manifest_header_t *manifest = NULL; size_t payload_size; - int ret; while (suffix_index < total_suffixes) { // If more than one sub-manifest, // clone original interest manifest and update suffix @@ -869,9 +868,9 @@ int _forwarder_forward_aggregated_interest( // Update manifest bitmap in current msgbuf - ret = + int ret = _forwarder_get_interest_manifest(msgbuf, &manifest, &payload_size); - assert(ret == 0); + _ASSERT(ret == 0); memcpy(manifest->request_bitmap, curr_bitmap, BITMAP_SIZE * sizeof(hicn_uword)); WITH_TRACE({ @@ -1088,7 +1087,7 @@ static ssize_t forwarder_process_interest(forwarder_t *forwarder, pkt_cache_save_suffixes_for_prefix( forwarder->pkt_cache, hicn_name_get_prefix(msgbuf_get_name(msgbuf))); - if (!int_manifest_header) + if (ret == -1) return forwarder_process_single_interest(forwarder, msgbuf_pool, msgbuf, msgbuf_id); return forwarder_process_aggregated_interest(forwarder, int_manifest_header, diff --git a/hicn-light/src/hicn/core/listener_table.c b/hicn-light/src/hicn/core/listener_table.c index c130399a5..4a0f74a13 100644 --- a/hicn-light/src/hicn/core/listener_table.c +++ b/hicn-light/src/hicn/core/listener_table.c @@ -19,6 +19,7 @@ */ #include <hicn/util/log.h> +#include <hicn/util/sstrncpy.h> #include "listener_table.h" #include "listener.h" @@ -27,6 +28,10 @@ */ #define DEFAULT_LISTENER_TABLE_SIZE 64 +typedef struct { + char name[SYMBOLIC_NAME_LEN]; +} name_key_t; + listener_table_t *_listener_table_create(size_t init_size, size_t max_size) { if (init_size == 0) init_size = DEFAULT_LISTENER_TABLE_SIZE; @@ -37,7 +42,9 @@ listener_table_t *_listener_table_create(size_t init_size, size_t max_size) { /* Initialize indices */ table->id_by_name = kh_init_lt_name(); + table->name_keys = slab_create(name_key_t, SLAB_INIT_SIZE); table->id_by_key = kh_init_lt_key(); + table->listener_keys = slab_create(listener_key_t, SLAB_INIT_SIZE); /* * We start by allocating a reasonably-sized pool, as this will eventually @@ -49,25 +56,19 @@ listener_table_t *_listener_table_create(size_t init_size, size_t max_size) { } void listener_table_free(listener_table_t *table) { - const char *k_name; - const listener_key_t *k_key; - unsigned v; - - listener_t *listener; - const char *name; - kh_foreach(table->id_by_key, k_key, v, { - listener = listener_table_get_by_id(table, v); - name = listener_get_name(listener); + unsigned listener_id; + kh_foreach_value(table->id_by_key, listener_id, { + listener_t *listener = listener_table_get_by_id(table, listener_id); + const char *name = listener_get_name(listener); INFO("Removing listener %s [%d]", name, listener->fd); listener_finalize(listener); }); - (void)v; - kh_foreach(table->id_by_name, k_name, v, { free((char *)k_name); }); - kh_foreach(table->id_by_key, k_key, v, { free((listener_key_t *)k_key); }); - kh_destroy_lt_name(table->id_by_name); + slab_free(table->name_keys); kh_destroy_lt_key(table->id_by_key); + slab_free(table->listener_keys); + pool_free(table->listeners); free(table); } @@ -83,12 +84,15 @@ listener_t *listener_table_allocate(const listener_table_t *table, int rc; // Add in name hash table - khiter_t k = kh_put_lt_name(table->id_by_name, strdup(name), &rc); + name_key_t *name_copy = slab_get(name_key_t, table->name_keys); + strcpy_s(name_copy->name, sizeof(name_key_t), name); + + khiter_t k = kh_put_lt_name(table->id_by_name, name_copy->name, &rc); assert(rc == KH_ADDED || rc == KH_RESET); kh_value(table->id_by_name, k) = (unsigned int)id; // Add in key hash table - listener_key_t *key_copy = (listener_key_t *)malloc(sizeof(listener_key_t)); + listener_key_t *key_copy = slab_get(listener_key_t, table->listener_keys); memcpy(key_copy, key, sizeof(listener_key_t)); k = kh_put_lt_key(table->id_by_key, key_copy, &rc); @@ -107,14 +111,14 @@ void listener_table_deallocate(const listener_table_t *table, // Remove from name hash table khiter_t k = kh_get_lt_name(table->id_by_name, name); assert(k != kh_end(table->id_by_name)); - free((char *)kh_key(table->id_by_name, k)); kh_del_lt_name(table->id_by_name, k); + slab_put(table->name_keys, kh_key(table->id_by_name, k)); // Remove from key hash table k = kh_get_lt_key(table->id_by_key, key); assert(k != kh_end(table->id_by_key)); - free((listener_key_t *)kh_key(table->id_by_key, k)); kh_del_lt_key(table->id_by_key, k); + slab_put(table->listener_keys, kh_key(table->id_by_key, k)); assert(kh_size(table->id_by_name) == kh_size(table->id_by_key)); pool_put(table->listeners, listener); diff --git a/hicn-light/src/hicn/core/listener_table.h b/hicn-light/src/hicn/core/listener_table.h index 27c5daa04..062d1748e 100644 --- a/hicn-light/src/hicn/core/listener_table.h +++ b/hicn-light/src/hicn/core/listener_table.h @@ -32,6 +32,7 @@ #include <hicn/util/khash.h> #include <hicn/util/hash.h> +#include <hicn/util/slab.h> #include "address.h" #include "listener.h" #include <hicn/util/pool.h> @@ -48,7 +49,9 @@ typedef struct { size_t max_size; kh_lt_key_t *id_by_key; + slab_t *listener_keys; kh_lt_name_t *id_by_name; + slab_t *name_keys; listener_t *listeners; // pool } listener_table_t; diff --git a/hicn-light/src/hicn/core/packet_cache.c b/hicn-light/src/hicn/core/packet_cache.c index 9d0b041c3..7fa18b48f 100644 --- a/hicn-light/src/hicn/core/packet_cache.c +++ b/hicn-light/src/hicn/core/packet_cache.c @@ -84,13 +84,9 @@ const char *_pkt_cache_verdict_str[] = { * Free the two level packet cache structure (helper) */ void _prefix_map_free(kh_pkt_cache_prefix_t *prefix_to_suffixes) { - const hicn_name_prefix_t *key; - kh_pkt_cache_suffix_t *value; - kh_foreach(prefix_to_suffixes, key, value, { - //(void)key; - free((hicn_name_prefix_t *)key); - kh_destroy_pkt_cache_suffix(value); - }); + kh_pkt_cache_suffix_t *suffix; + kh_foreach_value(prefix_to_suffixes, suffix, + { kh_destroy_pkt_cache_suffix(suffix); }); kh_destroy_pkt_cache_prefix(prefix_to_suffixes); } @@ -99,7 +95,7 @@ void _prefix_map_free(kh_pkt_cache_prefix_t *prefix_to_suffixes) { */ kh_pkt_cache_suffix_t *_get_suffixes(kh_pkt_cache_prefix_t *prefix_to_suffixes, const hicn_name_prefix_t *prefix, - bool create) { + bool create, slab_t *prefix_keys) { khiter_t k = kh_get_pkt_cache_prefix(prefix_to_suffixes, prefix); /* Return suffixes if found... */ @@ -114,8 +110,8 @@ kh_pkt_cache_suffix_t *_get_suffixes(kh_pkt_cache_prefix_t *prefix_to_suffixes, */ kh_pkt_cache_suffix_t *suffixes = kh_init_pkt_cache_suffix(); - hicn_name_prefix_t *prefix_copy = malloc(sizeof(hicn_name_prefix_t)); - *prefix_copy = *prefix; + hicn_name_prefix_t *prefix_copy = slab_get(hicn_name_prefix_t, prefix_keys); + memcpy(prefix_copy, prefix, sizeof(hicn_name_prefix_t)); int rc; k = kh_put_pkt_cache_prefix(prefix_to_suffixes, prefix_copy, &rc); @@ -129,8 +125,9 @@ kh_pkt_cache_suffix_t *_get_suffixes(kh_pkt_cache_prefix_t *prefix_to_suffixes, */ void _remove_suffix(kh_pkt_cache_prefix_t *prefixes, const hicn_name_prefix_t *prefix, - const hicn_name_suffix_t suffix) { - kh_pkt_cache_suffix_t *suffixes = _get_suffixes(prefixes, prefix, false); + const hicn_name_suffix_t suffix, slab_t *prefix_keys) { + kh_pkt_cache_suffix_t *suffixes = + _get_suffixes(prefixes, prefix, false, prefix_keys); assert(suffixes != NULL); khiter_t k = kh_get_pkt_cache_suffix(suffixes, suffix); @@ -159,8 +156,10 @@ void __add_suffix(kh_pkt_cache_suffix_t *suffixes, hicn_name_suffix_t suffix, */ void _add_suffix(kh_pkt_cache_prefix_t *prefixes, const hicn_name_prefix_t *prefix, - const hicn_name_suffix_t suffix, unsigned val) { - kh_pkt_cache_suffix_t *suffixes = _get_suffixes(prefixes, prefix, true); + const hicn_name_suffix_t suffix, unsigned val, + slab_t *prefix_keys) { + kh_pkt_cache_suffix_t *suffixes = + _get_suffixes(prefixes, prefix, true, prefix_keys); assert(suffixes != NULL); __add_suffix(suffixes, suffix, val); @@ -184,9 +183,10 @@ unsigned __get_suffix(kh_pkt_cache_suffix_t *suffixes, unsigned _get_suffix(kh_pkt_cache_prefix_t *prefixes, const hicn_name_prefix_t *prefix, - hicn_name_suffix_t suffix) { + hicn_name_suffix_t suffix, slab_t *prefix_keys) { /* create is false as this function is always called by lookup */ - kh_pkt_cache_suffix_t *suffixes = _get_suffixes(prefixes, prefix, false); + kh_pkt_cache_suffix_t *suffixes = + _get_suffixes(prefixes, prefix, false, prefix_keys); if (!suffixes) { return HICN_INVALID_SUFFIX; } @@ -197,11 +197,11 @@ unsigned _get_suffix(kh_pkt_cache_prefix_t *prefixes, * Lookup in both the first and second levels of the packet cache (helper) */ unsigned _get_suffix_from_name(kh_pkt_cache_prefix_t *prefixes, - const hicn_name_t *name) { + const hicn_name_t *name, slab_t *prefix_keys) { const hicn_name_prefix_t *prefix = hicn_name_get_prefix(name); const hicn_name_suffix_t suffix = hicn_name_get_suffix(name); - return _get_suffix(prefixes, prefix, suffix); + return _get_suffix(prefixes, prefix, suffix, prefix_keys); } void pkt_cache_save_suffixes_for_prefix(pkt_cache_t *pkt_cache, @@ -216,8 +216,9 @@ void pkt_cache_save_suffixes_for_prefix(pkt_cache_t *pkt_cache, // Update cached prefix information pkt_cache->cached_prefix = *prefix; pkt_cache->cached_suffixes = - _get_suffixes(pkt_cache->prefix_to_suffixes, prefix, true); // XXX - // + _get_suffixes(pkt_cache->prefix_to_suffixes, prefix, true, + pkt_cache->prefix_keys); // XXX + // } void pkt_cache_reset_suffixes_for_prefix(pkt_cache_t *pkt_cache) { @@ -237,6 +238,7 @@ pkt_cache_t *pkt_cache_create(size_t cs_size) { if (!pkt_cache->cs) return NULL; pkt_cache->prefix_to_suffixes = kh_init_pkt_cache_prefix(); + pkt_cache->prefix_keys = slab_create(hicn_name_prefix_t, SLAB_INIT_SIZE); pool_init(pkt_cache->entries, DEFAULT_PKT_CACHE_SIZE, 0); pkt_cache->cached_prefix = HICN_NAME_PREFIX_EMPTY; @@ -250,6 +252,7 @@ void pkt_cache_free(pkt_cache_t *pkt_cache) { // Free prefix hash table and pool _prefix_map_free(pkt_cache->prefix_to_suffixes); + slab_free(pkt_cache->prefix_keys); pool_free(pkt_cache->entries); // Free PIT and CS @@ -261,8 +264,10 @@ void pkt_cache_free(pkt_cache_t *pkt_cache) { kh_pkt_cache_suffix_t *pkt_cache_get_suffixes(const pkt_cache_t *pkt_cache, const hicn_name_prefix_t *prefix, - bool create) { - return _get_suffixes(pkt_cache->prefix_to_suffixes, prefix, create); + bool create, + slab_t *prefix_keys) { + return _get_suffixes(pkt_cache->prefix_to_suffixes, prefix, create, + prefix_keys); } pkt_cache_entry_t *pkt_cache_allocate(pkt_cache_t *pkt_cache) { @@ -286,7 +291,8 @@ void pkt_cache_add_to_index(const pkt_cache_t *pkt_cache, (unsigned int)id); } else { _add_suffix(pkt_cache->prefix_to_suffixes, hicn_name_get_prefix(name), - hicn_name_get_suffix(name), (unsigned int)id); + hicn_name_get_suffix(name), (unsigned int)id, + pkt_cache->prefix_keys); } } @@ -296,7 +302,7 @@ void pkt_cache_add_to_index(const pkt_cache_t *pkt_cache, void pkt_cache_remove_from_index(const pkt_cache_t *pkt_cache, const hicn_name_t *name) { _remove_suffix(pkt_cache->prefix_to_suffixes, hicn_name_get_prefix(name), - hicn_name_get_suffix(name)); + hicn_name_get_suffix(name), pkt_cache->prefix_keys); // TODO #if 0 @@ -321,7 +327,8 @@ pkt_cache_entry_t *pkt_cache_lookup(pkt_cache_t *pkt_cache, index = __get_suffix(pkt_cache->cached_suffixes, hicn_name_get_suffix(name)); } else { - index = _get_suffix_from_name(pkt_cache->prefix_to_suffixes, name); + index = _get_suffix_from_name(pkt_cache->prefix_to_suffixes, name, + pkt_cache->prefix_keys); } if (index == HICN_INVALID_SUFFIX) { @@ -364,7 +371,7 @@ void pkt_cache_cs_remove_entry(pkt_cache_t *pkt_cache, pkt_cache_entry_t *entry, // XXX const hicn_name_t *name = msgbuf_get_name(msgbuf); _remove_suffix(pkt_cache->prefix_to_suffixes, hicn_name_get_prefix(&entry->name), - hicn_name_get_suffix(&entry->name)); + hicn_name_get_suffix(&entry->name), pkt_cache->prefix_keys); // Do not update the LRU cache for evicted entries if (!is_evicted) cs_vft[pkt_cache->cs->type]->remove_entry(pkt_cache, entry); @@ -391,7 +398,7 @@ void pkt_cache_pit_remove_entry(pkt_cache_t *pkt_cache, const hicn_name_t *name = &entry->name; _remove_suffix(pkt_cache->prefix_to_suffixes, hicn_name_get_prefix(name), - hicn_name_get_suffix(name)); + hicn_name_get_suffix(name), pkt_cache->prefix_keys); pool_put(pkt_cache->entries, entry); diff --git a/hicn-light/src/hicn/core/packet_cache.h b/hicn-light/src/hicn/core/packet_cache.h index dcbc20c7d..1abdc57c2 100644 --- a/hicn-light/src/hicn/core/packet_cache.h +++ b/hicn-light/src/hicn/core/packet_cache.h @@ -41,6 +41,7 @@ #define HICNLIGHT_PACKET_CACHE_H #include <hicn/util/khash.h> +#include <hicn/util/slab.h> #include "content_store.h" #include "pit.h" #include "msgbuf_pool.h" @@ -112,6 +113,7 @@ typedef struct { cs_t *cs; pkt_cache_entry_t *entries; kh_pkt_cache_prefix_t *prefix_to_suffixes; + slab_t *prefix_keys; // Cached prefix info to avoid double lookups, // used for both single interest speculation and interest manifest @@ -455,19 +457,19 @@ unsigned __get_suffix(kh_pkt_cache_suffix_t *suffixes, hicn_name_suffix_t suffix); unsigned _get_suffix(kh_pkt_cache_prefix_t *prefixes, const hicn_name_prefix_t *prefix, - hicn_name_suffix_t suffix); + hicn_name_suffix_t suffix, slab_t *prefix_keys); void __add_suffix(kh_pkt_cache_suffix_t *suffixes, hicn_name_suffix_t suffix, unsigned val); void _add_suffix(kh_pkt_cache_prefix_t *prefixes, - const hicn_name_prefix_t *prefix, hicn_name_suffix_t suffix, - unsigned val); + const hicn_name_prefix_t *prefix, + const hicn_name_suffix_t suffix, unsigned val, slab_t *slab); void _remove_suffix(kh_pkt_cache_prefix_t *prefixes, - const hicn_name_prefix_t *prefix, - hicn_name_suffix_t suffix); + const hicn_name_prefix_t *prefix, hicn_name_suffix_t suffix, + slab_t *slab); void _prefix_map_free(kh_pkt_cache_prefix_t *prefix_to_suffixes); kh_pkt_cache_suffix_t *_get_suffixes(kh_pkt_cache_prefix_t *prefix_to_suffixes, const hicn_name_prefix_t *prefix, - bool create); + bool create, slab_t *prefix_keys); #endif /************** Content Store *****************************/ diff --git a/hicn-light/src/hicn/test/test-configuration.cc b/hicn-light/src/hicn/test/test-configuration.cc index b631bb20b..2d3b5329f 100644 --- a/hicn-light/src/hicn/test/test-configuration.cc +++ b/hicn-light/src/hicn/test/test-configuration.cc @@ -69,6 +69,7 @@ TEST_F(ConfigurationTest, SetLogParameters) { EXPECT_EQ(log_file, LOG_FILE); int write_fd = configuration_get_logfile_fd(config); EXPECT_NE(write_fd, -1); + configuration_flush_log(); } TEST_F(ConfigurationTest, SetStrategyParameter) { diff --git a/hicn-light/src/hicn/test/test-connection_table.cc b/hicn-light/src/hicn/test/test-connection_table.cc index 171921b53..6723d0ff1 100644 --- a/hicn-light/src/hicn/test/test-connection_table.cc +++ b/hicn-light/src/hicn/test/test-connection_table.cc @@ -28,14 +28,18 @@ extern "C" { #define WITH_TESTS #include <hicn/core/connection_table.h> #include <hicn/util/log.h> +#include <hicn/validation.h> } -#define CONNECTION_NAME "connection_name_test" -#define CONNECTION_NAME_2 "connection_name_test_2" +#define CONNECTION_NAME "conn_name" +#define CONNECTION_NAME_2 "conn_name_2" class ConnectionTableTest : public ::testing::Test { protected: ConnectionTableTest() { + assert(is_symbolic_name(CONNECTION_NAME, SYMBOLIC_NAME_LEN)); + assert(is_symbolic_name(CONNECTION_NAME_2, SYMBOLIC_NAME_LEN)); + log_conf.log_level = LOG_WARN; conn_table_ = connection_table_create(); diff --git a/hicn-light/src/hicn/test/test-listener_table.cc b/hicn-light/src/hicn/test/test-listener_table.cc index f4af02ee1..6bd2a6ab7 100644 --- a/hicn-light/src/hicn/test/test-listener_table.cc +++ b/hicn-light/src/hicn/test/test-listener_table.cc @@ -28,14 +28,18 @@ extern "C" { #define WITH_TESTS #include <hicn/core/listener_table.h> #include <hicn/util/log.h> +#include <hicn/validation.h> } -#define LISTENER_NAME "listener_name_test" -#define LISTENER_NAME_2 "listener_name_test_2" +#define LISTENER_NAME "listener_name" +#define LISTENER_NAME_2 "listener_name_2" class ListenerTableTest : public ::testing::Test { protected: ListenerTableTest() { + assert(is_symbolic_name(LISTENER_NAME, SYMBOLIC_NAME_LEN)); + assert(is_symbolic_name(LISTENER_NAME_2, SYMBOLIC_NAME_LEN)); + log_conf.log_level = LOG_INFO; listener_table_ = listener_table_create(); diff --git a/hicn-light/src/hicn/test/test-packet_cache.cc b/hicn-light/src/hicn/test/test-packet_cache.cc index 76fdb4516..37f4fe985 100644 --- a/hicn-light/src/hicn/test/test-packet_cache.cc +++ b/hicn-light/src/hicn/test/test-packet_cache.cc @@ -96,25 +96,26 @@ class PacketCacheTest : public ::testing::Test { TEST_F(PacketCacheTest, LowLevelOperations) { kh_pkt_cache_prefix_t *prefix_to_suffixes = kh_init_pkt_cache_prefix(); 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); + _add_suffix(prefix_to_suffixes, prefix, 1, 11, pkt_cache->prefix_keys); + _add_suffix(prefix_to_suffixes, prefix, 2, 22, pkt_cache->prefix_keys); - unsigned id = _get_suffix(prefix_to_suffixes, prefix, 1); + unsigned id = + _get_suffix(prefix_to_suffixes, prefix, 1, pkt_cache->prefix_keys); EXPECT_EQ(id, 11UL); - id = _get_suffix(prefix_to_suffixes, prefix, 2); + id = _get_suffix(prefix_to_suffixes, prefix, 2, pkt_cache->prefix_keys); EXPECT_EQ(id, 22UL); - id = _get_suffix(prefix_to_suffixes, prefix, 5); + id = _get_suffix(prefix_to_suffixes, prefix, 5, pkt_cache->prefix_keys); EXPECT_EQ(id, HICN_INVALID_SUFFIX); - _add_suffix(prefix_to_suffixes, prefix, 5, 55); - id = _get_suffix(prefix_to_suffixes, prefix, 5); + _add_suffix(prefix_to_suffixes, prefix, 5, 55, pkt_cache->prefix_keys); + id = _get_suffix(prefix_to_suffixes, prefix, 5, pkt_cache->prefix_keys); 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); + _remove_suffix(prefix_to_suffixes, prefix, 2, pkt_cache->prefix_keys); + _add_suffix(prefix_to_suffixes, prefix, 2, 222, pkt_cache->prefix_keys); + id = _get_suffix(prefix_to_suffixes, prefix, 2, pkt_cache->prefix_keys); EXPECT_EQ(id, 222UL); _prefix_map_free(prefix_to_suffixes); @@ -585,13 +586,15 @@ TEST_F(PacketCacheTest, PerformanceDoubleLookup) { for (int seq = 0; seq < N_OPS; seq++) { 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)); + hicn_name_get_suffix(&tmp), hicn_name_get_suffix(&tmp), + pkt_cache->prefix_keys); } // Read from hash table for (int seq = 0; seq < N_OPS; seq++) { hicn_name_set_suffix(&tmp, seq); - _get_suffix(prefix_to_suffixes, hicn_name_get_prefix(&tmp), seq); + _get_suffix(prefix_to_suffixes, hicn_name_get_prefix(&tmp), seq, + pkt_cache->prefix_keys); } _prefix_map_free(prefix_to_suffixes); @@ -605,7 +608,8 @@ TEST_F(PacketCacheTest, PerformanceCachedLookup) { 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, hicn_name_get_prefix(&tmp), true); + _get_suffixes(prefix_to_suffixes, hicn_name_get_prefix(&tmp), true, + pkt_cache->prefix_keys); // Add to hash table for (int seq = 0; seq < N_OPS; seq++) { @@ -638,7 +642,8 @@ 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, hicn_name_get_prefix(&tmp), true); + _get_suffixes(prefix_to_suffixes, hicn_name_get_prefix(&tmp), true, + pkt_cache->prefix_keys); // Add to hash table for (int seq = 0; seq < N_OPS; seq++) { |