Skip to content

Commit

Permalink
Fix serialization and refactor virtual switch init logic (sonic-net#85)
Browse files Browse the repository at this point in the history
* Fix serialization and refactor virtual switch init logic

* Remove unused variable

* Addressing comments
  • Loading branch information
kcudnik authored Oct 13, 2016
1 parent cc19600 commit b14b0f8
Show file tree
Hide file tree
Showing 15 changed files with 670 additions and 248 deletions.
2 changes: 1 addition & 1 deletion common/saiattribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SaiAttribute

sai_object_type_t m_objectType;
sai_attribute_t m_attr;

sai_attr_serialization_type_t m_serializationType;
};

Expand Down
45 changes: 28 additions & 17 deletions common/saiserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ sai_serialization_map_t sai_get_serialization_map()
map[SAI_OBJECT_TYPE_WRED][SAI_WRED_ATTR_WEIGHT] = SAI_SERIALIZATION_TYPE_UINT8;
map[SAI_OBJECT_TYPE_WRED][SAI_WRED_ATTR_ECN_MARK_MODE] = SAI_SERIALIZATION_TYPE_INT32;

map[SAI_OBJECT_TYPE_PORT][SAI_PORT_ATTR_TYPE] = SAI_SERIALIZATION_TYPE_INT32;
map[SAI_OBJECT_TYPE_PORT][SAI_PORT_ATTR_SPEED] = SAI_SERIALIZATION_TYPE_UINT32;
map[SAI_OBJECT_TYPE_PORT][SAI_PORT_ATTR_ADMIN_STATE] = SAI_SERIALIZATION_TYPE_BOOL;
map[SAI_OBJECT_TYPE_PORT][SAI_PORT_ATTR_OPER_STATUS] = SAI_SERIALIZATION_TYPE_INT32;
Expand Down Expand Up @@ -244,6 +245,7 @@ sai_object_type_to_string_map_t sai_get_object_type_map()
map[SAI_OBJECT_TYPE_NEIGHBOR] = TO_STR(SAI_OBJECT_TYPE_NEIGHBOR);
map[SAI_OBJECT_TYPE_ROUTE] = TO_STR(SAI_OBJECT_TYPE_ROUTE);
map[SAI_OBJECT_TYPE_VLAN] = TO_STR(SAI_OBJECT_TYPE_VLAN);
map[SAI_OBJECT_TYPE_VLAN_MEMBER] = TO_STR(SAI_OBJECT_TYPE_VLAN_MEMBER);
map[SAI_OBJECT_TYPE_TUNNEL] = TO_STR(SAI_OBJECT_TYPE_TUNNEL);
map[SAI_OBJECT_TYPE_TUNNEL_TABLE_ENTRY] = TO_STR(SAI_OBJECT_TYPE_TUNNEL_TABLE_ENTRY);

Expand All @@ -256,7 +258,7 @@ sai_status_t sai_get_object_type_string(sai_object_type_t object_type, std::stri

if (it == g_object_type_map.end())
{
SWSS_LOG_ERROR("serialization object not found %x", object_type);
SWSS_LOG_ERROR("serialization object not found %d", object_type);

return SAI_STATUS_NOT_IMPLEMENTED;
}
Expand Down Expand Up @@ -1347,6 +1349,13 @@ sai_status_t sai_deserialize_free_fdb_event_notification_data(
return SAI_STATUS_SUCCESS;
}

#define RETURN_ON_ERROR(x)\
{\
sai_status_t s = (x);\
if (s != SAI_STATUS_SUCCESS)\
return s;\
}

sai_status_t transfer_attribute(
_In_ sai_attr_serialization_type_t serialization_type,
_In_ sai_attribute_t &src_attr,
Expand Down Expand Up @@ -1416,31 +1425,31 @@ sai_status_t transfer_attribute(
break;

case SAI_SERIALIZATION_TYPE_OBJECT_LIST:
transfer_list(src_attr.value.objlist, dst_attr.value.objlist, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.objlist, dst_attr.value.objlist, countOnly));
break;

case SAI_SERIALIZATION_TYPE_UINT8_LIST:
transfer_list(src_attr.value.u8list, dst_attr.value.u8list, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.u8list, dst_attr.value.u8list, countOnly));
break;

case SAI_SERIALIZATION_TYPE_INT8_LIST:
transfer_list(src_attr.value.s8list, dst_attr.value.s8list, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.s8list, dst_attr.value.s8list, countOnly));
break;

