Skip to content

Commit

Permalink
[syncd] added tests for neighbor_bulk operations
Browse files Browse the repository at this point in the history
added unit tests for neighbor_bulk operations

Signed-off-by: Nikola Dancejic <ndancejic@microsoft.com>
  • Loading branch information
Ndancejic committed May 14, 2024
1 parent 8fa4032 commit b33a902
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 0 deletions.
75 changes: 75 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,33 @@ sai_status_t VendorSai::bulkCreate(
object_statuses);
}

sai_status_t VendorSai::bulkCreate(
_In_ uint32_t object_count,
_In_ const sai_neighbor_entry_t* entries,
_In_ const uint32_t *attr_count,
_In_ const sai_attribute_t **attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses)
{
MUTEX();
SWSS_LOG_ENTER();
VENDOR_CHECK_API_INITIALIZED();

if (!m_apis.neighbor_api->create_neighbor_entries)
{
SWSS_LOG_INFO("create_neighbor_entries is not supported");
return SAI_STATUS_NOT_SUPPORTED;
}

return m_apis.neighbor_api->create_neighbor_entries(
object_count,
entries,
attr_count,
attr_list,
mode,
object_statuses);
}

sai_status_t VendorSai::bulkCreate(
_In_ uint32_t object_count,
_In_ const sai_fdb_entry_t* entries,
Expand Down Expand Up @@ -985,6 +1012,29 @@ sai_status_t VendorSai::bulkRemove(
object_statuses);
}

sai_status_t VendorSai::bulkRemove(
_In_ uint32_t object_count,
_In_ const sai_neighbor_entry_t *entries,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses)
{
MUTEX();
SWSS_LOG_ENTER();
VENDOR_CHECK_API_INITIALIZED();

if (!m_apis.neighbor_api->remove_neighbor_entries)
{
SWSS_LOG_INFO("remove_neighbor_entries is not supported");
return SAI_STATUS_NOT_SUPPORTED;
}

return m_apis.neighbor_api->remove_neighbor_entries(
object_count,
entries,
mode,
object_statuses);
}


sai_status_t VendorSai::bulkRemove(
_In_ uint32_t object_count,
Expand Down Expand Up @@ -1289,6 +1339,31 @@ sai_status_t VendorSai::bulkSet(
object_statuses);
}

sai_status_t VendorSai::bulkSet(
_In_ uint32_t object_count,
_In_ const sai_neighbor_entry_t *entries,
_In_ const sai_attribute_t *attr_list,
_In_ sai_bulk_op_error_mode_t mode,
_Out_ sai_status_t *object_statuses)
{
MUTEX();
SWSS_LOG_ENTER();
VENDOR_CHECK_API_INITIALIZED();

if (!m_apis.neighbor_api->set_neighbor_entries_attribute)
{
SWSS_LOG_INFO("set_neighbor_entries_attribute is not supported");
return SAI_STATUS_NOT_SUPPORTED;
}

return m_apis.neighbor_api->set_neighbor_entries_attribute(
object_count,
entries,
attr_list,
mode,
object_statuses);
}

sai_status_t VendorSai::bulkSet(
_In_ uint32_t object_count,
_In_ const sai_fdb_entry_t *entries,
Expand Down
143 changes: 143 additions & 0 deletions syncd/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,147 @@ void test_bulk_route_set()
ASSERT_SUCCESS("Failed to bulk remove route entry");
}

void test_bulk_neighbor_set()
{
SWSS_LOG_ENTER();


sai_reinit();


sai_status_t status;

sai_neighbor_api_t *sai_neighbor_api = NULL;
sai_switch_api_t *sai_switch_api = NULL;
sai_virtual_router_api_t * sai_virtual_router_api = NULL;
sai_lag_api_t *sai_lag_api = NULL;
sai_router_interface_api_t *sai_rif_api = NULL;

sai_api_query(SAI_API_NEIGBOR, (void**)&sai_neighbor_api);
sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);
sai_api_query(SAI_API_VIRTUAL_ROUTER, (void**)&sai_virtual_router_api);
sai_api_query(SAI_API_ROUTER_INTERFACE, (void **)&sai_rif_api);
sai_api_query(SAI_API_LAG, (void**)&sai_lag_api);

uint32_t count = 3;

std::vector<sai_neighbor_entry_t> neighbors;
std::vector<sai_attribute_t> attrs;

uint32_t index = 15;

sai_attribute_t swattr;

swattr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
swattr.value.booldata = true;

sai_object_id_t switch_id;
status = sai_switch_api->create_switch(&switch_id, 1, &swattr);

ASSERT_SUCCESS("Failed to create switch");

std::vector<std::vector<sai_attribute_t>> neighbor_attrs;
std::vector<const sai_attribute_t *> neighbor_attrs_array;
std::vector<uint32_t> neighbor_attrs_count;

