From 26b22377767ed1e46bf8569b18bd02da4e2490ff Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Sat, 25 Sep 2021 08:50:24 +0200 Subject: [PATCH] [unittest] Update meta tests (#943) --- meta/Meta.cpp | 585 ++++++++++--------------------------- meta/Meta.h | 2 +- unittest/meta/Makefile.am | 1 + unittest/meta/MockMeta.cpp | 31 ++ unittest/meta/MockMeta.h | 27 ++ unittest/meta/TestMeta.cpp | 257 ++++++++++++++++ 6 files changed, 469 insertions(+), 434 deletions(-) create mode 100644 unittest/meta/MockMeta.cpp create mode 100644 unittest/meta/MockMeta.h diff --git a/meta/Meta.cpp b/meta/Meta.cpp index a90409b13..275d746a0 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -120,24 +120,21 @@ void Meta::dump() const { SWSS_LOG_ENTER(); - if (isEmpty() == false) - { - std::cout << "portRelatedSet: " << m_portRelatedSet.getAllPorts().size() << std::endl; - std::cout << "oids: " << m_oids.getAllOids().size() << std::endl; - std::cout << "attrKeys: " << m_attrKeys.getAllKeys().size() << std::endl; - std::cout << "saiObjectCollection: " << m_saiObjectCollection.getAllKeys().size() << std::endl; + SWSS_LOG_NOTICE("portRelatedSet: %zu", m_portRelatedSet.getAllPorts().size()); + SWSS_LOG_NOTICE("oids: %zu", m_oids.getAllOids().size()); + SWSS_LOG_NOTICE("attrKeys: %zu", m_attrKeys.getAllKeys().size()); + SWSS_LOG_NOTICE("saiObjectCollection: %zu", m_saiObjectCollection.getAllKeys().size()); - for (auto &oid: m_oids.getAllReferences()) - { - printf("oid: %s: count: %u\n", - sai_serialize_object_id(oid.first).c_str(), - oid.second); - } + for (auto &oid: m_oids.getAllReferences()) + { + SWSS_LOG_NOTICE("oid: %s: count: %u", + sai_serialize_object_id(oid.first).c_str(), + oid.second); + } - for (auto &mk: m_saiObjectCollection.getAllKeys()) - { - printf("objcollection: %s\n", sai_serialize_object_meta_key(mk).c_str()); - } + for (auto &mk: m_saiObjectCollection.getAllKeys()) + { + SWSS_LOG_NOTICE("objcollection: %s", sai_serialize_object_meta_key(mk).c_str()); } } @@ -149,19 +146,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_oid(object_type, &object_id, SAI_NULL_OBJECT_ID, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = object_id } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(object_type, object_id); @@ -182,19 +173,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_fdb_entry(fdb_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_FDB_ENTRY, .objectkey = { .key = { .fdb_entry = *fdb_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(fdb_entry); @@ -215,19 +200,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_mcast_fdb_entry(mcast_fdb_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_MCAST_FDB_ENTRY, .objectkey = { .key = { .mcast_fdb_entry = *mcast_fdb_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(mcast_fdb_entry); @@ -248,19 +227,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_neighbor_entry(neighbor_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, .objectkey = { .key = { .neighbor_entry = *neighbor_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(neighbor_entry); @@ -281,19 +254,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_route_entry(route_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_ROUTE_ENTRY, .objectkey = { .key = { .route_entry = *route_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(route_entry); @@ -314,19 +281,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_l2mc_entry(l2mc_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_L2MC_ENTRY, .objectkey = { .key = { .l2mc_entry = *l2mc_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(l2mc_entry); @@ -347,19 +308,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_ipmc_entry(ipmc_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_IPMC_ENTRY, .objectkey = { .key = { .ipmc_entry = *ipmc_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(ipmc_entry); @@ -380,19 +335,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_nat_entry(nat_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NAT_ENTRY, .objectkey = { .key = { .nat_entry = *nat_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(nat_entry); @@ -413,19 +362,13 @@ sai_status_t Meta::remove( sai_status_t status = meta_sai_validate_inseg_entry(inseg_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_INSEG_ENTRY, .objectkey = { .key = { .inseg_entry = *inseg_entry } } }; status = meta_generic_validation_remove(meta_key); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->remove(inseg_entry); @@ -481,19 +424,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_fdb_entry(fdb_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_FDB_ENTRY, .objectkey = { .key = { .fdb_entry = *fdb_entry } } }; status = meta_generic_validation_create(meta_key, fdb_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(fdb_entry, attr_count, attr_list); @@ -516,19 +453,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_mcast_fdb_entry(mcast_fdb_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_MCAST_FDB_ENTRY, .objectkey = { .key = { .mcast_fdb_entry = *mcast_fdb_entry } } }; status = meta_generic_validation_create(meta_key, mcast_fdb_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(mcast_fdb_entry, attr_count, attr_list); @@ -551,19 +482,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_neighbor_entry(neighbor_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, .objectkey = { .key = { .neighbor_entry = *neighbor_entry } } }; status = meta_generic_validation_create(meta_key, neighbor_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(neighbor_entry, attr_count, attr_list); @@ -585,19 +510,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_route_entry(route_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_ROUTE_ENTRY, .objectkey = { .key = { .route_entry = *route_entry } } }; status = meta_generic_validation_create(meta_key, route_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(route_entry, attr_count, attr_list); @@ -620,19 +539,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_l2mc_entry(l2mc_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_L2MC_ENTRY, .objectkey = { .key = { .l2mc_entry = *l2mc_entry } } }; status = meta_generic_validation_create(meta_key, l2mc_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(l2mc_entry, attr_count, attr_list); @@ -655,19 +568,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_ipmc_entry(ipmc_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_IPMC_ENTRY, .objectkey = { .key = { .ipmc_entry = *ipmc_entry } } }; status = meta_generic_validation_create(meta_key, ipmc_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(ipmc_entry, attr_count, attr_list); @@ -690,19 +597,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_inseg_entry(inseg_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_INSEG_ENTRY, .objectkey = { .key = { .inseg_entry = *inseg_entry } } }; status = meta_generic_validation_create(meta_key, inseg_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(inseg_entry, attr_count, attr_list); @@ -725,19 +626,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_nat_entry(nat_entry, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NAT_ENTRY, .objectkey = { .key = { .nat_entry = *nat_entry } } }; status = meta_generic_validation_create(meta_key, nat_entry->switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(nat_entry, attr_count, attr_list); @@ -794,19 +689,13 @@ sai_status_t Meta::set( sai_status_t status = meta_sai_validate_fdb_entry(fdb_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_FDB_ENTRY, .objectkey = { .key = { .fdb_entry = *fdb_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(fdb_entry, attr); @@ -828,19 +717,13 @@ sai_status_t Meta::set( sai_status_t status = meta_sai_validate_mcast_fdb_entry(mcast_fdb_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_MCAST_FDB_ENTRY, .objectkey = { .key = { .mcast_fdb_entry = *mcast_fdb_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(mcast_fdb_entry, attr); @@ -862,19 +745,13 @@ sai_status_t Meta::set( sai_status_t status = meta_sai_validate_neighbor_entry(neighbor_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, .objectkey = { .key = { .neighbor_entry = *neighbor_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(neighbor_entry, attr); @@ -896,19 +773,13 @@ sai_status_t Meta::set( sai_status_t status = meta_sai_validate_route_entry(route_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_ROUTE_ENTRY, .objectkey = { .key = { .route_entry = *route_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(route_entry, attr); @@ -930,19 +801,13 @@ sai_status_t Meta::set( sai_status_t status = meta_sai_validate_l2mc_entry(l2mc_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_L2MC_ENTRY, .objectkey = { .key = { .l2mc_entry = *l2mc_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(l2mc_entry, attr); @@ -964,19 +829,13 @@ sai_status_t Meta::set( sai_status_t status = meta_sai_validate_ipmc_entry(ipmc_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_IPMC_ENTRY, .objectkey = { .key = { .ipmc_entry = *ipmc_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(ipmc_entry, attr); @@ -998,19 +857,13 @@ sai_status_t Meta::set( sai_status_t status = meta_sai_validate_inseg_entry(inseg_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_INSEG_ENTRY, .objectkey = { .key = { .inseg_entry = *inseg_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(inseg_entry, attr); @@ -1031,19 +884,13 @@ sai_status_t Meta::set( SWSS_LOG_ENTER(); sai_status_t status = meta_sai_validate_nat_entry(nat_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NAT_ENTRY, .objectkey = { .key = { .nat_entry = *nat_entry } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(nat_entry, attr); @@ -1101,19 +948,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_fdb_entry(fdb_entry, false, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_FDB_ENTRY, .objectkey = { .key = { .fdb_entry = *fdb_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(fdb_entry, attr_count, attr_list); @@ -1136,19 +977,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_mcast_fdb_entry(mcast_fdb_entry, false, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_MCAST_FDB_ENTRY, .objectkey = { .key = { .mcast_fdb_entry = *mcast_fdb_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(mcast_fdb_entry, attr_count, attr_list); @@ -1169,19 +1004,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_neighbor_entry(neighbor_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NEIGHBOR_ENTRY, .objectkey = { .key = { .neighbor_entry = *neighbor_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(neighbor_entry, attr_count, attr_list); @@ -1202,19 +1031,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_route_entry(route_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_ROUTE_ENTRY, .objectkey = { .key = { .route_entry = *route_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(route_entry, attr_count, attr_list); @@ -1235,19 +1058,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_l2mc_entry(l2mc_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_L2MC_ENTRY, .objectkey = { .key = { .l2mc_entry = *l2mc_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(l2mc_entry, attr_count, attr_list); @@ -1268,19 +1085,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_ipmc_entry(ipmc_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_IPMC_ENTRY, .objectkey = { .key = { .ipmc_entry = *ipmc_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(ipmc_entry, attr_count, attr_list); @@ -1301,19 +1112,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_inseg_entry(inseg_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_INSEG_ENTRY, .objectkey = { .key = { .inseg_entry = *inseg_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(inseg_entry, attr_count, attr_list); @@ -1334,19 +1139,13 @@ sai_status_t Meta::get( sai_status_t status = meta_sai_validate_nat_entry(nat_entry, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = SAI_OBJECT_TYPE_NAT_ENTRY, .objectkey = { .key = { .nat_entry = *nat_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(nat_entry, attr_count, attr_list); @@ -1402,19 +1201,13 @@ sai_status_t Meta::create( sai_status_t status = meta_sai_validate_oid(object_type, object_id, switch_id, true); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = SAI_NULL_OBJECT_ID } } }; status = meta_generic_validation_create(meta_key, switch_id, attr_count, attr_list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->create(object_type, object_id, switch_id, attr_count, attr_list); @@ -1448,21 +1241,25 @@ sai_status_t Meta::set( { SWSS_LOG_ENTER(); - sai_status_t status = meta_sai_validate_oid(object_type, &object_id, SAI_NULL_OBJECT_ID, false); + sai_object_id_t switch_id = switchIdQuery(object_id); - if (status != SAI_STATUS_SUCCESS) + if (!m_oids.objectReferenceExists(switch_id)) { - return status; + SWSS_LOG_ERROR("switch id %s doesn't exist", + sai_serialize_object_id(switch_id).c_str()); + + return SAI_STATUS_INVALID_PARAMETER; } + sai_status_t status = meta_sai_validate_oid(object_type, &object_id, SAI_NULL_OBJECT_ID, false); + + CHECK_STATUS_SUCCESS(status) + sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = object_id } } }; status = meta_generic_validation_set(meta_key, attr); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) status = m_implementation->set(object_type, object_id, attr); @@ -1484,33 +1281,22 @@ sai_status_t Meta::get( { SWSS_LOG_ENTER(); + sai_object_id_t switch_id = switchIdQuery(object_id); + sai_status_t status = meta_sai_validate_oid(object_type, &object_id, SAI_NULL_OBJECT_ID, false); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) sai_object_meta_key_t meta_key = { .objecttype = object_type, .objectkey = { .key = { .object_id = object_id } } }; 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(object_type, object_id, attr_count, attr_list); if (status == SAI_STATUS_SUCCESS) { - sai_object_id_t switch_id = switchIdQuery(object_id); - - if (!m_oids.objectReferenceExists(switch_id)) - { - SWSS_LOG_ERROR("switch id 0x%" PRIx64 " doesn't exist", switch_id); - } - meta_generic_validation_post_get(meta_key, switch_id, attr_count, attr_list); } @@ -1595,19 +1381,10 @@ sai_status_t Meta::flushFdbEntries( attrs[attr->id] = attr; - if (md.flags != SAI_ATTR_FLAGS_CREATE_ONLY) - { - META_LOG_ERROR(md, "attr is expected to be marked as CREATE_ONLY"); - - return SAI_STATUS_INVALID_PARAMETER; - } - - if (md.isconditional || md.validonlylength > 0) - { - META_LOG_ERROR(md, "attr should not be conditional or validonly"); - - return SAI_STATUS_INVALID_PARAMETER; - } + // SAI metadata checks if + // - attribute is create only + // - is not conditional + // - is not valid only switch (md.attrvaluetype) { @@ -1627,17 +1404,15 @@ sai_status_t Meta::flushFdbEntries( { sai_status_t status = meta_generic_validation_objlist(md, switch_id, 1, &value.oid); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } default: - META_LOG_THROW(md, "serialization type is not supported yet FIXME"); + META_LOG_THROW(md, "value type %s is not supported yet, FIXME", + sai_serialize_attr_value_type(md.attrvaluetype).c_str()); } } @@ -1713,7 +1488,7 @@ sai_status_t Meta::flushFdbEntries( return SAI_STATUS_INVALID_PARAMETER; } } #define PARAMETER_CHECK_OID_OBJECT_TYPE(param, OT) { \ - sai_object_type_t _ot = objectTypeQuery(param); \ + sai_object_type_t _ot = objectTypeQuery(param); \ if (_ot != (OT)) { \ SWSS_LOG_ERROR("parameter " # param " %s object type is %s, but expected %s", \ sai_serialize_object_id(param).c_str(), \ @@ -1749,11 +1524,14 @@ sai_status_t Meta::objectTypeGetAvailability( PARAMETER_CHECK_OID_OBJECT_TYPE(switchId, SAI_OBJECT_TYPE_SWITCH); PARAMETER_CHECK_OID_EXISTS(switchId, SAI_OBJECT_TYPE_SWITCH); PARAMETER_CHECK_OBJECT_TYPE_VALID(objectType); + // When checking availability of a resource solely based on OBJECT_TYPE, attrCount is 0 + if (attrCount) { PARAMETER_CHECK_IF_NOT_NULL(attrList); } + PARAMETER_CHECK_IF_NOT_NULL(count); auto info = sai_metadata_get_object_type_info(objectType); @@ -1810,7 +1588,7 @@ sai_status_t Meta::objectTypeGetAvailability( default: - SWSS_LOG_THROW("value type %s not supported yet, FIXME!", + META_LOG_THROW(*mdp, "value type %s not supported yet, FIXME!", sai_serialize_attr_value_type(mdp->attrvaluetype).c_str()); } } @@ -1849,10 +1627,11 @@ sai_status_t Meta::queryAttributeCapability( auto status = m_implementation->queryAttributeCapability(switchId, objectType, attrId, capability); + // no post validation required + return status; } - sai_status_t Meta::queryAattributeEnumValuesCapability( _In_ sai_object_id_t switchId, _In_ sai_object_type_t objectType, @@ -1898,6 +1677,7 @@ sai_status_t Meta::queryAattributeEnumValuesCapability( if (enumValuesCapability->list) { // check if all returned values are members of defined enum + for (uint32_t idx = 0; idx < enumValuesCapability->count; idx++) { int val = enumValuesCapability->list[idx]; @@ -2126,7 +1906,6 @@ sai_status_t Meta::bulkRemove( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(route_entry); @@ -2185,7 +1964,6 @@ sai_status_t Meta::bulkRemove( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(nat_entry); @@ -2303,7 +2081,6 @@ sai_status_t Meta::bulkRemove( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(fdb_entry); @@ -2362,7 +2139,6 @@ sai_status_t Meta::bulkRemove( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(inseg_entry); @@ -2481,7 +2257,6 @@ sai_status_t Meta::bulkSet( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(route_entry); PARAMETER_CHECK_IF_NOT_NULL(attr_list); @@ -2539,7 +2314,6 @@ sai_status_t Meta::bulkSet( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(nat_entry); PARAMETER_CHECK_IF_NOT_NULL(attr_list); @@ -2655,7 +2429,6 @@ sai_status_t Meta::bulkSet( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(fdb_entry); PARAMETER_CHECK_IF_NOT_NULL(attr_list); @@ -2713,7 +2486,6 @@ sai_status_t Meta::bulkSet( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(inseg_entry); PARAMETER_CHECK_IF_NOT_NULL(attr_list); @@ -2791,6 +2563,11 @@ sai_status_t Meta::bulkCreate( return SAI_STATUS_INVALID_PARAMETER; } + + if (object_type == SAI_OBJECT_TYPE_SWITCH) + { + SWSS_LOG_THROW("create bulk switch not supported"); + } } PARAMETER_CHECK_IF_NOT_NULL(object_id); @@ -2829,11 +2606,6 @@ sai_status_t Meta::bulkCreate( { vmk[idx].objectkey.key.object_id = object_id[idx]; // assign new created object id - if (vmk[idx].objecttype == SAI_OBJECT_TYPE_SWITCH) - { - SWSS_LOG_THROW("create bulk switch not supported"); - } - meta_generic_validation_post_create(vmk[idx], switchId, attr_count[idx], attr_list[idx]); } } @@ -2858,7 +2630,6 @@ sai_status_t Meta::bulkCreate( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(route_entry); PARAMETER_CHECK_IF_NOT_NULL(attr_count); @@ -2918,7 +2689,6 @@ sai_status_t Meta::bulkCreate( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(fdb_entry); PARAMETER_CHECK_IF_NOT_NULL(attr_count); @@ -2978,7 +2748,6 @@ sai_status_t Meta::bulkCreate( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(inseg_entry); PARAMETER_CHECK_IF_NOT_NULL(attr_count); @@ -3038,7 +2807,6 @@ sai_status_t Meta::bulkCreate( object_statuses[idx] = SAI_STATUS_NOT_EXECUTED; } - //PARAMETER_CHECK_OBJECT_TYPE_VALID(object_type); PARAMETER_CHECK_POSITIVE(object_count); PARAMETER_CHECK_IF_NOT_NULL(nat_entry); PARAMETER_CHECK_IF_NOT_NULL(attr_count); @@ -3163,7 +2931,19 @@ sai_status_t Meta::logSet( { SWSS_LOG_ENTER(); - // TODO check api and log level + if (sai_metadata_get_enum_value_name(&sai_metadata_enum_sai_api_t, api) == nullptr) + { + SWSS_LOG_ERROR("api value %d is not in range on %s", api, sai_metadata_enum_sai_api_t.name); + + return SAI_STATUS_INVALID_PARAMETER; + } + + if (sai_metadata_get_enum_value_name(&sai_metadata_enum_sai_log_level_t, log_level) == nullptr) + { + SWSS_LOG_ERROR("log level value %d is not in range on %s", log_level, sai_metadata_enum_sai_log_level_t.name); + + return SAI_STATUS_INVALID_PARAMETER; + } return m_implementation->logSet(api, log_level); } @@ -3774,6 +3554,11 @@ sai_status_t Meta::meta_sai_validate_fdb_entry( { SWSS_LOG_ENTER(); + if (create && get) + { + SWSS_LOG_THROW("can't be create and get at the same time"); + } + if (fdb_entry == NULL) { SWSS_LOG_ERROR("fdb_entry pointer is NULL"); @@ -3781,15 +3566,6 @@ sai_status_t Meta::meta_sai_validate_fdb_entry( return SAI_STATUS_INVALID_PARAMETER; } - //sai_vlan_id_t vlan_id = fdb_entry->vlan_id; - - //if (vlan_id < MINIMUM_VLAN_NUMBER || vlan_id > MAXIMUM_VLAN_NUMBER) - //{ - // SWSS_LOG_ERROR("invalid vlan number %d expected <%d..%d>", vlan_id, MINIMUM_VLAN_NUMBER, MAXIMUM_VLAN_NUMBER); - - // return SAI_STATUS_INVALID_PARAMETER; - //} - // check if fdb entry exists sai_object_meta_key_t meta_key_fdb = { .objecttype = SAI_OBJECT_TYPE_FDB_ENTRY, .objectkey = { .key = { .fdb_entry = *fdb_entry } } }; @@ -4637,10 +4413,7 @@ sai_status_t Meta::meta_generic_validation_create( sai_status_t status = meta_generic_validate_non_object_on_create(meta_key, switch_id); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) std::unordered_map attrs; @@ -4775,10 +4548,7 @@ sai_status_t Meta::meta_generic_validation_create( { status = meta_generic_validation_objlist(md, switch_id, 1, &value.oid); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -4788,10 +4558,7 @@ sai_status_t Meta::meta_generic_validation_create( { status = meta_generic_validation_objlist(md, switch_id, value.objlist.count, value.objlist.list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -4822,10 +4589,7 @@ sai_status_t Meta::meta_generic_validation_create( status = meta_generic_validation_objlist(md, switch_id, 1, &value.aclfield.data.oid); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -4840,10 +4604,7 @@ sai_status_t Meta::meta_generic_validation_create( status = meta_generic_validation_objlist(md, switch_id, value.aclfield.data.objlist.count, value.aclfield.data.objlist.list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -4875,10 +4636,7 @@ sai_status_t Meta::meta_generic_validation_create( status = meta_generic_validation_objlist(md, switch_id, 1, &value.aclaction.parameter.oid); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -4893,10 +4651,7 @@ sai_status_t Meta::meta_generic_validation_create( status = meta_generic_validation_objlist(md, switch_id, value.aclaction.parameter.objlist.count, value.aclaction.parameter.objlist.list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -5445,10 +5200,7 @@ sai_status_t Meta::meta_generic_validation_set( sai_status_t status = meta_generic_validation_objlist(md, switch_id, 1, &value.oid); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -5458,10 +5210,7 @@ sai_status_t Meta::meta_generic_validation_set( { sai_status_t status = meta_generic_validation_objlist(md, switch_id, value.objlist.count, value.objlist.list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -5491,10 +5240,7 @@ sai_status_t Meta::meta_generic_validation_set( sai_status_t status = meta_generic_validation_objlist(md, switch_id, 1, &value.aclfield.data.oid); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -5509,10 +5255,7 @@ sai_status_t Meta::meta_generic_validation_set( sai_status_t status = meta_generic_validation_objlist(md, switch_id, value.aclfield.data.objlist.count, value.aclfield.data.objlist.list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -5543,10 +5286,7 @@ sai_status_t Meta::meta_generic_validation_set( sai_status_t status = meta_generic_validation_objlist(md, switch_id, 1, &value.aclaction.parameter.oid); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -5561,10 +5301,7 @@ sai_status_t Meta::meta_generic_validation_set( sai_status_t status = meta_generic_validation_objlist(md, switch_id, value.aclaction.parameter.objlist.count, value.aclaction.parameter.objlist.list); - if (status != SAI_STATUS_SUCCESS) - { - return status; - } + CHECK_STATUS_SUCCESS(status) break; } @@ -6612,31 +6349,11 @@ sai_object_id_t Meta::meta_extract_switch_id( * struct member contains switch_id, we need to extract it here. * * NOTE: we could have this in metadata predefined for all non object ids. + * + * NOTE: first field in every entry is switch id */ - for (size_t j = 0; j < info->structmemberscount; ++j) - { - const sai_struct_member_info_t *m = info->structmembers[j]; - - if (m->membervaluetype != SAI_ATTR_VALUE_TYPE_OBJECT_ID) - { - continue; - } - - for (size_t k = 0 ; k < m->allowedobjecttypeslength; k++) - { - sai_object_type_t ot = m->allowedobjecttypes[k]; - - if (ot == SAI_OBJECT_TYPE_SWITCH) - { - return m->getoid(&meta_key); - } - } - } - - SWSS_LOG_ERROR("unable to find switch id inside non object id"); - - return SAI_NULL_OBJECT_ID; + return meta_key.objectkey.key.object_id; } else { @@ -6834,6 +6551,8 @@ void Meta::meta_generic_validation_post_get_objlist( if (!m_saiObjectCollection.objectExists(key)) { m_saiObjectCollection.createObject(key); + + // TODO on post get on attribute, if snoop should we increase reference if not read_only ? } } diff --git a/meta/Meta.h b/meta/Meta.h index 696d04600..22a9d066f 100644 --- a/meta/Meta.h +++ b/meta/Meta.h @@ -384,7 +384,7 @@ namespace saimeta _In_ const uint32_t attr_count, _In_ sai_attribute_t *attr_list); - private: // stats + protected: // stats sai_status_t meta_validate_stats( _In_ sai_object_type_t object_type, diff --git a/unittest/meta/Makefile.am b/unittest/meta/Makefile.am index 7e94e56e8..48a52f103 100644 --- a/unittest/meta/Makefile.am +++ b/unittest/meta/Makefile.am @@ -13,6 +13,7 @@ tests_SOURCES = \ ../../lib/SwitchConfigContainer.cpp \ ../../lib/ZeroMQChannel.cpp \ ../../lib/Channel.cpp \ + MockMeta.cpp \ TestAttrKeyMap.cpp \ TestGlobals.cpp \ TestMetaKeyHasher.cpp \ diff --git a/unittest/meta/MockMeta.cpp b/unittest/meta/MockMeta.cpp new file mode 100644 index 000000000..081d038e6 --- /dev/null +++ b/unittest/meta/MockMeta.cpp @@ -0,0 +1,31 @@ +#include "MockMeta.h" + +using namespace saimeta; + +MockMeta::MockMeta( + _In_ std::shared_ptr impl): + Meta(impl) +{ + SWSS_LOG_ENTER(); + + // empty +} + +sai_status_t MockMeta::call_meta_validate_stats( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ uint32_t number_of_counters, + _In_ const sai_stat_id_t *counter_ids, + _Out_ uint64_t *counters, + _In_ sai_stats_mode_t mode) +{ + SWSS_LOG_ENTER(); + + return meta_validate_stats( + object_type, + object_id, + number_of_counters, + counter_ids, + counters, + mode); +} diff --git a/unittest/meta/MockMeta.h b/unittest/meta/MockMeta.h new file mode 100644 index 000000000..2a8f05460 --- /dev/null +++ b/unittest/meta/MockMeta.h @@ -0,0 +1,27 @@ +#include "Meta.h" + +namespace saimeta +{ + class MockMeta: + public Meta + { + public: + + using sairedis::SaiInterface::set; // name hiding + + MockMeta( + _In_ std::shared_ptr impl); + + virtual ~MockMeta() = default; + + public: + + sai_status_t call_meta_validate_stats( + _In_ sai_object_type_t object_type, + _In_ sai_object_id_t object_id, + _In_ uint32_t number_of_counters, + _In_ const sai_stat_id_t *counter_ids, + _Out_ uint64_t *counters, + _In_ sai_stats_mode_t mode); + }; +} diff --git a/unittest/meta/TestMeta.cpp b/unittest/meta/TestMeta.cpp index 1b2a9eae0..ab7d6425d 100644 --- a/unittest/meta/TestMeta.cpp +++ b/unittest/meta/TestMeta.cpp @@ -1,4 +1,5 @@ #include "Meta.h" +#include "MockMeta.h" #include "MetaTestSaiInterface.h" #include @@ -294,4 +295,260 @@ TEST(Meta, flushFdbEntries) EXPECT_NE(SAI_STATUS_SUCCESS, m.flushFdbEntries(switchId, 2, attrs)); EXPECT_EQ(SAI_STATUS_SUCCESS, m.flushFdbEntries(switchId, 1, attrs)); + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.flushFdbEntries(0x21000000000001, 1, attrs)); + EXPECT_EQ(SAI_STATUS_SUCCESS, m.flushFdbEntries(0x21000000000000, 1, attrs)); + + // SAI_FDB_FLUSH_ENTRY_TYPE attribute out of range + + attrs[0].value.s32 = 1000; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.flushFdbEntries(switchId, 1, attrs)); + + // test flush with vlan + + 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)); + + attrs[0].id = SAI_FDB_FLUSH_ATTR_ENTRY_TYPE; + attrs[0].value.s32 = SAI_FDB_FLUSH_ENTRY_TYPE_ALL; + + attrs[1].id = SAI_FDB_FLUSH_ATTR_BV_ID; + attrs[1].value.oid = vlanId; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.flushFdbEntries(switchId, 2, attrs)); + + // test dynamic flush + + attrs[0].value.s32 = SAI_FDB_FLUSH_ENTRY_TYPE_DYNAMIC; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.flushFdbEntries(switchId, 2, attrs)); + + // test static flush + + attrs[0].value.s32 = SAI_FDB_FLUSH_ENTRY_TYPE_STATIC; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.flushFdbEntries(switchId, 2, attrs)); +} + +TEST(Meta, meta_warm_boot_notify) +{ + 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)); + + m.meta_warm_boot_notify(); +} + +TEST(Meta, meta_init_db) +{ + 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)); + + m.meta_init_db(); +} + +TEST(Meta, dump) +{ + 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)); + + m.dump(); +} + +TEST(Meta, objectTypeGetAvailability) +{ + 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)); + + EXPECT_NE(SAI_STATUS_SUCCESS, m.objectTypeGetAvailability(0, SAI_OBJECT_TYPE_NULL, 0, nullptr, nullptr)); + + EXPECT_NE(SAI_STATUS_SUCCESS, m.objectTypeGetAvailability(switchId, SAI_OBJECT_TYPE_NULL, 0, nullptr, nullptr)); + + attr.id = SAI_DEBUG_COUNTER_ATTR_TYPE; + attr.value.s32 = SAI_DEBUG_COUNTER_TYPE_PORT_IN_DROP_REASONS; + + uint64_t count; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.objectTypeGetAvailability(switchId, SAI_OBJECT_TYPE_DEBUG_COUNTER, 1, &attr, &count)); + + // invalid attribute + + attr.id = 100000; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.objectTypeGetAvailability(switchId, SAI_OBJECT_TYPE_DEBUG_COUNTER, 1, &attr, &count)); + + // defined multiple times + + sai_attribute_t attrs[2]; + + attrs[0].id = SAI_DEBUG_COUNTER_ATTR_TYPE; + attrs[0].value.s32 = SAI_DEBUG_COUNTER_TYPE_PORT_IN_DROP_REASONS; + + attrs[1].id = SAI_DEBUG_COUNTER_ATTR_TYPE; + attrs[1].value.s32 = SAI_DEBUG_COUNTER_TYPE_PORT_IN_DROP_REASONS; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.objectTypeGetAvailability(switchId, SAI_OBJECT_TYPE_DEBUG_COUNTER, 2, attrs, &count)); + + // enum not on allowed list + + attr.id = SAI_DEBUG_COUNTER_ATTR_TYPE; + attr.value.s32 = 10000; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.objectTypeGetAvailability(switchId, SAI_OBJECT_TYPE_DEBUG_COUNTER, 1, &attr, &count)); + + // not resource type + + attr.id = SAI_DEBUG_COUNTER_ATTR_BIND_METHOD; + attr.value.s32 = 0; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.objectTypeGetAvailability(switchId, SAI_OBJECT_TYPE_DEBUG_COUNTER, 1, &attr, &count)); +} + +TEST(Meta, queryAttributeCapability) +{ + 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_attr_capability_t cap; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.queryAttributeCapability(switchId, SAI_OBJECT_TYPE_ACL_ENTRY, SAI_ACL_ENTRY_ATTR_TABLE_ID, &cap)); + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.queryAttributeCapability(switchId, SAI_OBJECT_TYPE_ACL_ENTRY, 100000, &cap)); +} + +TEST(Meta, queryAattributeEnumValuesCapability) +{ + 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_s32_list_t list; + + int32_t vals[2]; + + list.count = 2; + list.list = vals; + + vals[0] = 0; + vals[1] = 100000; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.queryAattributeEnumValuesCapability(switchId, SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_SWITCHING_MODE, &list)); + + // set count without list; + + list.list = nullptr; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.queryAattributeEnumValuesCapability(switchId, SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_SWITCHING_MODE, &list)); + + // non enum attribute + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.queryAattributeEnumValuesCapability(switchId, SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_BCAST_CPU_FLOOD_ENABLE, &list)); + + // invalid attribute + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.queryAattributeEnumValuesCapability(switchId, SAI_OBJECT_TYPE_SWITCH, 10000, &list)); +} + +TEST(Meta, meta_validate_stats) +{ + MockMeta 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_stat_id_t counter_ids[2]; + + counter_ids[0] = SAI_VLAN_STAT_IN_OCTETS; + counter_ids[1] = SAI_VLAN_STAT_IN_PACKETS; + + uint64_t counters[2]; + + m.meta_unittests_enable(true); + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.call_meta_validate_stats(SAI_OBJECT_TYPE_VLAN, vlanId, 2, counter_ids, counters, SAI_STATS_MODE_READ)); + + // invalid mode + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.call_meta_validate_stats(SAI_OBJECT_TYPE_VLAN, vlanId, 2, counter_ids, counters, (sai_stats_mode_t)7)); +#pragma GCC diagnostic pop + + // invalid counter + + counter_ids[0] = 10000; + + EXPECT_EQ(SAI_STATUS_INVALID_PARAMETER, m.call_meta_validate_stats(SAI_OBJECT_TYPE_VLAN, vlanId, 2, counter_ids, counters, SAI_STATS_MODE_READ)); + + // object with no stats + + sai_object_id_t vrId = 0; + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_VIRTUAL_ROUTER, &vrId, switchId, 0, &attr)); + + 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)); }