Skip to content

Commit

Permalink
[sairedis] Add support for bulk api in client/server (#844)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Jun 24, 2021
1 parent 76d28a6 commit 7c70e34
Show file tree
Hide file tree
Showing 4 changed files with 793 additions and 52 deletions.
46 changes: 45 additions & 1 deletion lib/inc/ServerSai.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "SaiInterface.h"

#include "meta/SaiAttributeList.h"
#include "syncd/SelectableChannel.h"

#include "swss/selectableevent.h"
Expand Down Expand Up @@ -291,6 +291,50 @@ namespace sairedis
_In_ uint32_t attr_count,
_In_ sai_attribute_t *attr_list);

// BULK

sai_status_t processBulkQuadEvent(
_In_ sai_common_api_t api,
_In_ const swss::KeyOpFieldsValuesTuple &kco);

sai_status_t processBulkOid(
_In_ sai_object_type_t objectType,
_In_ const std::vector<std::string>& strObjectIds,
_In_ sai_common_api_t api,
_In_ const std::vector<std::shared_ptr<saimeta::SaiAttributeList>>& attributes,
_In_ const std::vector<std::vector<swss::FieldValueTuple>>& strAttributes);

sai_status_t processBulkEntry(
_In_ sai_object_type_t objectType,
_In_ const std::vector<std::string>& objectIds,
_In_ sai_common_api_t api,
_In_ const std::vector<std::shared_ptr<saimeta::SaiAttributeList>>& attributes,
_In_ const std::vector<std::vector<swss::FieldValueTuple>>& strAttributes);

sai_status_t processBulkCreateEntry(
_In_ sai_object_type_t objectType,
_In_ const std::vector<std::string>& objectIds,
_In_ const std::vector<std::shared_ptr<saimeta::SaiAttributeList>>& attributes,
_Out_ std::vector<sai_status_t>& statuses);

sai_status_t processBulkRemoveEntry(
_In_ sai_object_type_t objectType,
_In_ const std::vector<std::string>& objectIds,
_Out_ std::vector<sai_status_t>& statuses);

sai_status_t processBulkSetEntry(
_In_ sai_object_type_t objectType,
_In_ const std::vector<std::string>& objectIds,
_In_ const std::vector<std::shared_ptr<saimeta::SaiAttributeList>>& attributes,
_Out_ std::vector<sai_status_t>& statuses);

void sendBulkApiResponse(
_In_ sai_common_api_t api,
_In_ sai_status_t status,
_In_ uint32_t object_count,
_In_ const sai_object_id_t* object_ids,
_In_ const sai_status_t* statuses);

private:

bool m_apiInitialized;
Expand Down
72 changes: 36 additions & 36 deletions lib/src/ClientSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ sai_status_t ClientSai::waitForQueryAttributeCapabilityResponse(
capability->get_implemented = (fvValue(values[2]) == "true" ? true : false);

SWSS_LOG_DEBUG("Received payload: create_implemented:%s, set_implemented:%s, get_implemented:%s",
(capability->create_implemented ? "true" : "false"),
(capability->set_implemented ? "true" : "false"),
(capability->create_implemented ? "true" : "false"),
(capability->set_implemented ? "true" : "false"),
(capability->get_implemented ? "true" : "false"));
}

Expand Down Expand Up @@ -1012,40 +1012,40 @@ sai_status_t ClientSai::bulkCreate(

// TODO support mode

SWSS_LOG_THROW("TODO, not implemented, FIXME");

//for (uint32_t idx = 0; idx < object_count; idx++)
//{
// object_id[idx] = m_virtualObjectIdManager->allocateNewObjectId(object_type, switch_id);

// if (object_id[idx] == SAI_NULL_OBJECT_ID)
// {
// SWSS_LOG_ERROR("failed to create %s, with switch id: %s",
// sai_serialize_object_type(object_type).c_str(),
// sai_serialize_object_id(switch_id).c_str());

// return SAI_STATUS_INSUFFICIENT_RESOURCES;
// }
//}

//std::vector<std::string> serialized_object_ids;

//// on create vid is put in db by syncd
//for (uint32_t idx = 0; idx < object_count; idx++)
//{
// std::string str_object_id = sai_serialize_object_id(object_id[idx]);
// serialized_object_ids.push_back(str_object_id);
//}

//auto status = bulkCreate(
// object_type,
// serialized_object_ids,
// attr_count,
// attr_list,
// mode,
// object_statuses);
// TODO m_lastCreateOids
std::vector<std::string> serialized_object_ids;

// server is responsible for generate new OID but for that we need switch ID
// to be sent to server as well, so instead of sending empty oids we will
// send switch IDs
for (uint32_t idx = 0; idx < object_count; idx++)
{
serialized_object_ids.emplace_back(sai_serialize_object_id(switch_id));
}

auto status = bulkCreate(
object_type,
serialized_object_ids,
attr_count,
attr_list,
mode,
object_statuses);

for (uint32_t idx = 0; idx < object_count; idx++)
{
// since user requested create, OID value was created remotely and it
// was returned in m_lastCreateOids

if (object_statuses[idx] == SAI_STATUS_SUCCESS)
{
object_id[idx] = m_lastCreateOids.at(idx);
}
else
{
object_id[idx] = SAI_NULL_OBJECT_ID;
}
}

return status;
}

sai_status_t ClientSai::bulkCreate(
Expand Down
Loading

0 comments on commit 7c70e34

Please sign in to comment.