}
/*
- * Allocate new node in protocol slab
+ * Allocate new node in protocol linpool
*/
static struct trie_node *
-create_new_node(slab *trie_slab)
+create_new_node(linpool *trie_pool)
{
- return sl_allocz(trie_slab);
+ return lp_allocz(trie_pool, sizeof(struct trie_node));
}
/*
- * Mark appropriate child of parent node as NULL and free @node
+ * Mark appropriate child of parent node as NULL
*/
static void
remove_node(struct trie_node *node)
else
bug("Invalid child pointer");
}
-
- sl_free(node);
}
/*
* Insert prefix in @addr to prefix trie with beginning at @root and assign @bucket to this prefix
*/
static void
-trie_insert_prefix_ip4(const struct net_addr_ip4 *addr, struct trie_node *const root, struct aggregator_bucket *bucket, slab *trie_slab)
+trie_insert_prefix_ip4(const struct net_addr_ip4 *addr, struct trie_node *const root, struct aggregator_bucket *bucket, linpool *trie_pool)
{
assert(addr != NULL);
assert(bucket != NULL);
assert(root != NULL);
- assert(trie_slab != NULL);
+ assert(trie_pool != NULL);
struct trie_node *node = root;
if (!node->child[bit])
{
- struct trie_node *new = create_new_node(trie_slab);
+ struct trie_node *new = create_new_node(trie_pool);
new->parent = node;
node->child[bit] = new;
new->depth = new->parent->depth + 1;
}
static void
-trie_insert_prefix_ip6(const struct net_addr_ip6 *addr, struct trie_node * const root, struct aggregator_bucket *bucket, slab *trie_slab)
+trie_insert_prefix_ip6(const struct net_addr_ip6 *addr, struct trie_node * const root, struct aggregator_bucket *bucket, linpool *trie_pool)
{
assert(addr != NULL);
assert(bucket != NULL);
assert(root != NULL);
- assert(trie_slab != NULL);
+ assert(trie_pool != NULL);
struct trie_node *node = root;
if (!node->child[bit])
{
- struct trie_node *new = create_new_node(trie_slab);
+ struct trie_node *new = create_new_node(trie_pool);
new->parent = node;
node->child[bit] = new;
new->depth = new->parent->depth + 1;
}
static void
-first_pass_new(struct trie_node *node, slab *trie_slab)
+first_pass_new(struct trie_node *node, linpool *trie_pool)
{
assert(node != NULL);
- assert(trie_slab != NULL);
+ assert(trie_pool != NULL);
if (is_leaf(node))
{
{
if (!node->child[i])
{
- struct trie_node *new = create_new_node(trie_slab);
+ struct trie_node *new = create_new_node(trie_pool);
new->parent = node;
new->bucket = node->bucket;
new->depth = node->depth + 1;
}
if (node->child[0])
- first_pass_new(node->child[0], trie_slab);
+ first_pass_new(node->child[0], trie_pool);
if (node->child[1])
- first_pass_new(node->child[1], trie_slab);
+ first_pass_new(node->child[1], trie_pool);
node->bucket = NULL;
}
* First pass of Optimal Route Table Construction (ORTC) algorithm
*/
static void
-first_pass(struct trie_node *node, slab *trie_slab)
+first_pass(struct trie_node *node, linpool *trie_pool)
{
bug("");
assert(node != NULL);
- assert(trie_slab != NULL);
+ assert(trie_pool != NULL);
if (!node->parent)
assert(node->bucket != NULL);
{
if (!node->child[i])
{
- struct trie_node *new = create_new_node(trie_slab);
+ struct trie_node *new = create_new_node(trie_pool);
new->parent = node;
new->bucket = get_ancestor_bucket(new);
node->child[i] = new;
}
/* Preorder traversal */
- first_pass(node->child[0], trie_slab);
- first_pass(node->child[1], trie_slab);
+ first_pass(node->child[0], trie_pool);
+ first_pass(node->child[1], trie_pool);
}
static int
if (uptr->n.type == NET_IP4)
{
const struct net_addr_ip4 *addr = &uptr->ip4;
- trie_insert_prefix_ip4(addr, p->root, bucket, p->trie_slab);
+ trie_insert_prefix_ip4(addr, p->root, bucket, p->trie_pool);
log("INSERT %N", addr);
p->before_count++;
}
else if (uptr->n.type == NET_IP6)
{
const struct net_addr_ip6 *addr = &uptr->ip6;
- trie_insert_prefix_ip6(addr, p->root, bucket, p->trie_slab);
+ trie_insert_prefix_ip6(addr, p->root, bucket, p->trie_pool);
log("INSERT %N", addr);
p->before_count++;
}
log("====PREFIXES BEFORE ====");
log("====FIRST PASS====");
- first_pass_new(p->root, p->trie_slab);
+ first_pass_new(p->root, p->trie_pool);
first_pass_after_check(p->root);
print_prefixes(p->root, p->addr_type);
return;
/* Evaluate route attributes. */
- struct aggregator_bucket *tmp_bucket = sl_allocz(p->bucket_slab);
+ struct aggregator_bucket *tmp_bucket = lp_allocz(p->bucket_pool, sizeof(*tmp_bucket));
for (uint val_idx = 0; val_idx < p->aggr_on_count; val_idx++)
{
/* Find the existing bucket */
if (new_bucket = HASH_FIND(p->buckets, AGGR_BUCK, tmp_bucket))
- sl_free(tmp_bucket);
+ ;
else
{
new_bucket = tmp_bucket;
log("new rte: %p, net: %p, src: %p, hash: %x", new, new->net, new->src, aggr_route_hash(new));
/* Insert the new route into the bucket */
- struct aggregator_route *arte = sl_alloc(p->route_slab);
+ struct aggregator_route *arte = lp_allocz(p->route_pool, sizeof(*arte));
*arte = (struct aggregator_route) {
.bucket = new_bucket,
.rte = *new,
old_bucket->count--;
HASH_REMOVE2(p->routes, AGGR_RTE, p->p.pool, old_route);
rta_free(old_route->rte.attrs);
- sl_free(old_route);
}
if (p->net_present != 0)
{
ASSERT_DIE(!old_bucket->rte && !old_bucket->count);
HASH_REMOVE2(p->buckets, AGGR_BUCK, p->p.pool, old_bucket);
- sl_free(old_bucket);
}
assert(p->root != NULL);
p->addr_type = p->src->table->addr_type;
- p->bucket_slab = sl_new(P->pool, sizeof(struct aggregator_bucket) + AGGR_DATA_MEMSIZE);
+ p->bucket_pool = lp_new(P->pool);
HASH_INIT(p->buckets, P->pool, AGGR_BUCK_ORDER);
- p->route_slab = sl_new(P->pool, sizeof(struct aggregator_route));
+ p->route_pool = lp_new(P->pool);
HASH_INIT(p->routes, P->pool, AGGR_RTE_ORDER);
p->reload_buckets = (event) {
.data = p,
};
- p->trie_slab = sl_new(p->p.pool, sizeof(struct trie_node));
- p->root = create_new_node(p->trie_slab);
+ p->trie_pool = lp_new(P->pool);
+ p->root = create_new_node(p->trie_pool);
p->root->depth = 1;
p->aggr_done = 0;
struct rta rta = { 0 };
/* Allocate bucket for root node */
- struct aggregator_bucket *new_bucket = sl_allocz(p->bucket_slab);
+ struct aggregator_bucket *new_bucket = lp_allocz(p->bucket_pool, sizeof(*new_bucket));
u64 haux = 0;
mem_hash_init(&haux);
new_bucket->hash = mem_hash_value(&haux);
- struct aggregator_route *arte = sl_alloc(p->route_slab);
+ struct aggregator_route *arte = lp_allocz(p->route_pool, sizeof(*arte));
*arte = (struct aggregator_route) {
.bucket = new_bucket,
b->count--;
HASH_REMOVE(p->routes, AGGR_RTE, arte);
rta_free(arte->rte.attrs);
- sl_free(arte);
}
ASSERT_DIE(b->count == 0);
HASH_REMOVE(p->buckets, AGGR_BUCK, b);
- sl_free(b);
}
HASH_WALK_END;
settle_cancel(&p->aggr_timer);
assert(p->root != NULL);
- delete_trie(p->root);
p->root = NULL;
return PS_DOWN;