From f04bd204af7c7750caabfdb674f262be329fe00b Mon Sep 17 00:00:00 2001 From: Shitanshu Shah Date: Tue, 15 Nov 2022 20:47:45 -0800 Subject: [PATCH 1/7] validation support for SAI_ATTR_VALUE_TYPE_JSON --- meta/Meta.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/meta/Meta.cpp b/meta/Meta.cpp index cd0d112d5..deac7b532 100644 --- a/meta/Meta.cpp +++ b/meta/Meta.cpp @@ -3680,6 +3680,7 @@ void Meta::meta_generic_validation_post_remove( case SAI_ATTR_VALUE_TYPE_INT32_RANGE: case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST: case SAI_ATTR_VALUE_TYPE_SEGMENT_LIST: + case SAI_ATTR_VALUE_TYPE_JSON: // no special action required break; @@ -4928,6 +4929,10 @@ sai_status_t Meta::meta_generic_validation_create( VALIDATION_LIST(md, value.segmentlist); break; + case SAI_ATTR_VALUE_TYPE_JSON: + VALIDATION_LIST(md, value.json.json); + break; + case SAI_ATTR_VALUE_TYPE_UINT32_RANGE: if (value.u32range.min > value.u32range.max) @@ -5581,6 +5586,10 @@ sai_status_t Meta::meta_generic_validation_set( VALIDATION_LIST(md, value.segmentlist); break; + case SAI_ATTR_VALUE_TYPE_JSON: + VALIDATION_LIST(md, value.json.json); + break; + case SAI_ATTR_VALUE_TYPE_UINT32_RANGE: if (value.u32range.min > value.u32range.max) @@ -5992,6 +6001,10 @@ sai_status_t Meta::meta_generic_validation_get( VALIDATION_LIST(md, value.segmentlist); break; + case SAI_ATTR_VALUE_TYPE_JSON: + VALIDATION_LIST(md, value.json.json); + break; + case SAI_ATTR_VALUE_TYPE_UINT32_RANGE: case SAI_ATTR_VALUE_TYPE_INT32_RANGE: // primitives @@ -6238,6 +6251,10 @@ void Meta::meta_generic_validation_post_get( VALIDATION_LIST_GET(md, value.segmentlist); break; + case SAI_ATTR_VALUE_TYPE_JSON: + VALIDATION_LIST_GET(md, value.json.json); + break; + case SAI_ATTR_VALUE_TYPE_UINT32_RANGE: if (value.u32range.min > value.u32range.max) @@ -7136,6 +7153,7 @@ void Meta::meta_generic_validation_post_create( case SAI_ATTR_VALUE_TYPE_INT32_RANGE: case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST: case SAI_ATTR_VALUE_TYPE_SEGMENT_LIST: + case SAI_ATTR_VALUE_TYPE_JSON: // no special action required break; @@ -7376,6 +7394,7 @@ void Meta::meta_generic_validation_post_set( case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST: case SAI_ATTR_VALUE_TYPE_ACL_CAPABILITY: case SAI_ATTR_VALUE_TYPE_SEGMENT_LIST: + case SAI_ATTR_VALUE_TYPE_JSON: // no special action required break; From 95b1e62751f6a4e1213c06c814fbdf605814bb1f Mon Sep 17 00:00:00 2001 From: Shitanshu Shah Date: Wed, 16 Nov 2022 18:26:30 -0800 Subject: [PATCH 2/7] add sairedis-lib and vslib tests for generic programmable --- .../test_sai_redis_generic_programmable.cpp | 23 +++++++++++++++++++ .../test_sai_vs_generic_programmable.cpp | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 unittest/lib/test_sai_redis_generic_programmable.cpp create mode 100644 unittest/vslib/test_sai_vs_generic_programmable.cpp diff --git a/unittest/lib/test_sai_redis_generic_programmable.cpp b/unittest/lib/test_sai_redis_generic_programmable.cpp new file mode 100644 index 000000000..37e79f28f --- /dev/null +++ b/unittest/lib/test_sai_redis_generic_programmable.cpp @@ -0,0 +1,23 @@ +#include + +extern "C" { +#include "sai.h" +} + +#include "swss/logger.h" + +TEST(libsairedis, generic_programmable) +{ + sai_generic_programmable_api_t *api = nullptr; + + sai_api_query(SAI_API_GENERIC_PROGRAMMABLE, (void**)&api); + + EXPECT_NE(api, nullptr); + + sai_object_id_t obj_id; + + EXPECT_NE(SAI_STATUS_SUCCESS, api->create_generic_programmable(&obj_id,0,0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_generic_programmable(0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->set_generic_programmable_attribute(0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->get_generic_programmable_attribute(0,0,0)); +} diff --git a/unittest/vslib/test_sai_vs_generic_programmable.cpp b/unittest/vslib/test_sai_vs_generic_programmable.cpp new file mode 100644 index 000000000..ca457c518 --- /dev/null +++ b/unittest/vslib/test_sai_vs_generic_programmable.cpp @@ -0,0 +1,23 @@ +#include + +extern "C" { +#include "sai.h" +} + +#include "swss/logger.h" + +TEST(libsaivs, generic_programmable) +{ + sai_generic_programmable_api_t *api = nullptr; + + sai_api_query(SAI_API_GENERIC_PROGRAMMABLE, (void**)&api); + + EXPECT_NE(api, nullptr); + + sai_object_id_t obj_id; + + EXPECT_NE(SAI_STATUS_SUCCESS, api->create_generic_programmable(&obj_id,0,0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->remove_generic_programmable(0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->set_generic_programmable_attribute(0,0)); + EXPECT_NE(SAI_STATUS_SUCCESS, api->get_generic_programmable_attribute(0,0,0)); +} From 766a3c2a448b097de0f155c300d9280a053955d7 Mon Sep 17 00:00:00 2001 From: Shitanshu Shah Date: Wed, 16 Nov 2022 19:05:23 -0800 Subject: [PATCH 3/7] add sairedis-lib and vslib tests for generic programmable --- unittest/lib/Makefile.am | 1 + unittest/vslib/Makefile.am | 1 + 2 files changed, 2 insertions(+) diff --git a/unittest/lib/Makefile.am b/unittest/lib/Makefile.am index 5ed79f199..9d385f2dc 100644 --- a/unittest/lib/Makefile.am +++ b/unittest/lib/Makefile.am @@ -37,6 +37,7 @@ testslibsairedis_SOURCES = main_libsairedis.cpp \ test_sai_redis_debug_counter.cpp \ test_sai_redis_dtel.cpp \ test_sai_redis_fdb.cpp \ + test_sai_redis_generic_programmable.cpp \ test_sai_redis_ipmc.cpp \ test_sai_redis_l2mc.cpp \ test_sai_redis_l2mcgroup.cpp \ diff --git a/unittest/vslib/Makefile.am b/unittest/vslib/Makefile.am index 9dfe4728f..83720d381 100644 --- a/unittest/vslib/Makefile.am +++ b/unittest/vslib/Makefile.am @@ -59,6 +59,7 @@ testslibsaivs_SOURCES = main_libsaivs.cpp \ test_sai_vs_debug_counter.cpp \ test_sai_vs_dtel.cpp \ test_sai_vs_fdb.cpp \ + test_sai_vs_generic_programmable.cpp \ test_sai_vs_ipmc.cpp \ test_sai_vs_l2mc.cpp \ test_sai_vs_l2mcgroup.cpp \ From 984e5da9ecded9ac3015c77e2d51b3d5939bc4c6 Mon Sep 17 00:00:00 2001 From: Shitanshu Shah Date: Wed, 16 Nov 2022 22:32:30 -0800 Subject: [PATCH 4/7] check if meta-test covers generic programmable --- unittest/meta/TestMeta.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/unittest/meta/TestMeta.cpp b/unittest/meta/TestMeta.cpp index 6bbc86811..2494563e9 100644 --- a/unittest/meta/TestMeta.cpp +++ b/unittest/meta/TestMeta.cpp @@ -555,6 +555,43 @@ 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_generic_programmable_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)); + + std::string table_name = "test_table"; + std::string json_value = "[{"match":{"datatype":"SAI_ATTR_VALUE_TYPE_UINT16","value":"0x07b"}},{"action":[{"field":{"datatype":"SAI_ATTR_VALUE_TYPE_UINT32","value":"0x000007d0"}}]}]"; + + sai_attribute_t attrs[2]; + attrs[0].id = SAI_GENERIC_PROGRAMMABLE_ATTR_OBJECT_NAME; + attrs[0].value.s8list.count = (uint32_t)table_name.size(); + attrs[0].value.s8list.list = (int8_t *)const_cast(table_name.c_str()); + + attrs[1].id = SAI_GENERIC_PROGRAMMABLE_ATTR_ENTRY; + attrs[1].value.s8list.count = (uint32_t)json_value.size(); + attrs[1].value.s8list.list = (int8_t *)const_cast(json_value.c_str()); + + sai_object_id_t objId = 0; + EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_GENERIC_PROGRAMMABLE, &objId, switchId, 2, attrs)); + + attr.id = SAI_GENERIC_PROGRAMMABLE_ATTR_ENTRY; + attr.value.s8list.count = (uint32_t)json_value.size(); + attr.value.s8list.list = (int8_t *)const_cast(json_value.c_str()); + EXPECT_EQ(SAI_STATUS_SUCCESS, m.set(objId, &attr)); + + EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove(objId)); +} + + TEST(Meta, quad_my_sid_entry) { Meta m(std::make_shared()); From 4cfde951715b700a0213b3e60f810c60eae5aedf Mon Sep 17 00:00:00 2001 From: Shitanshu Shah Date: Wed, 16 Nov 2022 22:48:25 -0800 Subject: [PATCH 5/7] check if meta-test covers generic programmable --- unittest/meta/TestMeta.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unittest/meta/TestMeta.cpp b/unittest/meta/TestMeta.cpp index 2494563e9..5193b8e2e 100644 --- a/unittest/meta/TestMeta.cpp +++ b/unittest/meta/TestMeta.cpp @@ -569,7 +569,7 @@ TEST(Meta, quad_generic_programmable_entry) EXPECT_EQ(SAI_STATUS_SUCCESS, m.create(SAI_OBJECT_TYPE_SWITCH, &switchId, SAI_NULL_OBJECT_ID, 1, &attr)); std::string table_name = "test_table"; - std::string json_value = "[{"match":{"datatype":"SAI_ATTR_VALUE_TYPE_UINT16","value":"0x07b"}},{"action":[{"field":{"datatype":"SAI_ATTR_VALUE_TYPE_UINT32","value":"0x000007d0"}}]}]"; + std::string json_value = "test_json"; sai_attribute_t attrs[2]; attrs[0].id = SAI_GENERIC_PROGRAMMABLE_ATTR_OBJECT_NAME; @@ -586,9 +586,9 @@ TEST(Meta, quad_generic_programmable_entry) attr.id = SAI_GENERIC_PROGRAMMABLE_ATTR_ENTRY; attr.value.s8list.count = (uint32_t)json_value.size(); attr.value.s8list.list = (int8_t *)const_cast(json_value.c_str()); - EXPECT_EQ(SAI_STATUS_SUCCESS, m.set(objId, &attr)); + EXPECT_EQ(SAI_STATUS_SUCCESS, m.set(&objId, &attr)); - EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove(objId)); + EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove(&objId)); } From 96d75f59f792e676eabec1c130584f8e73a66b66 Mon Sep 17 00:00:00 2001 From: Shitanshu Shah Date: Wed, 16 Nov 2022 23:08:42 -0800 Subject: [PATCH 6/7] check if meta-test covers generic programmable --- unittest/meta/TestMeta.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittest/meta/TestMeta.cpp b/unittest/meta/TestMeta.cpp index 5193b8e2e..d3ec3af0c 100644 --- a/unittest/meta/TestMeta.cpp +++ b/unittest/meta/TestMeta.cpp @@ -586,9 +586,9 @@ TEST(Meta, quad_generic_programmable_entry) attr.id = SAI_GENERIC_PROGRAMMABLE_ATTR_ENTRY; attr.value.s8list.count = (uint32_t)json_value.size(); attr.value.s8list.list = (int8_t *)const_cast(json_value.c_str()); - EXPECT_EQ(SAI_STATUS_SUCCESS, m.set(&objId, &attr)); + EXPECT_EQ(SAI_STATUS_SUCCESS, m.set(SAI_OBJECT_TYPE_GENERIC_PROGRAMMABLE, objId, &attr)); - EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove(&objId)); + EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove(SAI_OBJECT_TYPE_GENERIC_PROGRAMMABLE, objId)); } From bb15f791a3c1341a6111746a9c99dc86d8bc4eab Mon Sep 17 00:00:00 2001 From: Shitanshu Shah Date: Thu, 17 Nov 2022 00:30:45 -0800 Subject: [PATCH 7/7] check if meta-test covers generic programmable --- unittest/meta/TestMeta.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unittest/meta/TestMeta.cpp b/unittest/meta/TestMeta.cpp index d3ec3af0c..eebc4f5d2 100644 --- a/unittest/meta/TestMeta.cpp +++ b/unittest/meta/TestMeta.cpp @@ -588,6 +588,9 @@ TEST(Meta, quad_generic_programmable_entry) attr.value.s8list.list = (int8_t *)const_cast(json_value.c_str()); EXPECT_EQ(SAI_STATUS_SUCCESS, m.set(SAI_OBJECT_TYPE_GENERIC_PROGRAMMABLE, objId, &attr)); + attr.id = SAI_GENERIC_PROGRAMMABLE_ATTR_ENTRY; + EXPECT_EQ(SAI_STATUS_SUCCESS, m.get(SAI_OBJECT_TYPE_GENERIC_PROGRAMMABLE, objId, 1, &attr)); + EXPECT_EQ(SAI_STATUS_SUCCESS, m.remove(SAI_OBJECT_TYPE_GENERIC_PROGRAMMABLE, objId)); }