in meta/sai_rpc_frontend.cpp [151:544]
void convert_attr_thrift_to_sai(
const sai_object_type_t ot,
const sai_thrift_attribute_t &thrift_attr,
sai_attribute_t *attr)
{
const auto md = sai_metadata_get_attr_metadata(ot, thrift_attr.id);
attr->id = thrift_attr.id;
sai_thrift_exception e;
e.status = SAI_STATUS_NOT_SUPPORTED;
if (md == NULL)
{
SAI_META_LOG_ERROR("attr metadata not found for object type %d and attribute %d", ot, attr->id);
e.status = SAI_STATUS_INVALID_PARAMETER;
throw e;
}
switch (md->attrvaluetype)
{
case SAI_ATTR_VALUE_TYPE_BOOL:
attr->value.booldata = thrift_attr.value.booldata;
break;
case SAI_ATTR_VALUE_TYPE_CHARDATA:
// 32 is chardata size in sai types
std::memcpy(attr->value.chardata, thrift_attr.value.chardata.c_str(), 32);
break;
case SAI_ATTR_VALUE_TYPE_UINT8:
attr->value.u8 = thrift_attr.value.u8;
break;
case SAI_ATTR_VALUE_TYPE_INT8:
attr->value.s8 = thrift_attr.value.s8;
break;
case SAI_ATTR_VALUE_TYPE_UINT16:
attr->value.u16 = thrift_attr.value.u16;
break;
case SAI_ATTR_VALUE_TYPE_INT16:
attr->value.s16 = thrift_attr.value.s16;
break;
case SAI_ATTR_VALUE_TYPE_UINT32:
attr->value.u32 = thrift_attr.value.u32;
break;
case SAI_ATTR_VALUE_TYPE_INT32:
attr->value.s32 = thrift_attr.value.s32;
break;
case SAI_ATTR_VALUE_TYPE_UINT64:
attr->value.u64 = thrift_attr.value.u64;
break;
case SAI_ATTR_VALUE_TYPE_INT64:
attr->value.s64 = thrift_attr.value.s64;
break;
case SAI_ATTR_VALUE_TYPE_MAC:
sai_thrift_mac_t_parse(thrift_attr.value.mac, &attr->value.mac);
break;
case SAI_ATTR_VALUE_TYPE_IPV4:
sai_thrift_ip4_t_parse(thrift_attr.value.ip4, &attr->value.ip4);
break;
case SAI_ATTR_VALUE_TYPE_IPV6:
sai_thrift_ip6_t_parse(thrift_attr.value.ip6, attr->value.ip6);
break;
case SAI_ATTR_VALUE_TYPE_IP_ADDRESS:
sai_thrift_ip_address_t_parse(thrift_attr.value.ipaddr, &attr->value.ipaddr);
break;
case SAI_ATTR_VALUE_TYPE_IP_PREFIX:
sai_thrift_ip_prefix_t_parse(thrift_attr.value.ipprefix, &attr->value.ipprefix);
break;
case SAI_ATTR_VALUE_TYPE_OBJECT_ID:
attr->value.oid = thrift_attr.value.oid;
break;
case SAI_ATTR_VALUE_TYPE_OBJECT_LIST:
{
attr->value.objlist.list = (sai_object_id_t *)malloc(sizeof(sai_object_id_t) * thrift_attr.value.objlist.count);
int i = 0;
for (auto obj : thrift_attr.value.objlist.idlist)
{
attr->value.objlist.list[i++] = obj;
}
attr->value.objlist.count = thrift_attr.value.objlist.count;
}
break;
case SAI_ATTR_VALUE_TYPE_UINT8_LIST:
{
attr->value.u8list.list = (uint8_t *)malloc(sizeof(uint8_t) * thrift_attr.value.u8list.count);
int i = 0;
for (auto u8 : thrift_attr.value.u8list.uint8list)
{
attr->value.u8list.list[i++] = u8;
}
attr->value.u8list.count = thrift_attr.value.u8list.count;
}
break;
case SAI_ATTR_VALUE_TYPE_INT8_LIST:
{
attr->value.s8list.list = (int8_t *)malloc(sizeof(int8_t) * thrift_attr.value.s8list.count);
int i = 0;
for (auto s8 : thrift_attr.value.s8list.int8list)
{
attr->value.s8list.list[i++] = s8;
}
attr->value.s8list.count = thrift_attr.value.s8list.count;
}
break;
case SAI_ATTR_VALUE_TYPE_UINT16_LIST:
{
attr->value.u16list.list = (uint16_t *)malloc(sizeof(uint16_t) * thrift_attr.value.u16list.count);
int i = 0;
for (auto u16 : thrift_attr.value.u16list.uint16list)
{
attr->value.u16list.list[i++] = u16;
}
attr->value.u16list.count = thrift_attr.value.u16list.count;
}
break;
case SAI_ATTR_VALUE_TYPE_INT16_LIST:
{
attr->value.s16list.list = (int16_t *)malloc(sizeof(int16_t) * thrift_attr.value.s16list.count);
int i = 0;
for (auto s16 : thrift_attr.value.s16list.int16list)
{
attr->value.s16list.list[i++] = s16;
}
attr->value.s16list.count = thrift_attr.value.s16list.count;
}
break;
case SAI_ATTR_VALUE_TYPE_UINT32_LIST:
{
attr->value.u32list.list = (uint32_t *)malloc(sizeof(uint32_t) * thrift_attr.value.u32list.count);
int i = 0;
for (auto u32 : thrift_attr.value.u32list.uint32list)
{
attr->value.u32list.list[i++] = u32;
}
attr->value.u32list.count = thrift_attr.value.u32list.count;
}
break;
case SAI_ATTR_VALUE_TYPE_INT32_LIST:
{
attr->value.s32list.list = (int32_t *)malloc(sizeof(int32_t) * thrift_attr.value.s32list.count);
int i = 0;
for (auto s32 : thrift_attr.value.s32list.int32list)
{
attr->value.s32list.list[i++] = s32;
}
attr->value.s32list.count = thrift_attr.value.s32list.count;
}
break;
case SAI_ATTR_VALUE_TYPE_UINT32_RANGE:
attr->value.u32range.min = thrift_attr.value.u32range.min;
attr->value.u32range.max = thrift_attr.value.u32range.max;
break;
case SAI_ATTR_VALUE_TYPE_INT32_RANGE:
attr->value.s32range.min = thrift_attr.value.s32range.min;
attr->value.s32range.max = thrift_attr.value.s32range.max;
break;
case SAI_ATTR_VALUE_TYPE_UINT16_RANGE_LIST:
{
attr->value.u16rangelist.list = (sai_u16_range_t *)malloc(sizeof(sai_u16_range_t) * thrift_attr.value.u16rangelist.count);
int i = 0;
for (auto range : thrift_attr.value.u16rangelist.rangelist)
{
attr->value.u16rangelist.list[i].min = range.min;
attr->value.u16rangelist.list[i++].max = range.max;
}
attr->value.u16rangelist.count = thrift_attr.value.u16rangelist.count;
}
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_BOOL:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.booldata = thrift_attr.value.aclfield.data.booldata;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_UINT8:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.u8 = thrift_attr.value.aclfield.data.u8;
attr->value.aclfield.mask.u8 = thrift_attr.value.aclfield.mask.u8;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_INT8:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.s8 = thrift_attr.value.aclfield.data.s8;
attr->value.aclfield.mask.s8 = thrift_attr.value.aclfield.mask.s8;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_UINT16:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.u16 = thrift_attr.value.aclfield.data.u16;
attr->value.aclfield.mask.u16 = thrift_attr.value.aclfield.mask.u16;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_INT16:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.s16 = thrift_attr.value.aclfield.data.s16;
attr->value.aclfield.mask.s16 = thrift_attr.value.aclfield.mask.s16;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_UINT32:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.u32 = thrift_attr.value.aclfield.data.u32;
attr->value.aclfield.mask.u32 = thrift_attr.value.aclfield.mask.u32;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_INT32:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.s32 = thrift_attr.value.aclfield.data.s32;
attr->value.aclfield.mask.s32 = thrift_attr.value.aclfield.mask.s32;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_MAC:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
sai_thrift_mac_t_parse(thrift_attr.value.aclfield.data.mac, &attr->value.aclfield.data.mac);
sai_thrift_mac_t_parse(thrift_attr.value.aclfield.mask.mac, &attr->value.aclfield.mask.mac);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_IPV4:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
sai_thrift_ip4_t_parse(thrift_attr.value.aclfield.data.ip4, &attr->value.aclfield.data.ip4);
sai_thrift_ip4_t_parse(thrift_attr.value.aclfield.mask.ip4, &attr->value.aclfield.mask.ip4);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_IPV6:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
sai_thrift_ip6_t_parse(thrift_attr.value.aclfield.data.ip6, attr->value.aclfield.data.ip6);
sai_thrift_ip6_t_parse(thrift_attr.value.aclfield.mask.ip6, attr->value.aclfield.mask.ip6);
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_ID:
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.oid = thrift_attr.value.aclfield.data.oid;
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_OBJECT_LIST:
{
int i = 0;
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.objlist.list = (sai_object_id_t *)malloc(sizeof(sai_object_id_t) * thrift_attr.value.aclfield.data.objlist.count);
for (auto obj : thrift_attr.value.aclfield.data.objlist.idlist)
{
attr->value.aclfield.data.objlist.list[i++] = obj;
}
attr->value.aclfield.data.objlist.count = thrift_attr.value.aclfield.data.objlist.count;
}
break;
case SAI_ATTR_VALUE_TYPE_ACL_FIELD_DATA_UINT8_LIST:
{
int i = 0;
attr->value.aclfield.enable = thrift_attr.value.aclfield.enable;
attr->value.aclfield.data.u8list.list = (uint8_t *)malloc(sizeof(uint8_t) * thrift_attr.value.aclfield.data.u8list.count);
for (auto obj : thrift_attr.value.aclfield.data.u8list.uint8list)
{
attr->value.aclfield.data.u8list.list[i++] = obj;
}
attr->value.aclfield.data.u8list.count = thrift_attr.value.aclfield.data.u8list.count;
i = 0;
attr->value.aclfield.mask.u8list.list = (uint8_t *)malloc(sizeof(uint8_t) * thrift_attr.value.aclfield.mask.u8list.count);
for (auto obj : thrift_attr.value.aclfield.mask.u8list.uint8list)
{
attr->value.aclfield.mask.u8list.list[i++] = obj;
}
attr->value.aclfield.mask.u8list.count = thrift_attr.value.aclfield.mask.u8list.count;
}
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_BOOL:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.booldata = thrift_attr.value.aclaction.parameter.booldata;
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_UINT8:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.u8 = thrift_attr.value.aclaction.parameter.u8;
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_INT8:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.s8 = thrift_attr.value.aclaction.parameter.s8;
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_UINT16:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.u16 = thrift_attr.value.aclaction.parameter.u16;
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_INT16:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.s16 = thrift_attr.value.aclaction.parameter.s16;
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_UINT32:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.u32 = thrift_attr.value.aclaction.parameter.u32;
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_INT32:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.s32 = thrift_attr.value.aclaction.parameter.s32;
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_MAC:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
sai_thrift_mac_t_parse(thrift_attr.value.aclaction.parameter.mac, &attr->value.aclaction.parameter.mac);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_IPV4:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
sai_thrift_ip4_t_parse(thrift_attr.value.aclaction.parameter.ip4, &attr->value.aclaction.parameter.ip4);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_IPV6:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
sai_thrift_ip6_t_parse(thrift_attr.value.aclaction.parameter.ip6, attr->value.aclaction.parameter.ip6);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_IP_ADDRESS:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
sai_thrift_ip_address_t_parse(thrift_attr.value.aclaction.parameter.ipaddr, &attr->value.aclaction.parameter.ipaddr);
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_ID:
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.oid = thrift_attr.value.aclaction.parameter.oid;
break;
case SAI_ATTR_VALUE_TYPE_ACL_ACTION_DATA_OBJECT_LIST:
{
int i = 0;
attr->value.aclaction.enable = thrift_attr.value.aclaction.enable;
attr->value.aclaction.parameter.objlist.list = (sai_object_id_t*)malloc(sizeof(sai_object_id_t) * thrift_attr.value.aclaction.parameter.objlist.count);
for (auto obj : thrift_attr.value.aclaction.parameter.objlist.idlist)
{
attr->value.aclaction.parameter.objlist.list[i++] = obj;
}
attr->value.aclaction.parameter.objlist.count = thrift_attr.value.aclaction.parameter.objlist.count;
}
break;
case SAI_ATTR_VALUE_TYPE_ACL_CAPABILITY:
{
attr->value.aclcapability.is_action_list_mandatory = thrift_attr.value.aclcapability.is_action_list_mandatory;
attr->value.aclcapability.action_list.list = (int32_t *)malloc(sizeof(int32_t) * thrift_attr.value.aclcapability.action_list.count);
int i = 0;
for (auto s32 : thrift_attr.value.aclcapability.action_list.int32list)
{
attr->value.aclcapability.action_list.list[i++] = s32;
}
attr->value.aclcapability.action_list.count = thrift_attr.value.aclcapability.action_list.count;
}
break;
case SAI_ATTR_VALUE_TYPE_ACL_RESOURCE_LIST:
{
attr->value.aclresource.list = (sai_acl_resource_t *)malloc(sizeof(sai_acl_resource_t) * thrift_attr.value.aclresource.count);
int i = 0;
for (auto resource : thrift_attr.value.aclresource.resourcelist)
{
attr->value.aclresource.list[i].stage = static_cast<sai_acl_stage_t>(resource.stage);
attr->value.aclresource.list[i].bind_point = static_cast<sai_acl_bind_point_type_t>(resource.bind_point);
attr->value.aclresource.list[i++].avail_num = resource.avail_num;
}
attr->value.aclresource.count = thrift_attr.value.aclresource.count;
}
break;
case SAI_ATTR_VALUE_TYPE_IP_ADDRESS_LIST:
{
attr->value.ipaddrlist.list = (sai_ip_address_t *)malloc(sizeof(sai_ip_address_t) * thrift_attr.value.ipaddrlist.count);
int i = 0;
for (auto address : thrift_attr.value.ipaddrlist.addresslist)
{
sai_thrift_ip_address_t_parse(address, &attr->value.ipaddrlist.list[i++]);
}
attr->value.ipaddrlist.count = thrift_attr.value.ipaddrlist.count;
}
break;
case SAI_ATTR_VALUE_TYPE_IP_PREFIX_LIST:
{
attr->value.ipprefixlist.list = (sai_ip_prefix_t *)malloc(sizeof(sai_ip_prefix_t) * thrift_attr.value.ipprefixlist.count);
int i = 0;
for (auto address : thrift_attr.value.ipprefixlist.prefixlist)
{
sai_thrift_ip_prefix_t_parse(address, &attr->value.ipprefixlist.list[i++]);
}
attr->value.ipprefixlist.count = thrift_attr.value.ipprefixlist.count;
}
break;
case SAI_ATTR_VALUE_TYPE_QOS_MAP_LIST:
{
attr->value.qosmap.list = (sai_qos_map_t *)malloc(sizeof(sai_qos_map_t) * thrift_attr.value.qosmap.count);
int i = 0;
for (auto qosmap : thrift_attr.value.qosmap.maplist)
{
// key
attr->value.qosmap.list[i].key.tc = qosmap.key.tc;
attr->value.qosmap.list[i].key.dscp = qosmap.key.dscp;
attr->value.qosmap.list[i].key.dot1p = qosmap.key.dot1p;
attr->value.qosmap.list[i].key.prio = qosmap.key.prio;
attr->value.qosmap.list[i].key.pg = qosmap.key.pg;
attr->value.qosmap.list[i].key.queue_index = qosmap.key.queue_index;
attr->value.qosmap.list[i].key.color = static_cast<sai_packet_color_t>(qosmap.key.color);
attr->value.qosmap.list[i].key.mpls_exp = qosmap.key.mpls_exp;
// value
attr->value.qosmap.list[i].value.tc = qosmap.value.tc;
attr->value.qosmap.list[i].value.dscp = qosmap.value.dscp;
attr->value.qosmap.list[i].value.dot1p = qosmap.value.dot1p;
attr->value.qosmap.list[i].value.prio = qosmap.value.prio;
attr->value.qosmap.list[i].value.pg = qosmap.value.pg;
attr->value.qosmap.list[i].value.queue_index = qosmap.value.queue_index;
attr->value.qosmap.list[i].value.color = static_cast<sai_packet_color_t>(qosmap.value.color);
attr->value.qosmap.list[i].value.mpls_exp = qosmap.value.mpls_exp;
i++;
}
attr->value.qosmap.count = thrift_attr.value.qosmap.count;
}
break;
default:
SAI_META_LOG_ERROR("attr value type not supported for %s", md->attridname);
throw e;
}
}