for (uint32_t i = index; i < index + count; ++i)
{
sai_neighbor_entry_t neighbor_entry;

// virtual router
sai_object_id_t vr;

status = sai_virtual_router_api->create_virtual_router(&vr, switch_id, 0, NULL);

ASSERT_SUCCESS("failed to create virtual router");

// create lag
sai_object_id_t lag;
status = sai_lag_api->create_lag(&lag, switch_id, 0, NULL);

// create router interface
sai_object_id_t rif;
sai_attribute_t rifattr[3];
rifattr[0].id = SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID;
rifattr[0].value.oid = vr;
rifattr[1].id = SAI_ROUTER_INTERFACE_ATTR_TYPE;
rifattr[1].value.s32 = SAI_ROUTER_INTERFACE_TYPE_PORT;
rifattr[2].id = SAI_ROUTER_INTERFACE_ATTR_PORT_ID;
rifattr[2].value.oid = lag;
status = sai_rif_api->create_router_interface(&rif, switch_id, 3, rifattr);
ASSERT_SUCCESS("Failed to create router interface");

neighbor_entry.ip_address.addr_family = SAI_IP_ADDR_FAMILY_IPV4;
neighbor_entry.ip_address.addr.ip4 = htonl(0x0a000000 | i);
neighbor_entry.rif_id = rif;
neighbor_entry.switch_id = switch_id;
neighbors.push_back(neighbor_entry);

std::vector<sai_attribute_t> list(2);
sai_attribute_t &attr = list[0];

sai_mac_t mac1 = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
attr.id = SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS;
attr.value.mac = mac;
neighbor_attrs.push_back(list);
neighbor_attrs_count.push_back(2);
}

for (size_t j = 0; j < neighbor_attrs.size(); j++)
{
neighbor_attrs_array.push_back(neighbor_attrs[j].data());
}

std::vector<sai_status_t> statuses(count);
status = sai_neighbor_api->create_neighbor_entries(count, neighbors.data(), neighbor_attrs_count.data(), neighbor_attrs_array.data(), SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data());
ASSERT_SUCCESS("Failed to create neighbor");
for (size_t j = 0; j < statuses.size(); j++)
{
status = statuses[j];
ASSERT_SUCCESS("Failed to create neighbor # %zu", j);
}

for (uint32_t i = index; i < index + count; ++i)
{
sai_attribute_t attr;
attr.id = SAI_NEIGHBOR_ENTRY_ATTR_PACKET_ACTION;
attr.value.s32 = SAI_PACKET_ACTION_FORWARD;

status = sai_neighbor_api->set_neighbor_entry_attribute(&neighbors[i - index], &attr);

attrs.push_back(attr);

ASSERT_SUCCESS("Failed to set neighbor");
}

statuses.clear();
statuses.resize(attrs.size());

for (auto &attr: attrs)
{
attr.value.s32 = SAI_PACKET_ACTION_FORWARD;
}

status = sai_neighbor_api->set_neighbor_entries_attribute(
count,
neighbors.data(),
attrs.data(),
SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,
statuses.data());

ASSERT_SUCCESS("Failed to bulk set neighbor");

for (auto s: statuses)
{
status = s;

ASSERT_SUCCESS("Failed to bulk set neighbor on one of the neighbors");
}

status = sai_neighbor_api->remove_neighbor_entries(count, neighbors.data(), SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data());
ASSERT_SUCCESS("Failed to bulk remove neighbor entry");
}

void syncdThread()
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -764,6 +905,8 @@ int main()

test_bulk_fdb_create();

test_bulk_neighbor_set();

test_bulk_route_set();

sai_api_uninitialize();
Expand Down
5 changes: 5 additions & 0 deletions unittest/lib/test_sai_redis_neighbor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ TEST(libsairedis, neighbor)
EXPECT_NE(SAI_STATUS_SUCCESS, api->set_neighbor_entry_attribute(0,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->get_neighbor_entry_attribute(0,0,0));

EXPECT_NE(SAI_STATUS_SUCCESS, api->create_neighbor_entries(0,0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_neighbor_entries(0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->set_neighbor_entries_attribute(0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->get_neighbor_entries_attribute(0,0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));

EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, api->remove_all_neighbor_entries(0));
}
5 changes: 5 additions & 0 deletions unittest/vslib/test_sai_vs_neighbor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ TEST(libsaivs, neighbor)
EXPECT_NE(SAI_STATUS_SUCCESS, api->set_neighbor_entry_attribute(0,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->get_neighbor_entry_attribute(0,0,0));

EXPECT_NE(SAI_STATUS_SUCCESS, api->create_neighbor_entries(0,0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_neighbor_entries(0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->set_neighbor_entries_attribute(0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));
EXPECT_NE(SAI_STATUS_SUCCESS, api->get_neighbor_entries_attribute(0,0,0,0,SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR,0));

EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, api->remove_all_neighbor_entries(0));
}

0 comments on commit b33a902

Please sign in to comment.