case SAI_SERIALIZATION_TYPE_UINT16_LIST:
transfer_list(src_attr.value.u16list, dst_attr.value.u16list, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.u16list, dst_attr.value.u16list, countOnly));
break;

case SAI_SERIALIZATION_TYPE_INT16_LIST:
transfer_list(src_attr.value.s16list, dst_attr.value.s16list, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.s16list, dst_attr.value.s16list, countOnly));
break;

case SAI_SERIALIZATION_TYPE_UINT32_LIST:
transfer_list(src_attr.value.u32list, dst_attr.value.u32list, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.u32list, dst_attr.value.u32list, countOnly));
break;

case SAI_SERIALIZATION_TYPE_INT32_LIST:
transfer_list(src_attr.value.s32list, dst_attr.value.s32list, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.s32list, dst_attr.value.s32list, countOnly));
break;

case SAI_SERIALIZATION_TYPE_UINT32_RANGE:
Expand All @@ -1452,20 +1461,20 @@ sai_status_t transfer_attribute(
break;

case SAI_SERIALIZATION_TYPE_VLAN_LIST:
transfer_list(src_attr.value.vlanlist, dst_attr.value.vlanlist, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.vlanlist, dst_attr.value.vlanlist, countOnly));
break;

case SAI_SERIALIZATION_TYPE_PORT_BREAKOUT:
transfer_primitive(src_attr.value.portbreakout.breakout_mode, dst_attr.value.portbreakout.breakout_mode);
transfer_list(src_attr.value.portbreakout.port_list, dst_attr.value.portbreakout.port_list, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.portbreakout.port_list, dst_attr.value.portbreakout.port_list, countOnly));
break;

case SAI_SERIALIZATION_TYPE_QOS_MAP_LIST:
transfer_list(src_attr.value.qosmap, dst_attr.value.qosmap, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.qosmap, dst_attr.value.qosmap, countOnly));
break;

case SAI_SERIALIZATION_TYPE_TUNNEL_MAP_LIST:
transfer_list(src_attr.value.tunnelmap, dst_attr.value.tunnelmap, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.tunnelmap, dst_attr.value.tunnelmap, countOnly));
break;

/* ACL FIELD DATA */
Expand Down Expand Up @@ -1536,12 +1545,12 @@ sai_status_t transfer_attribute(

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_OBJECT_LIST:
transfer_primitive(src_attr.value.aclfield.enable, dst_attr.value.aclfield.enable);
transfer_list(src_attr.value.aclfield.data.objlist, dst_attr.value.aclfield.data.objlist, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.aclfield.data.objlist, dst_attr.value.aclfield.data.objlist, countOnly));
break;

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_UINT8_LIST:
transfer_primitive(src_attr.value.aclfield.enable, dst_attr.value.aclfield.enable);
transfer_list(src_attr.value.aclfield.mask.u8list, dst_attr.value.aclfield.mask.u8list, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.aclfield.mask.u8list, dst_attr.value.aclfield.mask.u8list, countOnly));
transfer_list(src_attr.value.aclfield.data.u8list, dst_attr.value.aclfield.data.u8list, countOnly);
break;

