summaryrefslogtreecommitdiff
path: root/tests/bgpd
diff options
context:
space:
mode:
authorYuqing Zhao <xiaopanghu99@163.com>2023-07-31 20:34:48 +0800
committerYuqing Zhao <xiaopanghu99@163.com>2023-08-22 09:35:46 +0800
commit6e7f305e54f4828d58cb4b2e4c815d82a4cbe560 (patch)
tree4c01b7351f468d2139053b3cc5095e4bde67c6bd /tests/bgpd
parent451fb24b17cb9272981d3809f755985d9ce52f79 (diff)
bgpd: Convert from struct bgp_node to struct bgp_dest
This is based on @donaldsharp's work The current code base is the struct bgp_node data structure. The problem with this is that it creates a bunch of extra data per route_node. The table structure generates ‘holder’ nodes that are never going to receive bgp routes, and now the memory of those nodes is allocated as if they are a full bgp_node. After splitting up the bgp_node into bgp_dest and route_node, the memory of ‘holder’ node which does not have any bgp data will be allocated as the route_node, not the bgp_node, and the memory usage is reduced. The memory usage of BGP node will be reduced from 200B to 96B. The total memory usage optimization of this part is ~16.00%. Signed-off-by: Donald Sharp <sharpd@nvidia.com> Signed-off-by: Yuqing Zhao <xiaopanghu99@163.com>
Diffstat (limited to 'tests/bgpd')
-rw-r--r--tests/bgpd/test_mpath.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c
index 0124ad9b22..bc2c1e8a44 100644
--- a/tests/bgpd/test_mpath.c
+++ b/tests/bgpd/test_mpath.c
@@ -244,6 +244,7 @@ static int run_bgp_mp_list(testcase_t *t)
for (i = 0, mp_node = mp_list.head; i < test_mp_list_info_count;
i++, mp_node = listnextnode(mp_node)) {
info = listgetdata(mp_node);
+ info->lock++;
EXPECT_TRUE(info == &test_mp_list_info[i], test_result);
}
@@ -274,14 +275,14 @@ testcase_t test_bgp_mp_list = {
* Testcase for bgp_path_info_mpath_update
*/
-struct bgp_node test_rn;
+static struct bgp_dest *dest;
static int setup_bgp_path_info_mpath_update(testcase_t *t)
{
int i;
struct bgp *bgp;
struct bgp_table *rt;
- struct route_node *rt_node;
+ struct prefix p;
as_t asn = 1;
t->tmp_data = bgp_create_fake(&asn, NULL);
@@ -294,13 +295,12 @@ static int setup_bgp_path_info_mpath_update(testcase_t *t)
if (!rt)
return -1;
- str2prefix("42.1.1.0/24", &test_rn.p);
- rt_node = bgp_dest_to_rnode(&test_rn);
- memcpy((struct route_table *)&rt_node->table, &rt->route_table,
- sizeof(struct route_table));
+ str2prefix("42.1.1.0/24", &p);
+ dest = bgp_node_get(rt, &p);
+
setup_bgp_mp_list(t);
for (i = 0; i < test_mp_list_info_count; i++)
- bgp_path_info_add(&test_rn, &test_mp_list_info[i]);
+ bgp_path_info_add(dest, &test_mp_list_info[i]);
return 0;
}
@@ -309,6 +309,7 @@ static int run_bgp_path_info_mpath_update(testcase_t *t)
struct bgp_path_info *new_best, *old_best, *mpath;
struct list mp_list;
struct bgp_maxpaths_cfg mp_cfg = {3, 3};
+
int test_result = TEST_PASSED;
bgp_mp_list_init(&mp_list);
bgp_mp_list_add(&mp_list, &test_mp_list_info[4]);
@@ -317,7 +318,7 @@ static int run_bgp_path_info_mpath_update(testcase_t *t)
bgp_mp_list_add(&mp_list, &test_mp_list_info[1]);
new_best = &test_mp_list_info[3];
old_best = NULL;
- bgp_path_info_mpath_update(NULL, &test_rn, new_best, old_best, &mp_list,
+ bgp_path_info_mpath_update(NULL, dest, new_best, old_best, &mp_list,
&mp_cfg);
bgp_mp_list_clear(&mp_list);
EXPECT_TRUE(bgp_path_info_mpath_count(new_best) == 2, test_result);
@@ -332,7 +333,7 @@ static int run_bgp_path_info_mpath_update(testcase_t *t)
bgp_mp_list_add(&mp_list, &test_mp_list_info[1]);
new_best = &test_mp_list_info[0];
old_best = &test_mp_list_info[3];
- bgp_path_info_mpath_update(NULL, &test_rn, new_best, old_best, &mp_list,
+ bgp_path_info_mpath_update(NULL, dest, new_best, old_best, &mp_list,
&mp_cfg);
bgp_mp_list_clear(&mp_list);
EXPECT_TRUE(bgp_path_info_mpath_count(new_best) == 1, test_result);