if (t->cmp)
return t->result == f_same(t->fn, t->cmp);
- linpool *tmp = lp_new_default(&root_pool);
- enum filter_return fret = f_eval(t->fn, tmp, NULL);
- rfree(tmp);
+ enum filter_return fret = f_eval(t->fn, tmp_linpool, NULL);
return (fret < F_REJECT);
}
start_conf_env(void)
{
bt_bird_init();
-
- pool *p = rp_new(&root_pool, "helper_pool");
- linpool *l = lp_new_default(p);
- cfg_mem = l;
+ cfg_mem = tmp_linpool;
}
static struct f_tree *
}
static list *
-make_random_prefix_list(linpool *lp, int num, int v6, int tight)
+make_random_prefix_list(int num, int v6, int tight)
{
- list *prefixes = lp_allocz(lp, sizeof(struct f_prefix_node));
+ list *prefixes = lp_allocz(tmp_linpool, sizeof(struct f_prefix_node));
init_list(prefixes);
for (int i = 0; i < num; i++)
{
- struct f_prefix_node *px = lp_allocz(lp, sizeof(struct f_prefix_node));
+ struct f_prefix_node *px = lp_allocz(tmp_linpool, sizeof(struct f_prefix_node));
get_random_prefix(&px->prefix, v6, tight);
add_tail(prefixes, &px->n);
}
static struct f_trie *
-make_trie_from_prefix_list(linpool *lp, list *prefixes)
+make_trie_from_prefix_list(list *prefixes)
{
- struct f_trie *trie = f_new_trie(lp, 0);
+ struct f_trie *trie = f_new_trie(tmp_linpool, 0);
struct f_prefix_node *n;
WALK_LIST(n, *prefixes)
* Arg @plus means prefix should include all longer ones.
*/
static list *
-read_prefix_list(linpool *lp, FILE *f, int v6, int plus)
+read_prefix_list(FILE *f, int v6, int plus)
{
ASSERT(!v6);
char s[32];
int n;
- list *pxlist = lp_allocz(lp, sizeof(struct f_prefix_node));
+ list *pxlist = lp_allocz(tmp_linpool, sizeof(struct f_prefix_node));
init_list(pxlist);
errno = 0;
if (n != 5)
bt_abort_msg("Invalid content of trie_data");
- struct f_prefix_node *px = lp_allocz(lp, sizeof(struct f_prefix_node));
+ struct f_prefix_node *px = lp_allocz(tmp_linpool, sizeof(struct f_prefix_node));
net_fill_ip4(&px->prefix.net, ip4_build(a0, a1, a2, a3), pl);
px->prefix.lo = pl;
px->prefix.hi = plus ? IP4_MAX_PREFIX_LENGTH : pl;
*/
static int
read_prefix_file(const char *filename, int plus,
- linpool *lp0, linpool *lp1,
list *data[], struct f_trie *trie[])
{
FILE *f = fopen(filename, "r");
int n = 0;
list *pxlist;
- while (pxlist = read_prefix_list(lp0, f, 0, plus))
+ while (pxlist = read_prefix_list(f, 0, plus))
{
data[n] = pxlist;
- trie[n] = make_trie_from_prefix_list(lp1, pxlist);
+ trie[n] = make_trie_from_prefix_list(pxlist);
bt_debug("NEXT\n");
n++;
}
bt_config_parse(BT_CONFIG_SIMPLE);
int v6 = 0;
- linpool *lp = lp_new_default(&root_pool);
for (int round = 0; round < TESTS_NUM; round++)
{
- list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
- struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
+ list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
+ struct f_trie *trie = make_trie_from_prefix_list(prefixes);
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
{
}
v6 = !v6;
- lp_flush(lp);
+ tmp_flush();
}
bt_bird_cleanup();
bt_config_parse(BT_CONFIG_SIMPLE);
int v6 = 0;
- linpool *lp = lp_new_default(&root_pool);
for (int round = 0; round < TESTS_NUM; round++)
{
- list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
- struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
+ list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
+ struct f_trie *trie = make_trie_from_prefix_list(prefixes);
struct f_prefix_node *n = HEAD(*prefixes);
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
}
v6 = !v6;
- lp_flush(lp);
+ tmp_flush();
}
bt_bird_cleanup();
bt_config_parse(BT_CONFIG_SIMPLE);
int v6 = 0;
- linpool *lp = lp_new_default(&root_pool);
for (int round = 0; round < TESTS_NUM; round++)
{
- list *prefixes = make_random_prefix_list(lp, PREFIXES_NUM, v6, 0);
- struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
+ list *prefixes = make_random_prefix_list(PREFIXES_NUM, v6, 0);
+ struct f_trie *trie = make_trie_from_prefix_list(prefixes);
struct f_prefix_node *n = HEAD(*prefixes);
for (int i = 0; i < PREFIX_TESTS_NUM; i++)
}
v6 = !v6;
- lp_flush(lp);
+ tmp_flush();
}
v6 = !v6;
benchmark_trie_dataset(const char *filename, int plus)
{
int n = 0;
- linpool *lp0 = lp_new_default(&root_pool);
- linpool *lp1 = lp_new_default(&root_pool);
list *data[TRIE_BUFFER_SIZE];
struct f_trie *trie[TRIE_BUFFER_SIZE];
net_addr *nets;
bt_reset_suite_case_timer();
bt_log_suite_case_result(1, "Reading %s", filename, n);
- n = read_prefix_file(filename, plus, lp0, lp1, data, trie);
+ n = read_prefix_file(filename, plus, data, trie);
bt_log_suite_case_result(1, "Read prefix data, %d lists, ", n);
- size_t trie_size = rmemsize(lp1).effective * 1000 / (1024*1024);
+ size_t trie_size = rmemsize(tmp_linpool).effective * 1000 / (1024*1024);
bt_log_suite_case_result(1, "Trie size %u.%03u MB",
(uint) (trie_size / 1000), (uint) (trie_size % 1000));
int t = PREFIX_BENCH_NUM / n;
int tb = MIN(t, TEST_BUFFER_SIZE);
- nets = lp_alloc(lp0, tb * sizeof(net_addr));
+ nets = tmp_alloc(tb * sizeof(net_addr));
if (!plus)
select_random_prefix_subset(data, nets, n, tb);
bt_log_suite_case_result(1, "Matching done, %d / %d matches", match, t * n);
- rfree(lp0);
- rfree(lp1);
-
+ tmp_flush();
return 1;
}
bt_config_parse(BT_CONFIG_SIMPLE);
int v6 = 0;
- linpool *lp = lp_new_default(&root_pool);
for (int round = 0; round < TESTS_NUM*4; round++)
{
- list *prefixes = make_random_prefix_list(lp, 100 * PREFIXES_NUM, v6, 0);
- struct f_trie *trie1 = f_new_trie(lp, 0);
- struct f_trie *trie2 = f_new_trie(lp, 0);
+ list *prefixes = make_random_prefix_list(100 * PREFIXES_NUM, v6, 0);
+ struct f_trie *trie1 = f_new_trie(tmp_linpool, 0);
+ struct f_trie *trie2 = f_new_trie(tmp_linpool, 0);
struct f_prefix_node *n;
WALK_LIST(n, *prefixes)
bt_assert(trie_same(trie1, trie2));
v6 = !v6;
- lp_flush(lp);
+ tmp_flush();
}
bt_bird_cleanup();
bt_bird_init();
bt_config_parse(BT_CONFIG_SIMPLE);
- linpool *lp = lp_new_default(&root_pool);
for (int round = 0; round < TESTS_NUM*8; round++)
{
int level = round / TESTS_NUM;
int v6 = level % 2;
int num = PREFIXES_NUM * (int[]){1, 10, 100, 1000}[level / 2];
int pos = 0, end = 0;
- list *prefixes = make_random_prefix_list(lp, num, v6, 1);
- struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
+ list *prefixes = make_random_prefix_list(num, v6, 1);
+ struct f_trie *trie = make_trie_from_prefix_list(prefixes);
struct f_prefix *pxset = malloc((num + 1) * sizeof(struct f_prefix));
struct f_prefix_node *n;
bt_assert((pos == num) || !net_in_netX(&pxset[pos].net, &from.net));
bt_debug("Subnet walk done for %s (found %d nets)\n", buf0, pos - p0);
- lp_flush(lp);
+ tmp_flush();
}
bt_bird_cleanup();
bt_bird_init();
bt_config_parse(BT_CONFIG_SIMPLE);
- linpool *lp = lp_new_default(&root_pool);
for (int round = 0; round < TESTS_NUM * 4; round++)
{
int level = round / TESTS_NUM;
int pos = 0;
int st = 0, sn = 0, sm = 0;
- list *prefixes = make_random_prefix_list(lp, num, v6, 1);
- struct f_trie *trie = make_trie_from_prefix_list(lp, prefixes);
+ list *prefixes = make_random_prefix_list(num, v6, 1);
+ struct f_trie *trie = make_trie_from_prefix_list(prefixes);
struct f_prefix *pxset = malloc((num + 1) * sizeof(struct f_prefix));
struct f_prefix_node *pxn;
bt_debug("Success in %d / %d, sum %d, max %d\n", sn, i, st, sm);
- lp_flush(lp);
+ tmp_flush();
}
bt_bird_cleanup();
resource_init();
struct flow_builder *fb = flow_builder_init(&root_pool);
- linpool *lp = lp_new_default(&root_pool);
/* Expectation */
flow_builder_set_type(fb, FLOW_TYPE_TCP_FLAGS);
flow_builder_add_op_val(fb, 0, 0x55);
- net_addr_flow4 *res = flow_builder4_finalize(fb, lp);
+ net_addr_flow4 *res = flow_builder4_finalize(fb, tmp_linpool);
bt_assert(memcmp(res, expect, expect->length) == 0);
net_addr_ip6 ip;
resource_init();
- linpool *lp = lp_new_default(&root_pool);
struct flow_builder *fb = flow_builder_init(&root_pool);
fb->ipv6 = 1;
flow_builder_set_type(fb, FLOW_TYPE_LABEL);
flow_builder_add_op_val(fb, 0, 0x55);
- net_addr_flow6 *res = flow_builder6_finalize(fb, lp);
+ net_addr_flow6 *res = flow_builder6_finalize(fb, tmp_linpool);
bt_assert(memcmp(res, expect, expect->length) == 0);
/* Reverse order */
flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
flow_builder6_add_pfx(fb, &ip, 61);
- res = flow_builder6_finalize(fb, lp);
+ res = flow_builder6_finalize(fb, tmp_linpool);
bt_assert(memcmp(res, expect, expect->length) == 0);
return 1;
struct adata *as_path = &empty_as_path;
u32 first_prepended, last_prepended;
first_prepended = last_prepended = 0;
- struct linpool *lp = lp_new_default(&root_pool);
struct f_path_mask *mask = alloca(sizeof(struct f_path_mask) + AS_PATH_LENGTH * sizeof(struct f_path_mask_item));
mask->len = AS_PATH_LENGTH;
for (int i = AS_PATH_LENGTH - 1; i >= 0; i--)
{
u32 val = bt_random();
- as_path = as_path_prepend(lp, as_path, val);
+ as_path = as_path_prepend(tmp_linpool, as_path, val);
bt_debug("Prepending ASN: %10u \n", val);
if (i == 0)
bt_assert(as_path_get_last(as_path, &asn));
bt_assert_msg(asn == first_prepended, "as_path_get_last() should return the first prepended ASN");
- rfree(lp);
+ tmp_flush();
}
return 1;
struct adata empty_as_path = {};
struct adata *as_path = &empty_as_path;
- struct linpool *lp = lp_new_default(&root_pool);
uint i;
for (i = 4294967285; i <= 4294967294; i++)
{
- as_path = as_path_prepend(lp, as_path, i);
+ as_path = as_path_prepend(tmp_linpool, as_path, i);
bt_debug("Prepending ASN: %10u \n", i);
}
as_path_format(as_path, buf2, SMALL_BUFFER_SIZE);
bt_assert_msg(strcmp(buf2, "4294967294 42...") == 0, "Small Buffer(%zu): '%s'", strlen(buf2), buf2);
- rfree(lp);
+ tmp_flush();
return 1;
}
struct adata empty_as_path = {};
struct adata *as_path = &empty_as_path;
- struct linpool *lp = lp_new_default(&root_pool);
u32 as_nums[AS_PATH_LENGTH] = {};
int i;
{
u32 val = bt_random();
as_nums[i] = val;
- as_path = as_path_prepend(lp, as_path, val);
+ as_path = as_path_prepend(tmp_linpool, as_path, val);
}
for (i = 0; i < AS_PATH_LENGTH; i++)
int counts_of_contains = count_asn_in_array(as_nums, as_nums[i]);
bt_assert_msg(as_path_contains(as_path, as_nums[i], counts_of_contains), "AS Path should contains %d-times number %d", counts_of_contains, as_nums[i]);
- bt_assert(as_path_filter(lp, as_path, NULL, as_nums[i], 0) != NULL);
- bt_assert(as_path_filter(lp, as_path, NULL, as_nums[i], 1) != NULL);
+ bt_assert(as_path_filter(tmp_linpool, as_path, NULL, as_nums[i], 0) != NULL);
+ bt_assert(as_path_filter(tmp_linpool, as_path, NULL, as_nums[i], 1) != NULL);
}
for (i = 0; i < 10000; i++)
bt_assert_msg(result == 0, "As path should not contain the number %u", test_val);
}
- rfree(lp);
+ tmp_flush();
return 1;
}
struct adata empty_as_path = {};
struct adata *as_path = &empty_as_path;
- struct linpool *lp = lp_new_default(&root_pool);
#define AS_PATH_LENGTH_FOR_CONVERTING_TEST 10
int i;
for (i = 0; i < AS_PATH_LENGTH_FOR_CONVERTING_TEST; i++)
- as_path = as_path_prepend(lp, as_path, i);
+ as_path = as_path_prepend(tmp_linpool, as_path, i);
bt_debug("data length: %u \n", as_path->length);
#define SET_SIZE_FOR_FORMAT_OUTPUT 10
-struct linpool *lp;
-
enum set_type
{
SET_TYPE_INT,
{
struct adata empty_as_path = {};
set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path;
- lp = lp_new_default(&root_pool);
int i;
for (i = 0; i < len; i++)
{
if (type == SET_TYPE_INT)
{
- set_sequence = int_set_add(lp, set_sequence, i);
- set_sequence_same = int_set_add(lp, set_sequence_same, i);
- set_sequence_higher = int_set_add(lp, set_sequence_higher, i + SET_SIZE);
- set_random = int_set_add(lp, set_random, bt_random());
+ set_sequence = int_set_add(tmp_linpool, set_sequence, i);
+ set_sequence_same = int_set_add(tmp_linpool, set_sequence_same, i);
+ set_sequence_higher = int_set_add(tmp_linpool, set_sequence_higher, i + SET_SIZE);
+ set_random = int_set_add(tmp_linpool, set_random, bt_random());
}
else if (type == SET_TYPE_EC)
{
- set_sequence = ec_set_add(lp, set_sequence, i);
- set_sequence_same = ec_set_add(lp, set_sequence_same, i);
- set_sequence_higher = ec_set_add(lp, set_sequence_higher, i + SET_SIZE);
- set_random = ec_set_add(lp, set_random, (bt_random() << 32 | bt_random()));
+ set_sequence = ec_set_add(tmp_linpool, set_sequence, i);
+ set_sequence_same = ec_set_add(tmp_linpool, set_sequence_same, i);
+ set_sequence_higher = ec_set_add(tmp_linpool, set_sequence_higher, i + SET_SIZE);
+ set_random = ec_set_add(tmp_linpool, set_random, (bt_random() << 32 | bt_random()));
}
else
bt_abort_msg("This should be unreachable");
for (i = 0; i < SET_SIZE; i++)
bt_assert_msg(data[i] == i, "(data[i] = %d) == i = %d)", data[i], i);
- rfree(lp);
return 1;
}
generate_set_sequence(SET_TYPE_INT, SET_SIZE);
const struct adata *set_union;
- set_union = int_set_union(lp, set_sequence, set_sequence_same);
+ set_union = int_set_union(tmp_linpool, set_sequence, set_sequence_same);
bt_assert(int_set_get_size(set_union) == SET_SIZE);
bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0);
- set_union = int_set_union(lp, set_sequence, set_sequence_higher);
+ set_union = int_set_union(tmp_linpool, set_sequence, set_sequence_higher);
bt_assert_msg(int_set_get_size(set_union) == SET_SIZE*2, "int_set_get_size(set_union) %d, SET_SIZE*2 %d", int_set_get_size(set_union), SET_SIZE*2);
bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0);
- rfree(lp);
return 1;
}
bt_assert(int_set_format(set_sequence, 1, 0, buf, BUFFER_SIZE) == 0);
bt_assert(strcmp(buf, "(0,0) (0,1) (0,2) (0,3) (0,4) (0,5) (0,6) (0,7) (0,8) (0,9)") == 0);
- rfree(lp);
return 1;
}
u32 i;
for (i = 0; i < SET_SIZE; i++)
{
- deleting_sequence = int_set_del(lp, deleting_sequence, i);
+ deleting_sequence = int_set_del(tmp_linpool, deleting_sequence, i);
bt_assert_msg(int_set_get_size(deleting_sequence) == (int) (SET_SIZE-1-i),
"int_set_get_size(deleting_sequence) %d == SET_SIZE-1-i %d",
int_set_get_size(deleting_sequence),
// for (i = 0; i < SET_SIZE; i++)
// bt_assert_msg(data[i] == (SET_SIZE-1-i), "(data[i] = %d) == ((SET_SIZE-1-i) = %d)", data[i], SET_SIZE-1-i);
- rfree(lp);
return 1;
}
generate_set_sequence(SET_TYPE_EC, SET_SIZE);
const struct adata *set_union;
- set_union = ec_set_union(lp, set_sequence, set_sequence_same);
+ set_union = ec_set_union(tmp_linpool, set_sequence, set_sequence_same);
bt_assert(ec_set_get_size(set_union) == SET_SIZE);
bt_assert(ec_set_format(set_union, 0, buf, BUFFER_SIZE) == 0);
- set_union = ec_set_union(lp, set_sequence, set_sequence_higher);
+ set_union = ec_set_union(tmp_linpool, set_sequence, set_sequence_higher);
bt_assert_msg(ec_set_get_size(set_union) == SET_SIZE*2, "ec_set_get_size(set_union) %d, SET_SIZE*2 %d", ec_set_get_size(set_union), SET_SIZE*2);
bt_assert(ec_set_format(set_union, 0, buf, BUFFER_SIZE) == 0);
- rfree(lp);
return 1;
}
const struct adata empty_as_path = {};
set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path;
- lp = lp_new_default(&root_pool);
u64 i = 0;
- set_sequence = ec_set_add(lp, set_sequence, i);
+ set_sequence = ec_set_add(tmp_linpool, set_sequence, i);
for (i = 1; i < SET_SIZE_FOR_FORMAT_OUTPUT; i++)
- set_sequence = ec_set_add(lp, set_sequence, i + ((i%2) ? ((u64)EC_RO << 48) : ((u64)EC_RT << 48)));
+ set_sequence = ec_set_add(tmp_linpool, set_sequence, i + ((i%2) ? ((u64)EC_RO << 48) : ((u64)EC_RT << 48)));
bt_assert(ec_set_format(set_sequence, 0, buf, BUFFER_SIZE) == 0);
bt_assert_msg(strcmp(buf, "(unknown 0x0, 0, 0) (ro, 0, 1) (rt, 0, 2) (ro, 0, 3) (rt, 0, 4) (ro, 0, 5) (rt, 0, 6) (ro, 0, 7) (rt, 0, 8) (ro, 0, 9)") == 0,
"ec_set_format() returns '%s'", buf);
- rfree(lp);
return 1;
}
u32 i;
for (i = 0; i < SET_SIZE; i++)
{
- deleting_sequence = ec_set_del(lp, deleting_sequence, i);
+ deleting_sequence = ec_set_del(tmp_linpool, deleting_sequence, i);
bt_assert_msg(ec_set_get_size(deleting_sequence) == (int) (SET_SIZE-1-i),
"ec_set_get_size(deleting_sequence) %d == SET_SIZE-1-i %d",
ec_set_get_size(deleting_sequence), SET_SIZE-1-i);