summaryrefslogtreecommitdiff
path: root/infra
diff options
context:
space:
mode:
authorsongyanchao <[email protected]>2023-12-26 07:11:04 +0000
committersongyanchao <[email protected]>2024-01-05 02:27:42 +0000
commitf19e5a4fdc6e089cedf7c7de92f22a018b950c0d (patch)
tree4f98c0e9af0ecb8a26784c2e672e2a7e5a294685 /infra
parent8b844e17c85a1a916cb9a824630b1eb1cb58eef9 (diff)
✨ feat(TSG-17959): Add Tera adapter type for link db.
Add Tera adapter type for link db.
Diffstat (limited to 'infra')
-rw-r--r--infra/include/link_db.h2
-rw-r--r--infra/src/link_db.c40
-rw-r--r--infra/test/TestLinkDb.cc69
3 files changed, 100 insertions, 11 deletions
diff --git a/infra/include/link_db.h b/infra/include/link_db.h
index af5a4c3..4bccd5b 100644
--- a/infra/include/link_db.h
+++ b/infra/include/link_db.h
@@ -6,6 +6,7 @@ enum link_db_type
{
LINK_DB_TYPE_EF = ADAPTER_TYPE_EF,
LINK_DB_TYPE_VWIRE = ADAPTER_TYPE_VWIRE,
+ LINK_DB_TYPE_TERA = ADAPTER_TYPE_TERA,
LINK_DB_TYPE_MAX,
};
@@ -18,6 +19,7 @@ struct link_db_match_field
uint16_t ef_link_id;
};
uint32_t vwire_id;
+ uint32_t tera_id;
};
};
diff --git a/infra/src/link_db.c b/infra/src/link_db.c
index 4a77411..1a44f48 100644
--- a/infra/src/link_db.c
+++ b/infra/src/link_db.c
@@ -5,6 +5,7 @@
uint16_t link_db_match_ef(struct link_db_ctx * ctx, struct link_db_match_field * match_field);
uint16_t link_db_match_vwire(struct link_db_ctx * ctx, struct link_db_match_field * match_field);
+uint16_t link_db_match_tera(struct link_db_ctx * ctx, struct link_db_match_field * match_field);
typedef uint16_t (*link_db_match_func)(struct link_db_ctx * ctx, struct link_db_match_field * match_field);
/* Link db struct */
@@ -18,6 +19,7 @@ struct link_db
uint32_t ef_ip_addr;
};
uint32_t vwire_id;
+ uint32_t tera_id;
};
};
@@ -34,7 +36,7 @@ struct link_db_ctx
/* Link db ctx item create */
struct link_db_ctx * link_db_create(enum link_db_type type, uint32_t max_entries)
{
- assert((type == LINK_DB_TYPE_EF) || (type == LINK_DB_TYPE_VWIRE));
+ assert((type == LINK_DB_TYPE_EF) || (type == LINK_DB_TYPE_VWIRE) || (type == LINK_DB_TYPE_TERA));
struct link_db_ctx * link_db_ctx = (struct link_db_ctx *)ZMALLOC(sizeof(struct link_db_ctx));
MR_VERIFY_MALLOC(link_db_ctx);
@@ -54,6 +56,10 @@ struct link_db_ctx * link_db_create(enum link_db_type type, uint32_t max_entries
{
link_db_ctx->match_func = link_db_match_vwire;
}
+ else if (type == LINK_DB_TYPE_TERA)
+ {
+ link_db_ctx->match_func = link_db_match_tera;
+ }
return link_db_ctx;
}
@@ -88,6 +94,9 @@ void link_db_ctx_dump(struct link_db_ctx * ctx)
case LINK_DB_TYPE_VWIRE:
snprintf(str_type, sizeof(str_type) - 1, "%u(vwire)", ctx->type);
break;
+ case LINK_DB_TYPE_TERA:
+ snprintf(str_type, sizeof(str_type) - 1, "%u(tera)", ctx->type);
+ break;
default:
snprintf(str_type, sizeof(str_type) - 1, "%u(unknow)", ctx->type);
break;
@@ -172,6 +181,18 @@ int link_db_config_parse(const char * cfgfile, struct link_db_ctx * ctx)
link_db->vwire_id = vwire_id;
}
+ else if (type == LINK_DB_TYPE_TERA)
+ {
+ uint32_t tera_id;
+ ret = MESA_load_profile_uint_nodef(cfgfile, str_section, "tera_id", &tera_id);
+ if (ret < 0)
+ {
+ MR_ERROR("The : %s ,No config the 'tera_id'.", str_section);
+ return RT_ERR;
+ }
+
+ link_db->tera_id = tera_id;
+ }
uint32_t traffic_link_id;
ret = MESA_load_profile_uint_nodef(cfgfile, str_section, "traffic_link_id", &traffic_link_id);
@@ -225,6 +246,23 @@ uint16_t link_db_match_vwire(struct link_db_ctx * ctx, struct link_db_match_fiel
return UINT16_MAX;
}
+/* Link db match for tera */
+uint16_t link_db_match_tera(struct link_db_ctx * ctx, struct link_db_match_field * match_field)
+{
+ assert(ctx->type == LINK_DB_TYPE_TERA);
+
+ for (int index = 0; index < ctx->nr_entries; index++)
+ {
+ struct link_db * link_db = &ctx->link_dbs[index];
+ if (match_field->tera_id == link_db->tera_id)
+ {
+ return link_db->traffic_link_id;
+ }
+ }
+
+ return UINT16_MAX;
+}
+
/* Link db match */
void link_db_match(struct link_db_ctx * ctx, struct link_db_match_field match_fields[], uint16_t nr_fields,
uint16_t result[])
diff --git a/infra/test/TestLinkDb.cc b/infra/test/TestLinkDb.cc
index c32fd37..731217a 100644
--- a/infra/test/TestLinkDb.cc
+++ b/infra/test/TestLinkDb.cc
@@ -89,22 +89,53 @@ TEST(TestCaseLinkDb, TypeVwire)
ASSERT_EQ(ctx, nullptr);
}
-/* Etherfabric type and Vwire type */
-TEST(TestCaseLinkDb, TypeEtherfabricAndVwire)
+/* Only Tera type */
+TEST(TestCaseLinkDb, TypeTera)
+{
+ struct link_db_ctx * ctx = link_db_create(LINK_DB_TYPE_TERA, 32);
+ ASSERT_TRUE(ctx != NULL);
+
+ const std::string filename = "link_db.cfg";
+ const std::string content = "[link_db:0]\n type = 2\n traffic_link_id = 12345\n tera_id = 16\n ";
+ writeLinkDbCfg(filename, content);
+
+ ASSERT_EQ(link_db_config_parse(filename.c_str(), ctx), 0);
+
+ struct link_db_match_field match_field[3];
+ match_field[0].tera_id = 1;
+ match_field[1].tera_id = 16;
+ match_field[2].tera_id = 16;
+
+ uint16_t result[3];
+ link_db_match(ctx, match_field, 3, result);
+ ASSERT_EQ(result[0], UINT16_MAX);
+ ASSERT_EQ(result[1], 12345);
+ ASSERT_EQ(result[2], 12345);
+
+ link_db_destroy(&ctx);
+ ASSERT_EQ(ctx, nullptr);
+}
+
+/* Etherfabric type Vwire type and Tera type */
+TEST(TestCaseLinkDb, TypeEtherfabricVwireAndTera)
{
struct link_db_ctx * ef_ctx = link_db_create(LINK_DB_TYPE_EF, 32);
struct link_db_ctx * vwire_ctx = link_db_create(LINK_DB_TYPE_VWIRE, 32);
+ struct link_db_ctx * tera_ctx = link_db_create(LINK_DB_TYPE_TERA, 32);
ASSERT_TRUE(ef_ctx != NULL);
ASSERT_TRUE(vwire_ctx != NULL);
+ ASSERT_TRUE(tera_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 = 16\n ";
+ "ef_link_id = 16\n [link_db:1]\n type = 1\n traffic_link_id = 54321\n vwire_id = 16\n "
+ "[link_db:2]\n type = 2\n traffic_link_id = 6000\n tera_id = 17\n ";
writeLinkDbCfg(filename, content);
ASSERT_EQ(link_db_config_parse(filename.c_str(), ef_ctx), 0);
ASSERT_EQ(link_db_config_parse(filename.c_str(), vwire_ctx), 0);
+ ASSERT_EQ(link_db_config_parse(filename.c_str(), tera_ctx), 0);
/* Etherfabric */
struct link_db_match_field match_field[3];
@@ -132,30 +163,48 @@ TEST(TestCaseLinkDb, TypeEtherfabricAndVwire)
ASSERT_EQ(result[1], 54321);
ASSERT_EQ(result[2], 54321);
+ /* Tera */
+ memset(match_field, 0, sizeof(match_field));
+ match_field[0].tera_id = 1;
+ match_field[1].tera_id = 16;
+ match_field[2].tera_id = 17;
+
+ link_db_match(tera_ctx, match_field, 3, result);
+ ASSERT_EQ(result[0], UINT16_MAX);
+ ASSERT_EQ(result[1], UINT16_MAX);
+ ASSERT_EQ(result[2], 6000);
+
/* Etherfabric and Vwire */
memset(match_field, 0, sizeof(match_field));
- match_field[0].ef_link_id = 1;
+ match_field[0].ef_link_id = 16;
match_field[0].ef_ip_addr = 0x0a01010a;
- match_field[1].ef_link_id = 16;
- match_field[1].ef_ip_addr = 0x0a01010a;
- match_field[2].vwire_id = 16;
+ match_field[1].vwire_id = 16;
+ match_field[2].tera_id = 17;
+
printf("match_field: %x\n", match_field[2].ef_ip_addr);
link_db_match(ef_ctx, match_field, 3, result);
- ASSERT_EQ(result[0], UINT16_MAX);
- ASSERT_EQ(result[1], 12345);
+ ASSERT_EQ(result[0], 12345);
+ ASSERT_EQ(result[1], UINT16_MAX);
ASSERT_EQ(result[2], UINT16_MAX);
link_db_match(vwire_ctx, match_field, 3, result);
ASSERT_EQ(result[0], UINT16_MAX);
+ ASSERT_EQ(result[1], 54321);
+ ASSERT_EQ(result[2], UINT16_MAX);
+
+ link_db_match(tera_ctx, match_field, 3, result);
+ ASSERT_EQ(result[0], UINT16_MAX);
ASSERT_EQ(result[1], UINT16_MAX);
- ASSERT_EQ(result[2], 54321);
+ ASSERT_EQ(result[2], 6000);
/* Destroy ctx */
link_db_destroy(&ef_ctx);
link_db_destroy(&vwire_ctx);
+ link_db_destroy(&tera_ctx);
ASSERT_EQ(ef_ctx, nullptr);
ASSERT_EQ(vwire_ctx, nullptr);
+ ASSERT_EQ(tera_ctx, nullptr);
}
/* Rules number out of max entries */