Skip to content

Commit

Permalink
[cbf] Add Class Based Forwarding support (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
abanu-ms authored Oct 5, 2021
1 parent 1148d16 commit ecb95a8
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 0 deletions.
15 changes: 15 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3417,6 +3417,7 @@ void Meta::meta_generic_validation_post_remove(
case SAI_ATTR_VALUE_TYPE_UINT32_LIST:
case SAI_ATTR_VALUE_TYPE_INT32_LIST:
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
case SAI_ATTR_VALUE_TYPE_MAP_LIST:
case SAI_ATTR_VALUE_TYPE_IP_ADDRESS_LIST:
case SAI_ATTR_VALUE_TYPE_UINT32_RANGE:
case SAI_ATTR_VALUE_TYPE_INT32_RANGE:
Expand Down Expand Up @@ -4657,6 +4658,9 @@ sai_status_t Meta::meta_generic_validation_create(
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
VALIDATION_LIST(md, value.qosmap);
break;
case SAI_ATTR_VALUE_TYPE_MAP_LIST:
VALIDATION_LIST(md, value.maplist);
break;
case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST:
VALIDATION_LIST(md, value.aclresource);
break;
Expand Down Expand Up @@ -5307,6 +5311,9 @@ sai_status_t Meta::meta_generic_validation_set(
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
VALIDATION_LIST(md, value.qosmap);
break;
case SAI_ATTR_VALUE_TYPE_MAP_LIST:
VALIDATION_LIST(md, value.maplist);
break;
case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST:
VALIDATION_LIST(md, value.aclresource);
break;
Expand Down Expand Up @@ -5715,6 +5722,9 @@ sai_status_t Meta::meta_generic_validation_get(
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
VALIDATION_LIST(md, value.qosmap);
break;
case SAI_ATTR_VALUE_TYPE_MAP_LIST:
VALIDATION_LIST(md, value.maplist);
break;
case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST:
VALIDATION_LIST(md, value.aclresource);
break;
Expand Down Expand Up @@ -5958,6 +5968,9 @@ void Meta::meta_generic_validation_post_get(
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
VALIDATION_LIST_GET(md, value.qosmap);
break;
case SAI_ATTR_VALUE_TYPE_MAP_LIST:
VALIDATION_LIST_GET(md, value.maplist);
break;
case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST:
VALIDATION_LIST_GET(md, value.aclresource);
break;
Expand Down Expand Up @@ -6861,6 +6874,7 @@ void Meta::meta_generic_validation_post_create(
case SAI_ATTR_VALUE_TYPE_UINT32_LIST:
case SAI_ATTR_VALUE_TYPE_INT32_LIST:
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
case SAI_ATTR_VALUE_TYPE_MAP_LIST:
case SAI_ATTR_VALUE_TYPE_IP_ADDRESS_LIST:
case SAI_ATTR_VALUE_TYPE_UINT32_RANGE:
case SAI_ATTR_VALUE_TYPE_INT32_RANGE:
Expand Down Expand Up @@ -7099,6 +7113,7 @@ void Meta::meta_generic_validation_post_set(
case SAI_ATTR_VALUE_TYPE_UINT32_LIST:
case SAI_ATTR_VALUE_TYPE_INT32_LIST:
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
case SAI_ATTR_VALUE_TYPE_MAP_LIST:
case SAI_ATTR_VALUE_TYPE_IP_ADDRESS_LIST:
case SAI_ATTR_VALUE_TYPE_UINT32_RANGE:
case SAI_ATTR_VALUE_TYPE_INT32_RANGE:
Expand Down
103 changes: 103 additions & 0 deletions meta/SaiSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,50 @@ std::string sai_serialize_qos_map_list(
return j.dump();
}

json sai_serialize_map(
_In_ const sai_map_t &map)
{
SWSS_LOG_ENTER();

json j;

j["key"] = map.key;
j["value"] = map.value;

return j;
}

std::string sai_serialize_map_list(
_In_ const sai_map_list_t &maplist,
_In_ bool countOnly)
{
SWSS_LOG_ENTER();

json j;

j["count"] = maplist.count;

if (maplist.list == NULL || countOnly)
{
j["list"] = nullptr;

return j.dump();
}

json arr = json::array();

for (uint32_t i = 0; i < maplist.count; ++i)
{
json item = sai_serialize_map(maplist.list[i]);

arr.push_back(item);
}

j["list"] = arr;

return j.dump();
}

json sai_serialize_acl_resource(
_In_ const sai_acl_resource_t& aclresource)
{
Expand Down Expand Up @@ -1704,6 +1748,9 @@ std::string sai_serialize_attr_value(
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
return sai_serialize_qos_map_list(attr.value.qosmap, countOnly);

case SAI_ATTR_VALUE_TYPE_MAP_LIST:
return sai_serialize_map_list(attr.value.maplist, countOnly);

case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST:
return sai_serialize_acl_resource_list(attr.value.aclresource, countOnly);

Expand Down Expand Up @@ -2516,6 +2563,16 @@ static void sai_deserialize_qos_map(
sai_deserialize_qos_map_params(j["value"], qosmap.value);
}

void sai_deserialize_map(
_In_ const json &j,
_Out_ sai_map_t &map)
{
SWSS_LOG_ENTER();

map.key = j["key"];
map.value = j["value"];
}

void sai_deserialize_qos_map_list(
_In_ const std::string& s,
_Out_ sai_qos_map_list_t& qosmap,
Expand Down Expand Up @@ -2555,6 +2612,45 @@ void sai_deserialize_qos_map_list(
}
}

void sai_deserialize_map_list(
_In_ const std::string &s,
_Out_ sai_map_list_t &maplist,
_In_ bool countOnly)
{
SWSS_LOG_ENTER();

json j = json::parse(s);

maplist.count = j["count"];

if (countOnly)
{
return;
}

if (j["list"] == nullptr)
{
maplist.list = NULL;
return;
}

json arr = j["list"];

if (arr.size() != (size_t)maplist.count)
{
SWSS_LOG_THROW("map list count mismatch %lu vs %u", arr.size(), maplist.count);
}

maplist.list = sai_alloc_n_of_ptr_type(maplist.count, maplist.list);

for (uint32_t i = 0; i < maplist.count; ++i)
{
const json &item = arr[i];

sai_deserialize_map(item, maplist.list[i]);
}
}

void sai_deserialize_acl_stage(
_In_ const std::string& s,
_Out_ sai_acl_stage_t& stage)
Expand Down Expand Up @@ -3186,6 +3282,9 @@ void sai_deserialize_attr_value(
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
return sai_deserialize_qos_map_list(s, attr.value.qosmap, countOnly);

case SAI_ATTR_VALUE_TYPE_MAP_LIST:
return sai_deserialize_map_list(s, attr.value.maplist, countOnly);

case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST:
return sai_deserialize_acl_resource_list(s, attr.value.aclresource, countOnly);

Expand Down Expand Up @@ -3912,6 +4011,10 @@ void sai_deserialize_free_attribute_value(
sai_free_list(attr.value.qosmap);
break;

case SAI_ATTR_VALUE_TYPE_MAP_LIST:
sai_free_list(attr.value.maplist);
break;

case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST:
sai_free_list(attr.value.aclresource);
break;
Expand Down
40 changes: 40 additions & 0 deletions unittest/meta/TestSaiSerialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,46 @@ TEST(SaiSerialize, serialize_qos_map)
EXPECT_EQ(l.value.fc, 2);
}

TEST(SaiSerialize, serialize_map)
{
sai_attribute_t attr;
const sai_attr_metadata_t* meta;
std::string s;

attr.id = SAI_NEXT_HOP_GROUP_MAP_ATTR_MAP_TO_VALUE_LIST;

sai_map_t map = { .key = 1, .value = 11 };

attr.value.maplist.count = 1;
attr.value.maplist.list = &map;

meta = sai_metadata_get_attr_metadata(SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MAP, attr.id);

s = sai_serialize_attr_value(*meta, attr);

std::string ret = "{\"count\":1,\"list\":[{\"key\":1,\"value\":11}]}";

EXPECT_EQ(s, ret);

s = sai_serialize_attr_value(*meta, attr, true);

std::string ret2 = "{\"count\":1,\"list\":null}";
EXPECT_EQ(s, ret2);

// deserialize

memset(&attr, 0, sizeof(attr));

sai_deserialize_attr_value(ret, *meta, attr);

EXPECT_EQ(attr.value.maplist.count, 1);

auto &l = attr.value.maplist.list[0];
EXPECT_EQ(l.key, 1);

EXPECT_EQ(l.value, 11);
}

template<typename T>
static void deserialize_number(
_In_ const std::string& s,
Expand Down
5 changes: 5 additions & 0 deletions vslib/VirtualSwitchSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,11 @@ sai_status_t VirtualSwitchSaiInterface::objectTypeGetAvailability(
}
return SAI_STATUS_SUCCESS;
}
else if (objectType == SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MAP)
{
*count = 512;
return SAI_STATUS_SUCCESS;
}

return SAI_STATUS_NOT_SUPPORTED;
}
Expand Down

0 comments on commit ecb95a8

Please sign in to comment.