Expand Down Expand Up @@ -1599,7 +1608,7 @@ sai_status_t transfer_attribute(

case SAI_SERIALIZATION_TYPE_ACL_ACTION_DATA_OBJECT_LIST:
transfer_primitive(src_attr.value.aclaction.enable, dst_attr.value.aclaction.enable);
transfer_list(src_attr.value.aclaction.parameter.objlist, dst_attr.value.aclaction.parameter.objlist, countOnly);
RETURN_ON_ERROR(transfer_list(src_attr.value.aclaction.parameter.objlist, dst_attr.value.aclaction.parameter.objlist, countOnly));
break;

default:
Expand All @@ -1609,7 +1618,7 @@ sai_status_t transfer_attribute(
return SAI_STATUS_SUCCESS;
}

void transfer_attributes(
sai_status_t transfer_attributes(
_In_ sai_object_type_t object_type,
_In_ uint32_t attr_count,
_In_ sai_attribute_t *src_attr_list,
Expand All @@ -1634,8 +1643,10 @@ void transfer_attributes(
exit(EXIT_FAILURE);
}

transfer_attribute(serialization_type, src_attr, dst_attr, countOnly);
RETURN_ON_ERROR(transfer_attribute(serialization_type, src_attr, dst_attr, countOnly));
}

return SAI_STATUS_SUCCESS;
}

void sai_serialize_ip_address(
Expand Down
42 changes: 31 additions & 11 deletions common/saiserialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern "C" {

#define TO_STR(x) #x

typedef enum _sai_attr_serialization_type_t
typedef enum _sai_attr_serialization_type_t
{
SAI_SERIALIZATION_TYPE_BOOL,
SAI_SERIALIZATION_TYPE_CHARDATA,
Expand Down Expand Up @@ -107,14 +107,14 @@ void sai_dealloc_array(
void sai_deserialize_buffer(
_In_ const std::string &s,
_In_ int index,
_In_ size_t buffer_size,
_In_ size_t buffer_size,
_In_ void *buffer);

void sai_free_buffer(void * buffer);

void sai_serialize_buffer(
_In_ const void *buffer,
_In_ size_t buffer_size,
_In_ const void *buffer,
_In_ size_t buffer_size,
_Out_ std::string &s);

template<typename T>
Expand Down Expand Up @@ -227,20 +227,40 @@ void transfer_primitive(
}

template<typename T>
void transfer_list(
sai_status_t transfer_list(
_In_ const T &src_element,
_In_ T &dst_element,
_In_ bool countOnly)
{
transfer_primitive(src_element.count, dst_element.count);
if (countOnly || dst_element.count == 0)
{
transfer_primitive(src_element.count, dst_element.count);
return SAI_STATUS_SUCCESS;
}

if (countOnly)
return;
if (dst_element.list == NULL)
{
SWSS_LOG_ERROR("destination list is null, unable to transfer elements");

for (size_t i = 0; i < src_element.count; i++)
return SAI_STATUS_FAILURE;
}

if (dst_element.count >= src_element.count)
{
transfer_primitive(src_element.list[i], dst_element.list[i]);
transfer_primitive(src_element.count, dst_element.count);

for (size_t i = 0; i < src_element.count; i++)
{
transfer_primitive(src_element.list[i], dst_element.list[i]);
}

return SAI_STATUS_SUCCESS;
}

// input buffer is too small to get all list elements, so return count only
transfer_primitive(src_element.count, dst_element.count);

return SAI_STATUS_BUFFER_OVERFLOW;
}

void sai_serialize_ip_address(
Expand Down Expand Up @@ -330,7 +350,7 @@ sai_status_t transfer_attribute(
_In_ sai_attribute_t &dst_attr,
_In_ bool countOnly);

void transfer_attributes(
sai_status_t transfer_attributes(
_In_ sai_object_type_t object_type,
_In_ uint32_t attr_count,
_In_ sai_attribute_t *src_attr_list,
Expand Down
2 changes: 0 additions & 2 deletions lib/src/sai_redis_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,5 @@ sai_status_t sai_api_uninitialize(void)

g_apiInitialized = false;

SWSS_LOG_ERROR("not implemented");

return SAI_STATUS_NOT_IMPLEMENTED;
}
76 changes: 18 additions & 58 deletions meta/sai_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ class SaiAttrWrapper
#define META_LOG_ERROR(md, format, ...) SWSS_LOG_ERROR("%s " format, get_attr_info(md).c_str(), ##__VA_ARGS__)
#define META_LOG_DEBUG(md, format, ...) SWSS_LOG_DEBUG("%s " format, get_attr_info(md).c_str(), ##__VA_ARGS__)
#define META_LOG_NOTICE(md, format, ...) SWSS_LOG_NOTICE("%s " format, get_attr_info(md).c_str(), ##__VA_ARGS__)
#define META_LOG_INFO(md, format, ...) SWSS_LOG_INFO("%s " format, get_attr_info(md).c_str(), ##__VA_ARGS__)

// traps and vlan will be converted to oid
// fdb, route, neighbor don't need reference count,
Expand Down Expand Up @@ -2164,28 +2165,19 @@ sai_status_t meta_generic_validation_get(
break;

case SAI_SERIALIZATION_TYPE_OBJECT_LIST:

// allow NULL list if count is zero (just get list length)

if (value.objlist.count != 0 && value.objlist.list == NULL)
{
META_LOG_ERROR(md, "object list count is %u, but list is NULL", value.objlist.count);

return SAI_STATUS_INVALID_PARAMETER;
}

if (value.objlist.count > MAX_LIST_COUNT)
{
META_LOG_ERROR(md, "object list count %u is > then max list count %u", value.objlist.count, MAX_LIST_COUNT);

return SAI_STATUS_INVALID_PARAMETER;
}

VALIDATION_LIST(md, value.objlist);
break;

case SAI_SERIALIZATION_TYPE_VLAN_LIST:

{
if (value.vlanlist.count == 0 && value.vlanlist.list != NULL)
{
META_LOG_ERROR(md, "vlan list count is zero, but list not NULL");

return SAI_STATUS_INVALID_PARAMETER;
}

if (value.vlanlist.count != 0 && value.vlanlist.list == NULL)
{
META_LOG_ERROR(md, "vlan list count is %u, but list is NULL", value.vlanlist.count);
Expand Down Expand Up @@ -2222,26 +2214,8 @@ sai_status_t meta_generic_validation_get(
break;

case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_OBJECT_LIST:

{
// allow NULL list if count is zero (just get list length)

if (value.aclfield.data.objlist.count != 0 && value.aclfield.data.objlist.list == NULL)
{
META_LOG_ERROR(md, "object list count is %u, but list is NULL", value.aclfield.data.objlist.count);

return SAI_STATUS_INVALID_PARAMETER;
}

if (value.aclfield.data.objlist.count > MAX_LIST_COUNT)
{
META_LOG_ERROR(md, "object list count %u is > then max list count %u", value.aclfield.data.objlist.count, MAX_LIST_COUNT);

return SAI_STATUS_INVALID_PARAMETER;
}

break;
}
VALIDATION_LIST(md, value.aclfield.data.objlist);
break;

// case SAI_SERIALIZATION_TYPE_ACL_FIELD_DATA_UINT8_LIST:

Expand All @@ -2263,26 +2237,8 @@ sai_status_t meta_generic_validation_get(
break;

case SAI_SERIALIZATION_TYPE_ACL_ACTION_DATA_OBJECT_LIST:

{
// allow NULL list if count is zero (just get list length)

if (value.aclaction.parameter.objlist.count != 0 && value.aclaction.parameter.objlist.list == NULL)
{
META_LOG_ERROR(md, "object list count is %u, but list is NULL", value.aclaction.parameter.objlist.count);

return SAI_STATUS_INVALID_PARAMETER;
}

if (value.aclaction.parameter.objlist.count > MAX_LIST_COUNT)
{
META_LOG_ERROR(md, "object list count %u is > then max list count %u", value.aclaction.parameter.objlist.count, MAX_LIST_COUNT);

return SAI_STATUS_INVALID_PARAMETER;
}

break;
}
VALIDATION_LIST(md, value.aclaction.parameter.objlist);
break;

// ACL END

Expand Down Expand Up @@ -3013,7 +2969,11 @@ void meta_generic_validation_post_get_objlist(

if (!object_reference_exists(oid))
{
META_LOG_NOTICE(md, "returned get object on list [%u] oid 0x%llx object type %d does not exists in local DB (snoop)", i, oid, ot);
// NOTE: there may happen that user will request multiple object lists
// and first list was retrived ok, but second failed with overflow
// then we may forget to snoop

META_LOG_INFO(md, "returned get object on list [%u] oid 0x%llx object type %d does not exists in local DB (snoop)", i, oid, ot);

sai_object_meta_key_t key = { .object_type = ot, .key = { .object_id = oid } };

Expand Down
1 change: 1 addition & 0 deletions meta/sai_meta_sanity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ std::unordered_map<int32_t, std::unordered_map<int32_t, std::string>> get_attr_n
ATTR_MAP_SET(PORT,SAI_PORT_ATTR_MULTICAST_STORM_CONTROL_POLICER_ID);
ATTR_MAP_SET(PORT,SAI_PORT_ATTR_GLOBAL_FLOW_CONTROL);
ATTR_MAP_SET(PORT,SAI_PORT_ATTR_MAX_LEARNED_ADDRESSES);
ATTR_MAP_SET(PORT,SAI_PORT_ATTR_FDB_LEARNING);
ATTR_MAP_SET(PORT,SAI_PORT_ATTR_FDB_LEARNING_LIMIT_VIOLATION);
ATTR_MAP_SET(PORT,SAI_PORT_ATTR_INGRESS_MIRROR_SESSION);
ATTR_MAP_SET(PORT,SAI_PORT_ATTR_EGRESS_MIRROR_SESSION);
Expand Down
Loading

0 comments on commit b14b0f8

Please sign in to comment.