Skip to content

Commit

Permalink
Support System ports config (#657)
Browse files Browse the repository at this point in the history
This PR includes implementation of System ports initialization & orchestration, Interface & Neighbor Synchronization using GLOBAL_APP_DB, Inband Interface Configuration.

HLD: sonic-net/SONiC#639
Dependency PR(sonic-swss-common): sonic-net/sonic-swss-common#380

Co-authored-by: vedganes <vedavinayagam.ganesan@nokia.com>
  • Loading branch information
minionatwork and vedganes authored Oct 12, 2020
1 parent 0f3668f commit 017056a
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 0 deletions.
43 changes: 43 additions & 0 deletions meta/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3351,6 +3351,11 @@ void Meta::meta_generic_validation_post_remove(
// no special action required
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
// no special action required
break;

default:
META_LOG_THROW(md, "serialization type is not supported yet FIXME");
}
Expand Down Expand Up @@ -4565,6 +4570,13 @@ sai_status_t Meta::meta_generic_validation_create(
break;
}

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
VALIDATION_LIST(md, value.sysportconfiglist);
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
break;

default:

META_LOG_THROW(md, "serialization type is not supported yet FIXME");
Expand Down Expand Up @@ -5196,6 +5208,13 @@ sai_status_t Meta::meta_generic_validation_set(
VALIDATION_LIST(md, value.aclcapability.action_list);
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
VALIDATION_LIST(md, value.sysportconfiglist);
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
break;

default:

META_LOG_THROW(md, "serialization type is not supported yet FIXME");
Expand Down Expand Up @@ -5557,6 +5576,13 @@ sai_status_t Meta::meta_generic_validation_get(
VALIDATION_LIST(md, value.aclcapability.action_list);
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
VALIDATION_LIST(md, value.sysportconfiglist);
break;

default:

// acl capability will is more complex since is in/out we need to check stage
Expand Down Expand Up @@ -5798,6 +5824,13 @@ void Meta::meta_generic_validation_post_get(

break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
VALIDATION_LIST_GET(md, value.sysportconfiglist);
break;

default:

META_LOG_THROW(md, "serialization type is not supported yet FIXME");
Expand Down Expand Up @@ -6679,6 +6712,11 @@ void Meta::meta_generic_validation_post_create(
// no special action required
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
// no special action required
break;

default:

META_LOG_THROW(md, "serialization type is not supported yet FIXME");
Expand Down Expand Up @@ -6906,6 +6944,11 @@ void Meta::meta_generic_validation_post_set(
// no special action required
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
// no special action required
break;

default:
META_LOG_THROW(md, "serialization type is not supported yet FIXME");
}
Expand Down
165 changes: 165 additions & 0 deletions meta/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ sai_status_t transfer_attribute(
RETURN_ON_ERROR(transfer_list(src_attr.value.aclcapability.action_list, dst_attr.value.aclcapability.action_list, countOnly));
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
transfer_primitive(src_attr.value.sysportconfig, dst_attr.value.sysportconfig);
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
RETURN_ON_ERROR(transfer_list(src_attr.value.sysportconfiglist, dst_attr.value.sysportconfiglist, countOnly));
break;

default:
return SAI_STATUS_NOT_IMPLEMENTED;
}
Expand Down Expand Up @@ -1398,6 +1406,73 @@ std::string sai_serialize_acl_capability(
return mandatory + ":" + list;
}

std::string sai_serialize_system_port_config(
_In_ const sai_attr_metadata_t &meta,
_In_ const sai_system_port_config_t &sysportconfig)
{
SWSS_LOG_ENTER();

json j;

j["port_id"] = sai_serialize_number(sysportconfig.port_id, false);
j["attached_switch_id"] = sai_serialize_number(sysportconfig.attached_switch_id, false);
j["attached_core_index"] = sai_serialize_number(sysportconfig.attached_core_index, false);
j["attached_core_port_index"] = sai_serialize_number(sysportconfig.attached_core_port_index, false);
j["speed"] = sai_serialize_number(sysportconfig.speed, false);
j["num_voq"] = sai_serialize_number(sysportconfig.num_voq, false);

return j.dump();
}

json sai_serialize_system_port_cfg_list_item(
_In_ const sai_system_port_config_t &sysportconfig)
{
SWSS_LOG_ENTER();

json j;

j["port_id"] = sai_serialize_number(sysportconfig.port_id, false);
j["attached_switch_id"] = sai_serialize_number(sysportconfig.attached_switch_id, false);
j["attached_core_index"] = sai_serialize_number(sysportconfig.attached_core_index, false);
j["attached_core_port_index"] = sai_serialize_number(sysportconfig.attached_core_port_index, false);
j["speed"] = sai_serialize_number(sysportconfig.speed, false);
j["num_voq"] = sai_serialize_number(sysportconfig.num_voq, false);

return j;
}

std::string sai_serialize_system_port_config_list(
_In_ const sai_attr_metadata_t &meta,
_In_ const sai_system_port_config_list_t& sysportconfiglist,
_In_ bool countOnly)
{
SWSS_LOG_ENTER();

json j;

j["count"] = sysportconfiglist.count;

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

return j.dump();
}

json arr = json::array();

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

arr.push_back(item);
}

j["list"] = arr;

return j.dump();
}

std::string sai_serialize_attr_value(
_In_ const sai_attr_metadata_t& meta,
_In_ const sai_attribute_t &attr,
Expand Down Expand Up @@ -1533,6 +1608,12 @@ std::string sai_serialize_attr_value(
case SAI_ATTR_VALUE_TYPE_ACL_CAPABILITY:
return sai_serialize_acl_capability(meta, attr.value.aclcapability, countOnly);

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
return sai_serialize_system_port_config(meta, attr.value.sysportconfig);

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
return sai_serialize_system_port_config_list(meta, attr.value.sysportconfiglist, countOnly);

default:
SWSS_LOG_THROW("FATAL: invalid serialization type %d", meta.attrvaluetype);
}
Expand Down Expand Up @@ -2566,6 +2647,77 @@ void sai_deserialize_acl_capability(
sai_deserialize_enum_list(list, &sai_metadata_enum_sai_acl_action_type_t, cap.action_list, false);
}

void sai_deserialize_system_port_config(
_In_ const std::string& s,
_Out_ sai_system_port_config_t& sysportconfig)
{
SWSS_LOG_ENTER();

json j = json::parse(s);

sai_deserialize_number(j["port_id"], sysportconfig.port_id, false);
sai_deserialize_number(j["attached_switch_id"], sysportconfig.attached_switch_id, false);
sai_deserialize_number(j["attached_core_index"], sysportconfig.attached_core_index, false);
sai_deserialize_number(j["attached_core_port_index"], sysportconfig.attached_core_port_index, false);
sai_deserialize_number(j["speed"], sysportconfig.speed, false);
sai_deserialize_number(j["num_voq"], sysportconfig.num_voq, false);

}

void sai_deserialize_system_port_cfg_list_item(
_In_ const json& j,
_Out_ sai_system_port_config_t& sysportconfig)
{
SWSS_LOG_ENTER();

sai_deserialize_number(j["port_id"], sysportconfig.port_id, false);
sai_deserialize_number(j["attached_switch_id"], sysportconfig.attached_switch_id, false);
sai_deserialize_number(j["attached_core_index"], sysportconfig.attached_core_index, false);
sai_deserialize_number(j["attached_core_port_index"], sysportconfig.attached_core_port_index, false);
sai_deserialize_number(j["speed"], sysportconfig.speed, false);
sai_deserialize_number(j["num_voq"], sysportconfig.num_voq, false);
}

void sai_deserialize_system_port_config_list(
_In_ const std::string& s,
_Out_ sai_system_port_config_list_t& sysportconfiglist,
_In_ bool countOnly)
{
SWSS_LOG_ENTER();

json j = json::parse(s);

sysportconfiglist.count = j["count"];

if (countOnly)
{
return;
}

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

json arr = j["list"];

if (arr.size() != (size_t)sysportconfiglist.count)
{
SWSS_LOG_ERROR("system port config list count mismatch %lu vs %u", arr.size(), sysportconfiglist.count);
throw std::runtime_error("system port config list count mismatch");
}

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

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

sai_deserialize_system_port_cfg_list_item(item, sysportconfiglist.list[i]);
}
}

void sai_deserialize_attr_value(
_In_ const std::string& s,
_In_ const sai_attr_metadata_t& meta,
Expand Down Expand Up @@ -2704,6 +2856,12 @@ void sai_deserialize_attr_value(
case SAI_ATTR_VALUE_TYPE_ACL_CAPABILITY:
return sai_deserialize_acl_capability(s, attr.value.aclcapability);

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
return sai_deserialize_system_port_config(s, attr.value.sysportconfig);

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
return sai_deserialize_system_port_config_list(s, attr.value.sysportconfiglist, countOnly);

default:
SWSS_LOG_THROW("deserialize type %d is not supportd yet FIXME", meta.attrvaluetype);
}
Expand Down Expand Up @@ -3269,6 +3427,13 @@ void sai_deserialize_free_attribute_value(
sai_free_list(attr.value.aclcapability.action_list);
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG:
break;

case SAI_ATTR_VALUE_TYPE_SYSTEM_PORT_CONFIG_LIST:
sai_free_list(attr.value.sysportconfiglist);
break;

default:
SWSS_LOG_THROW("unsupported type %d on deserialize free, FIXME", type);
}
Expand Down

0 comments on commit 017056a

Please sign in to comment.