Skip to content

Commit

Permalink
[unittest] Add more Meta tests (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Sep 27, 2021
1 parent 5863ed3 commit 812f7a5
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 32 deletions.
42 changes: 10 additions & 32 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -2644,6 +2620,8 @@ sai_status_t Meta::bulkCreate(

std::vector<sai_object_meta_key_t> 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);
Expand Down
200 changes: 200 additions & 0 deletions unittest/meta/TestMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,203 @@ 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<MetaTestSaiInterface>());

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<MetaTestSaiInterface>());

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<const sai_attribute_t*> 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));
}

TEST(Meta, quad_bulk_nat_entry)
{
Meta m(std::make_shared<MetaTestSaiInterface>());

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<const sai_attribute_t*> 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));
}

0 comments on commit 812f7a5

Please sign in to comment.