diff options
| author | songyanchao <[email protected]> | 2024-05-09 07:43:38 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2024-05-15 02:06:26 +0000 |
| commit | 5602c112f97e74233fe488cd64f05a3457daa187 (patch) | |
| tree | 4fe9002053215161f0ca11ebddae9206278a28ab /infra | |
| parent | 4465a1ce74f4a6109bacff3e475a55f3ea1990d7 (diff) | |
🧪 test(DPISDN-42): Add test case for link aware injector node.
Add test case for link aware injector node.
Diffstat (limited to 'infra')
| -rw-r--r-- | infra/include/link_db.h | 4 | ||||
| -rw-r--r-- | infra/src/link_db.c | 75 | ||||
| -rw-r--r-- | infra/test/TestLinkDb.cc | 15 |
3 files changed, 73 insertions, 21 deletions
diff --git a/infra/include/link_db.h b/infra/include/link_db.h index 3affd77..3ce321a 100644 --- a/infra/include/link_db.h +++ b/infra/include/link_db.h @@ -28,7 +28,9 @@ struct link_db_match_field struct link_db_reverse_result { enum link_db_type type; - uint16_t adapter_id; + uint8_t nr_adapters; + uint16_t ef_link_id; + uint16_t adapter_id[16]; int match_result; }; diff --git a/infra/src/link_db.c b/infra/src/link_db.c index ae42ec5..f2fffb0 100644 --- a/infra/src/link_db.c +++ b/infra/src/link_db.c @@ -13,7 +13,9 @@ typedef uint16_t (*link_db_match_func)(struct link_db_ctx * ctx, struct link_db_ struct link_db { enum link_db_type type; + uint8_t nr_ef_adapters; uint16_t traffic_link_id; + uint16_t ef_adapter_ids[16]; union { struct { @@ -105,18 +107,29 @@ void link_db_ctx_dump(struct link_db_ctx * ctx) for (int index = 0; index < ctx->nr_entries; index++) { struct link_db * link_db = &ctx->link_dbs[index]; - if (ctx->type == LINK_DB_TYPE_EF) + if (link_db->type == LINK_DB_TYPE_EF) { char str_addr[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &link_db->ef_ip_addr, str_addr, sizeof(str_addr)); - MR_INFO("Link db, traffic link id:%u, etherfabric link id:%u, etherfabric ip addr:%s", - link_db->traffic_link_id, link_db->ef_link_id, str_addr); + + char str_db_info[MR_STRING_MAX] = {}; + int len = snprintf(str_db_info, sizeof(str_db_info), + "Link db, traffic link id:%u, ef link id:%u, ef ip addr:%s, nr ef adapters:%u", + link_db->traffic_link_id, link_db->ef_link_id, str_addr, link_db->nr_ef_adapters); + + for (int i = 0; i < link_db->nr_ef_adapters; i++) + { + len += snprintf(str_db_info + len, sizeof(str_db_info) - len, ", ef adapter id:%u", + link_db->ef_adapter_ids[i]); + } + + MR_INFO("%s", str_db_info); } - else if (ctx->type == LINK_DB_TYPE_VWIRE) + else if (link_db->type == LINK_DB_TYPE_VWIRE) { MR_INFO("Link db, traffic link id:%u, vwire id:%u", link_db->traffic_link_id, link_db->vwire_id); } - else if (ctx->type == LINK_DB_TYPE_TERA) + else if (link_db->type == LINK_DB_TYPE_TERA) { MR_INFO("Link db, traffic link id:%u, tera id:%u", link_db->traffic_link_id, link_db->tera_adapter_id); } @@ -143,6 +156,24 @@ int link_db_config_parse(const char * cfgfile, struct link_db_ctx * ctx) struct link_db * link_db = &ctx->link_dbs[nr_entries]; if (type == LINK_DB_TYPE_EF) { + int nr_ef_adapters = 0; + unsigned int ef_adapter_ids[RTE_DIM(link_db->ef_adapter_ids)] = {}; + if (ctx->type == LINK_DB_TYPE_ALL) + { + nr_ef_adapters = MESA_load_profile_uint_range(cfgfile, str_section, "ef_adapter_ids", + RTE_DIM(ef_adapter_ids), ef_adapter_ids); + if (nr_ef_adapters < 0) + { + nr_ef_adapters = 0; + } + else if (nr_ef_adapters > RTE_DIM(link_db->ef_adapter_ids)) + { + MR_ERROR("The : %s ,The 'ef_adapter_ids' is out of the max range(%u).", str_section, + (unsigned int)(RTE_DIM(link_db->ef_adapter_ids))); + return RT_ERR; + } + } + uint32_t ef_link_id; ret = MESA_load_profile_uint_nodef(cfgfile, str_section, "ef_link_id", &ef_link_id); if (ret < 0) @@ -171,6 +202,12 @@ int link_db_config_parse(const char * cfgfile, struct link_db_ctx * ctx) link_db->type = LINK_DB_TYPE_EF; link_db->ef_link_id = (uint16_t)ef_link_id; link_db->ef_ip_addr = ef_ip_addr; + link_db->nr_ef_adapters = (uint8_t)nr_ef_adapters; + + for (int i = 0; i < nr_ef_adapters; i++) + { + link_db->ef_adapter_ids[i] = (uint16_t)ef_adapter_ids[i]; + } } if (type == LINK_DB_TYPE_VWIRE) @@ -332,15 +369,25 @@ void link_db_reverse_match(struct link_db_ctx * ctx, uint16_t link_id, struct li switch (link_db->type) { - case LINK_DB_TYPE_EF: - result->adapter_id = link_db->ef_link_id; - break; - case LINK_DB_TYPE_VWIRE: - result->adapter_id = link_db->vwire_id; - break; - case LINK_DB_TYPE_TERA: - result->adapter_id = link_db->tera_adapter_id; - break; + case LINK_DB_TYPE_EF: { + result->nr_adapters = link_db->nr_ef_adapters; + result->ef_link_id = link_db->ef_link_id; + for (int i = 0; i < link_db->nr_ef_adapters; i++) + { + result->adapter_id[i] = link_db->ef_adapter_ids[i]; + } + } + break; + case LINK_DB_TYPE_VWIRE: { + result->nr_adapters = 1; + result->adapter_id[0] = link_db->vwire_id; + } + break; + case LINK_DB_TYPE_TERA: { + result->nr_adapters = 1; + result->adapter_id[0] = link_db->tera_adapter_id; + } + break; default: break; } diff --git a/infra/test/TestLinkDb.cc b/infra/test/TestLinkDb.cc index 86bb0d2..e88fdc0 100644 --- a/infra/test/TestLinkDb.cc +++ b/infra/test/TestLinkDb.cc @@ -271,9 +271,10 @@ TEST(TestCaseLinkDb, TypeAllReverseMatch) ASSERT_TRUE(all_ctx != NULL); const std::string filename = "link_db.cfg"; - const std::string content = "[link_db:0]\n type = 0\n traffic_link_id = 12345\n ef_ip_addr = 10.1.1.10\n " - "ef_link_id = 16\n [link_db:1]\n type = 1\n traffic_link_id = 54321\n vwire_id = 17\n " - "[link_db:2]\n type = 2\n traffic_link_id = 6000\n tera_adapter_id = 18\n "; + const std::string content = + "[link_db:0]\n type = 0\n traffic_link_id = 12345\n ef_ip_addr = 10.1.1.10\n ef_adapter_ids=12\n " + "ef_link_id = 16\n [link_db:1]\n type = 1\n traffic_link_id = 54321\n vwire_id = 17\n " + "[link_db:2]\n type = 2\n traffic_link_id = 6000\n tera_adapter_id = 18\n "; writeLinkDbCfg(filename, content); @@ -305,7 +306,9 @@ TEST(TestCaseLinkDb, TypeAllReverseMatch) link_db_reverse_match(all_ctx, result[2], &reverse_result); ASSERT_EQ(reverse_result.match_result, 0); ASSERT_EQ(reverse_result.type, LINK_DB_TYPE_EF); - ASSERT_EQ(reverse_result.adapter_id, 16); + ASSERT_EQ(reverse_result.nr_adapters, 1); + ASSERT_EQ(reverse_result.adapter_id[0], 12); + ASSERT_EQ(reverse_result.ef_link_id, 16); /* Vwire */ memset(match_field, 0, sizeof(match_field)); @@ -327,7 +330,7 @@ TEST(TestCaseLinkDb, TypeAllReverseMatch) link_db_reverse_match(all_ctx, result[2], &reverse_result); ASSERT_EQ(reverse_result.match_result, 0); ASSERT_EQ(reverse_result.type, LINK_DB_TYPE_VWIRE); - ASSERT_EQ(reverse_result.adapter_id, 17); + ASSERT_EQ(reverse_result.adapter_id[0], 17); /* Tera */ memset(match_field, 0, sizeof(match_field)); @@ -349,7 +352,7 @@ TEST(TestCaseLinkDb, TypeAllReverseMatch) link_db_reverse_match(all_ctx, result[2], &reverse_result); ASSERT_EQ(reverse_result.match_result, 0); ASSERT_EQ(reverse_result.type, LINK_DB_TYPE_TERA); - ASSERT_EQ(reverse_result.adapter_id, 18); + ASSERT_EQ(reverse_result.adapter_id[0], 18); /* Destroy ctx */ link_db_destroy(&all_ctx); |
