extern linpool *rte_update_pool;
-static int total_nodes;
-static int prefix_nodes;
-static int imaginary_nodes;
-static int additional_nodes;
-static int removed_nodes;
-static int one_child_nodes_1;
-static int one_child_nodes_2;
-
static const char *px_origin_str[] = {
[FILLER] = "filler",
[ORIGINAL] = "original",
create_new_node(linpool *trie_pool)
{
struct trie_node *node = lp_allocz(trie_pool, sizeof(*node));
- total_nodes++;
return node;
}
node->parent = NULL;
memset(node, 0xfe, sizeof(*node));
- removed_nodes++;
}
/*
};
node->child[bit] = new;
- prefix_nodes++;
}
node = node->child[bit];
};
node->child[bit] = new;
- prefix_nodes++;
}
node = node->child[bit];
return node;
}
-static void
-before_check(const struct trie_node *node)
-{
- assert(node != NULL);
-
- if (node->original_bucket)
- assert(IN_FIB == node->status);
- else
- assert(NON_FIB == node->status);
-
- if (node->child[0])
- before_check(node->child[0]);
-
- if (node->child[1])
- before_check(node->child[1]);
-}
-
static void
find_subtree_prefix(const struct trie_node *target, struct net_addr_ip4 *addr)
{
if (!node->original_bucket)
node->original_bucket = node->parent->original_bucket;
- for (int i = 0; i < 2; i++)
- {
- if (!node->child[i])
- imaginary_nodes++;
- }
-
if (node->child[0])
first_pass(node->child[0]);
left = &imaginary_node;
else
bug("Node does not have only one child");
-
- one_child_nodes_1++;
}
assert(left != NULL && right != NULL);
node->child[0] = new;
else
bug("Node does not have only one child");
-
- additional_nodes++;
}
-
- one_child_nodes_2++;
}
/* Preorder traversal */
log("==== TRIE END ====");
}
-static void
-get_trie_prefix_count_helper(const struct trie_node *node, int *count)
-{
- if (is_leaf(node))
- {
- *count += 1;
- return;
- }
-
- if (node->child[0])
- get_trie_prefix_count_helper(node->child[0], count);
-
- if (node->child[1])
- get_trie_prefix_count_helper(node->child[1], count);
-}
-
-static int
-get_trie_prefix_count(const struct trie_node *node)
-{
- int count = 0;
- get_trie_prefix_count_helper(node, &count);
-
- return count;
-}
-
-static void
-get_trie_depth_helper(const struct trie_node *node, int *result, int depth)
-{
- if (is_leaf(node))
- {
- if (depth > *result)
- *result = depth;
-
- return;
- }
-
- if (node->child[0])
- get_trie_depth_helper(node->child[0], result, depth + 1);
-
- if (node->child[1])
- get_trie_depth_helper(node->child[1], result, depth + 1);
-}
-
-static int
-get_trie_depth(const struct trie_node *node)
-{
- int result = 0;
- get_trie_depth_helper(node, &result, 0);
-
- return result;
-}
-
-static void
-get_trie_node_count_helper(const struct trie_node *node, int *count)
-{
- *count += 1;
-
- if (node->child[0])
- get_trie_node_count_helper(node->child[0], count);
-
- if (node->child[1])
- get_trie_node_count_helper(node->child[1], count);
-}
-
-static int
-get_trie_node_count(const struct trie_node *root)
-{
- int count = 0;
- get_trie_node_count_helper(root, &count);
- return count;
-}
-
static void
print_prefixes_ip4_helper(struct net_addr_ip4 *addr, const struct trie_node *node, int depth)
{
assert(node != NULL);
assert(node->status == IN_FIB || node->status == NON_FIB);
- if (is_leaf(node))
- {
- if (IN_FIB == node->status)
- p->leaves++;
- }
-
/* Internal node with assigned bucket */
if (IN_FIB == node->status)
{
create_route_ip4(p, node->selected_bucket, addr);
*count += 1;
- p->internal_nodes++;
}
if (node->child[0])
assert(node != NULL);
assert(node->status == IN_FIB || node->status == NON_FIB);
- if (is_leaf(node))
- {
- if (IN_FIB == node->status)
- p->leaves++;
- }
-
/* Internal node with assigned bucket */
if (IN_FIB == node->status)
{
create_route_ip6(p, node->selected_bucket, addr);
*count += 1;
- p->internal_nodes++;
}
if (node->child[0])
print_prefixes(p->root, p->addr_type);
}
- before_check(p->root);
-
times_update(&main_timeloop);
log("==== FIRST PASS ====");
first_pass(p->root);
log("%d prefixes before aggregation", p->before_count);
log("%d prefixes after aggregation", p->after_count);
- log("%d internal nodes with bucket", p->internal_nodes);
- log("%d leaves with bucket", p->leaves);
-
- log("");
- log("%d nodes in total", total_nodes);
- log("%d prefix nodes", prefix_nodes);
- log("%d imaginary nodes", imaginary_nodes);
- log("%d nodes added in the third pass", additional_nodes);
- log("%d nodes removed", removed_nodes);
- log("%d nodes left", get_trie_node_count(p->root));
- log("%d one-child nodes in the second pass", one_child_nodes_1);
- log("%d one-child nodes in the third pass", one_child_nodes_2);
-
- total_nodes = prefix_nodes = imaginary_nodes = additional_nodes = removed_nodes = one_child_nodes_1 = one_child_nodes_2 = 0;
log("---- AGGREGATION DONE ----");
}
p->before_count = 0;
p->after_count = 0;
- p->internal_nodes = 0;
- p->leaves = 0;
}
/*
p->before_count = 0;
p->after_count = 0;
- p->internal_nodes = 0;
- p->leaves = 0;
p->bucket_list = NULL;
p->bucket_list_size = 0;