Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[syncd] Enable bulk api for next hop objects #1487

Merged
merged 4 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,10 @@ sai_status_t VendorSai::bulkCreate(
ptr = m_apis.next_hop_group_api->create_next_hop_group_members;
break;

case SAI_OBJECT_TYPE_NEXT_HOP:
ptr = m_apis.next_hop_api->create_next_hops;
break;

case SAI_OBJECT_TYPE_SRV6_SIDLIST:
ptr = m_apis.srv6_api->create_srv6_sidlists;
break;
Expand Down Expand Up @@ -548,6 +552,10 @@ sai_status_t VendorSai::bulkRemove(
ptr = m_apis.next_hop_group_api->remove_next_hop_group_members;
break;

case SAI_OBJECT_TYPE_NEXT_HOP:
ptr = m_apis.next_hop_api->remove_next_hops;
break;

case SAI_OBJECT_TYPE_SRV6_SIDLIST:
ptr = m_apis.srv6_api->remove_srv6_sidlists;
break;
Expand Down
109 changes: 109 additions & 0 deletions syncd/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,113 @@ void test_bulk_next_hop_group_member_create()
ASSERT_SUCCESS("Failed to bulk remove nhgm");
}

void test_bulk_next_hop_create()
{
SWSS_LOG_ENTER();


sai_reinit();

sai_status_t status;

sai_next_hop_api_t *sai_next_hop_api = NULL;
sai_switch_api_t *sai_switch_api = NULL;
sai_lag_api_t *sai_lag_api = NULL;
sai_router_interface_api_t *sai_rif_api = NULL;
sai_virtual_router_api_t * sai_virtual_router_api = NULL;

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

uint32_t count = 3;

std::vector<sai_attribute_t> attrs;

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");

// 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");

std::vector<std::vector<sai_attribute_t>> nh_attrs;
std::vector<const sai_attribute_t *> nh_attrs_array;
std::vector<uint32_t> nh_attrs_count;
for (uint32_t i = 0; i < count; ++i)
{
std::vector<sai_attribute_t> list(3);
sai_attribute_t &nhattr0 = list[0];
sai_attribute_t &nhattr1 = list[1];
sai_attribute_t &nhattr2 = list[2];

nhattr0.id = SAI_NEXT_HOP_ATTR_TYPE;
nhattr0.value.s32 = SAI_NEXT_HOP_TYPE_IP;
nhattr1.id = SAI_NEXT_HOP_ATTR_IP;
nhattr1.value.ipaddr.addr_family = SAI_IP_ADDR_FAMILY_IPV4;
nhattr1.value.ipaddr.addr.ip4 = 0x10000001;
nhattr2.id = SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID;
nhattr2.value.oid = rif;

nh_attrs.push_back(list);
nh_attrs_count.push_back(3);
}

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

std::vector<sai_status_t> statuses(count);
std::vector<sai_object_id_t> object_id(count);
sai_next_hop_api->create_next_hops(switch_id, count, nh_attrs_count.data(), nh_attrs_array.data(), SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, object_id.data(), statuses.data());
ASSERT_SUCCESS("Failed to bulk create nh");

for (size_t j = 0; j < statuses.size(); j++)
{
status = statuses[j];
ASSERT_SUCCESS("Failed to create nh # %zu", j);
}

statuses.clear();

status = sai_next_hop_api->remove_next_hops(count, object_id.data(), SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses.data());
ASSERT_SUCCESS("Failed to bulk remove nh");
for (size_t j = 0; j < statuses.size(); j++)
{
status = statuses[j];
ASSERT_SUCCESS("Failed to remove nh # %zu", j);
}
}

void test_bulk_fdb_create()
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -907,6 +1014,8 @@ int main()

test_bulk_next_hop_group_member_create();

test_bulk_next_hop_create();

test_bulk_fdb_create();

test_bulk_neighbor_set();
Expand Down
6 changes: 6 additions & 0 deletions tests/BCM56850/bulk_object.rec
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
2017-06-14.01:55:56.555975|C|SAI_OBJECT_TYPE_NEXT_HOP_GROUP||oid:0x5000000000005|SAI_NEXT_HOP_GROUP_ATTR_TYPE=SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP||oid:0x5000000000006|SAI_NEXT_HOP_GROUP_ATTR_TYPE=SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP||oid:0x5000000000007|SAI_NEXT_HOP_GROUP_ATTR_TYPE=SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP
2017-06-14.01:55:56.555975|S|SAI_OBJECT_TYPE_NEXT_HOP_GROUP||oid:0x5000000000005|SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER=true||oid:0x5000000000006|SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER=true||oid:0x5000000000007|SAI_NEXT_HOP_GROUP_ATTR_SET_SWITCHOVER=true
2017-06-14.01:55:56.555975|R|SAI_OBJECT_TYPE_NEXT_HOP_GROUP||oid:0x5000000000005||oid:0x5000000000006||oid:0x5000000000007
2017-06-14.01:55:56.555975|G|SAI_STATUS_SUCCESS|SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID=oid:0x3000000000022
2017-06-14.01:55:56.555975|c|SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x60000000005bc|SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID=oid:0x3000000000022|SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS=00:E0:EC:C2:AD:F1|SAI_ROUTER_INTERFACE_ATTR_TYPE=SAI_ROUTER_INTERFACE_TYPE_PORT|SAI_ROUTER_INTERFACE_ATTR_PORT_ID=oid:0x1000000000009|SAI_ROUTER_INTERFACE_ATTR_MTU=9100
2017-06-14.01:55:56.555975|c|SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x600000000065d|SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID=oid:0x3000000000022|SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS=00:E0:EC:C2:AD:F1|SAI_ROUTER_INTERFACE_ATTR_TYPE=SAI_ROUTER_INTERFACE_TYPE_PORT|SAI_ROUTER_INTERFACE_ATTR_PORT_ID=oid:0x100000000001e|SAI_ROUTER_INTERFACE_ATTR_MTU=9100
2017-06-14.01:55:56.555975|c|SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000663|SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID=oid:0x3000000000022|SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS=00:E0:EC:C2:AD:F1|SAI_ROUTER_INTERFACE_ATTR_TYPE=SAI_ROUTER_INTERFACE_TYPE_PORT|SAI_ROUTER_INTERFACE_ATTR_PORT_ID=oid:0x1000000000005|SAI_ROUTER_INTERFACE_ATTR_MTU=9100
2017-06-14.01:55:56.555975|C|SAI_OBJECT_TYPE_NEXT_HOP||oid:0x4000000000667|SAI_NEXT_HOP_ATTR_TYPE=SAI_NEXT_HOP_TYPE_IP|SAI_NEXT_HOP_ATTR_IP=10.0.0.55|SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID=oid:0x60000000005bc||oid:0x4000000000668|SAI_NEXT_HOP_ATTR_TYPE=SAI_NEXT_HOP_TYPE_IP|SAI_NEXT_HOP_ATTR_IP=10.0.0.47|SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID=oid:0x6000000000663||oid:0x4000000000669|SAI_NEXT_HOP_ATTR_TYPE=SAI_NEXT_HOP_TYPE_IP|SAI_NEXT_HOP_ATTR_IP=10.0.0.57|SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID=oid:0x600000000065d
2017-06-14.01:55:56.555975|R|SAI_OBJECT_TYPE_NEXT_HOP||oid:0x4000000000667||oid:0x4000000000668||oid:0x4000000000669
2017-06-14.01:56:06.151337|a|APPLY_VIEW
2017-06-14.01:56:06.156740|A|SAI_STATUS_SUCCESS
Loading