From e06ee450d5edc8ddcfeefa0893ab013780be9716 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Sun, 26 Sep 2021 13:11:42 +0200 Subject: [PATCH 1/2] [unittest] Add Meta bulk route quad test --- meta/Meta.cpp | 42 +++---------- unittest/meta/TestMeta.cpp | 125 +++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 32 deletions(-) diff --git a/meta/Meta.cpp b/meta/Meta.cpp index 275d746a0..c830f9af9 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -389,19 +389,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_my_sid_entry(my_sid_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status); sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_MY_SID_ENTRY, .objectkey = { .key = { .my_sid_entry = *my_sid_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status); status = m_implementation->remove(my_sid_entry); @@ -655,19 +649,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_my_sid_entry(my_sid_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status); sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_MY_SID_ENTRY, .objectkey = { .key = { .my_sid_entry = *my_sid_entry } } }; status = meta_generic_validation_create(meta_key, my_sid_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status); status = m_implementation->create(my_sid_entry, attr_count, attr_list); @@ -911,19 +899,13 @@ sai_status_t Meta::set( SWSS_LOG_ENTER(); sai_status_t status = meta_sai_validate_my_sid_entry(my_sid_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status); sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_MY_SID_ENTRY, .objectkey = { .key = { .my_sid_entry = *my_sid_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status); status = m_implementation->set(my_sid_entry, attr); @@ -1166,19 +1148,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_my_sid_entry(my_sid_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status); sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_MY_SID_ENTRY, .objectkey = { .key = { .my_sid_entry = *my_sid_entry } } }; status = meta_generic_validation_get(meta_key, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status); status = m_implementation->get(my_sid_entry, attr_count, attr_list); @@ -2644,6 +2620,8 @@ sai_status_t Meta::bulkCreate( std::vector vmk; + // TODO handle case when two 2 identical routes are created - it will throw, should return fail + for (uint32_t idx = 0; idx < object_count; idx++) { sai_status_t status = meta_sai_validate_route_entry(&route_entry[idx], true); diff --git a/unittest/meta/TestMeta.cpp b/unittest/meta/TestMeta.cpp index ab7d6425d..199634062 100644 --- a/unittest/meta/TestMeta.cpp +++ b/unittest/meta/TestMeta.cpp @@ -552,3 +552,128 @@ TEST(Meta, meta_validate_stats) EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.call_meta_validate_stats(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, vrId, 2, counter_ids, counters, SAI_STATS_MODE_READ)); } + +TEST(Meta, quad_my_sid_entry) +{ + Meta m(std::make_shared()); + + sai_object_id_t switchId = 0; + + sai_attribute_t attr; + + attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; + attr.value.booldata = true; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr)); + + sai_object_id_t vlanId = 0; + + attr.id = SAI_VLAN_ATTR_VLAN_ID; + attr.value.u16 = 2; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VLAN, &vlanId, switchId, 1, &attr)); + + sai_object_id_t vrId = 0; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &vrId, switchId, 0, &attr)); + + sai_attribute_t attrs[2]; + + attrs[0].id = SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR; + attrs[0].value.s32 = SAI_MY_SID_ENTRY_ENDPOINT_BEHAVIOR_E; + + sai_my_sid_entry_t e; + + memset(&e, 0, sizeof(e)); + + e.switch_id = switchId; + e.vr_id = vrId; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(&e, 1, attrs)); + + attr.id = SAI_MY_SID_ENTRY_ATTR_ENDPOINT_BEHAVIOR; + attr.value.s32 = SAI_MY_SID_ENTRY_ENDPOINT_BEHAVIOR_X; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.set(&e, &attr)); + + attr.id = SAI_MCAST_FDB_ENTRY_ATTR_GROUP_ID; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.get(&e, 1, &attr)); + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove(&e)); +} + +TEST(Meta, quad_bulk_route_entry) +{ + Meta m(std::make_shared()); + + sai_object_id_t switchId = 0; + + sai_attribute_t attr; + + attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; + attr.value.booldata = true; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr)); + + sai_object_id_t vlanId = 0; + + attr.id = SAI_VLAN_ATTR_VLAN_ID; + attr.value.u16 = 2; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VLAN, &vlanId, switchId, 1, &attr)); + + sai_object_id_t vrId = 0; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &vrId, switchId, 0, &attr)); + + // create + + sai_route_entry_t e[2]; + + memset(e, 0, sizeof(e)); + + e[0].switch_id = switchId; + e[1].switch_id = switchId; + + e[0].vr_id = vrId; + e[1].vr_id = vrId; + + e[0].destination.addr.ip4 = 1; + e[1].destination.addr.ip4 = 2; + + uint32_t attr_count[2]; + + attr_count[0] = 0; + attr_count[1] = 0; + + sai_attribute_t list1[2]; + sai_attribute_t list2[2]; + + std::vector alist; + + alist.push_back(list1); + alist.push_back(list2); + + const sai_attribute_t **attr_list = alist.data(); + + sai_status_t statuses[2]; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkCreate(2, e, attr_count, attr_list, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses)); + + // set + + sai_attribute_t setlist[2]; + + setlist[0].id = SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION; + setlist[0].value.s32 = SAI_PACKET_ACTION_DROP; + + setlist[1].id = SAI_ROUTE_ENTRY_ATTR_PACKET_ACTION; + setlist[1].value.s32 = SAI_PACKET_ACTION_DROP; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkSet(2, e, setlist, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses)); + + // remove + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkRemove(2, e, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses)); +} From c9e7e8575fb5af2040552ad4703c162b12cd8786 Mon Sep 17 00:00:00 2001 From: kcudnik Date: Sun, 26 Sep 2021 13:15:26 +0200 Subject: [PATCH 2/2] [unittest] Add Meta bulk nat quad test --- unittest/meta/TestMeta.cpp | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/unittest/meta/TestMeta.cpp b/unittest/meta/TestMeta.cpp index 199634062..ec1a54098 100644 --- a/unittest/meta/TestMeta.cpp +++ b/unittest/meta/TestMeta.cpp @@ -677,3 +677,78 @@ TEST(Meta, quad_bulk_route_entry) EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkRemove(2, e, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses)); } + +TEST(Meta, quad_bulk_nat_entry) +{ + Meta m(std::make_shared()); + + sai_object_id_t switchId = 0; + + sai_attribute_t attr; + + attr.id = SAI_SWITCH_ATTR_INIT_SWITCH; + attr.value.booldata = true; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr)); + + sai_object_id_t vlanId = 0; + + attr.id = SAI_VLAN_ATTR_VLAN_ID; + attr.value.u16 = 2; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VLAN, &vlanId, switchId, 1, &attr)); + + sai_object_id_t vrId = 0; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &vrId, switchId, 0, &attr)); + + // create + + sai_nat_entry_t e[2]; + + memset(e, 0, sizeof(e)); + + e[0].switch_id = switchId; + e[1].switch_id = switchId; + + e[0].vr_id = vrId; + e[1].vr_id = vrId; + + e[0].nat_type = SAI_NAT_TYPE_SOURCE_NAT; + e[1].nat_type = SAI_NAT_TYPE_DESTINATION_NAT; + + uint32_t attr_count[2]; + + attr_count[0] = 0; + attr_count[1] = 0; + + sai_attribute_t list1[2]; + sai_attribute_t list2[2]; + + std::vector alist; + + alist.push_back(list1); + alist.push_back(list2); + + const sai_attribute_t **attr_list = alist.data(); + + sai_status_t statuses[2]; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkCreate(2, e, attr_count, attr_list, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses)); + + // set + + sai_attribute_t setlist[2]; + + setlist[0].id = SAI_NAT_ENTRY_ATTR_NAT_TYPE; + setlist[0].value.s32 = SAI_NAT_TYPE_NONE; + + setlist[1].id = SAI_NAT_ENTRY_ATTR_NAT_TYPE; + setlist[1].value.s32 = SAI_NAT_TYPE_NONE; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkSet(2, e, setlist, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses)); + + // remove + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.bulkRemove(2, e, SAI_BULK_OP_ERROR_MODE_IGNORE_ERROR, statuses)); +}