Skip to content

Commit

Permalink
Move joinFieldValues to libsaimeta
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 21, 2021
1 parent 638ca82 commit cc5ab4c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 78 deletions.
9 changes: 3 additions & 6 deletions lib/src/ClientSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ using namespace std::placeholders;

// TODO how to tell if current SAI is in init view or apply view ?

std::string joinFieldValues(
_In_ const std::vector<swss::FieldValueTuple> &values);

std::vector<swss::FieldValueTuple> serialize_counter_id_list(
_In_ const sai_enum_metadata_t *stats_enum,
_In_ uint32_t count,
Expand Down Expand Up @@ -646,7 +643,7 @@ sai_status_t ClientSai::objectTypeGetAvailability(
SWSS_LOG_DEBUG(
"Query arguments: switch: %s, attributes: %s",
strSwitchId.c_str(),
joinFieldValues(entry).c_str());
Globals::joinFieldValues(entry).c_str());

// Syncd will pop this argument off before trying to deserialize the attribute list

Expand Down Expand Up @@ -1241,7 +1238,7 @@ sai_status_t ClientSai::bulkCreate(
entry.push_back(null);
}

std::string str_attr = joinFieldValues(entry);
std::string str_attr = Globals::joinFieldValues(entry);

swss::FieldValueTuple fvtNoStatus(serialized_object_ids[idx] , str_attr);

Expand Down Expand Up @@ -1537,7 +1534,7 @@ sai_status_t ClientSai::bulkSet(
{
auto entry = SaiAttributeList::serialize_attr_list(object_type, 1, &attr_list[idx], false);

std::string str_attr = joinFieldValues(entry);
std::string str_attr = Globals::joinFieldValues(entry);

swss::FieldValueTuple value(serialized_object_ids[idx], str_attr);

Expand Down
34 changes: 16 additions & 18 deletions lib/src/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "meta/sai_serialize.h"
#include "meta/SaiAttributeList.h"
#include "meta/Globals.h"

#include <unistd.h>
#include <inttypes.h>
Expand All @@ -13,9 +14,6 @@
using namespace sairedis;
using namespace saimeta;

std::string joinFieldValues(
_In_ const std::vector<swss::FieldValueTuple> &values);

std::vector<swss::FieldValueTuple> serialize_counter_id_list(
_In_ const sai_enum_metadata_t *stats_enum,
_In_ uint32_t count,
Expand Down Expand Up @@ -307,7 +305,7 @@ void Recorder::recordFlushFdbEntries(
{
SWSS_LOG_ENTER();

recordLine("f|" + key + "|" + joinFieldValues(arguments));
recordLine("f|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordFlushFdbEntriesResponse(
Expand All @@ -324,7 +322,7 @@ void Recorder::recordQueryAttributeCapability(
{
SWSS_LOG_ENTER();

recordLine("q|attribute_capability|" + key + "|" + joinFieldValues(arguments));
recordLine("q|attribute_capability|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordQueryAttributeCapabilityResponse(
Expand All @@ -333,7 +331,7 @@ void Recorder::recordQueryAttributeCapabilityResponse(
{
SWSS_LOG_ENTER();

recordLine("Q|attribute_capability|" + sai_serialize_status(status) + "|" + joinFieldValues(arguments));
recordLine("Q|attribute_capability|" + sai_serialize_status(status) + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordQueryAttributeEnumValuesCapability(
Expand All @@ -342,7 +340,7 @@ void Recorder::recordQueryAttributeEnumValuesCapability(
{
SWSS_LOG_ENTER();

recordLine("q|attribute_enum_values_capability|" + key + "|" + joinFieldValues(arguments));
recordLine("q|attribute_enum_values_capability|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordQueryAttributeEnumValuesCapabilityResponse(
Expand All @@ -351,7 +349,7 @@ void Recorder::recordQueryAttributeEnumValuesCapabilityResponse(
{
SWSS_LOG_ENTER();

recordLine("Q|attribute_enum_values_capability|" + sai_serialize_status(status) + "|" + joinFieldValues(arguments));
recordLine("Q|attribute_enum_values_capability|" + sai_serialize_status(status) + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordObjectTypeGetAvailability(
Expand All @@ -360,7 +358,7 @@ void Recorder::recordObjectTypeGetAvailability(
{
SWSS_LOG_ENTER();

recordLine("q|object_type_get_availability|" + key + "|" + joinFieldValues(arguments));
recordLine("q|object_type_get_availability|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordObjectTypeGetAvailabilityResponse(
Expand All @@ -369,7 +367,7 @@ void Recorder::recordObjectTypeGetAvailabilityResponse(
{
SWSS_LOG_ENTER();

recordLine("Q|object_type_get_availability|" + sai_serialize_status(status) + "|" + joinFieldValues(arguments));
recordLine("Q|object_type_get_availability|" + sai_serialize_status(status) + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordNotifySyncd(
Expand Down Expand Up @@ -400,7 +398,7 @@ void Recorder::recordGenericCreate(

// lower case 'c' stands for create api

recordLine("c|" + key + "|" + joinFieldValues(arguments));
recordLine("c|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordGenericCreateResponse(
Expand Down Expand Up @@ -534,7 +532,7 @@ void Recorder::recordGenericSet(

// lower case 's' stands for SET api

recordLine("s|" + key + "|" + joinFieldValues(arguments));
recordLine("s|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordGenericSetResponse(
Expand Down Expand Up @@ -600,7 +598,7 @@ void Recorder::recordGenericGet(

// lower case 'g' stands for GET api

recordLine("g|" + key + "|" + joinFieldValues(arguments));
recordLine("g|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordGenericGetResponse(
Expand All @@ -611,7 +609,7 @@ void Recorder::recordGenericGetResponse(

// capital 'G' stands for GET api response

recordLine("G|" + sai_serialize_status(status) + "|" + joinFieldValues(arguments));
recordLine("G|" + sai_serialize_status(status) + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordGenericGetStats(
Expand Down Expand Up @@ -647,7 +645,7 @@ void Recorder::recordGenericGetStats(
if (!m_recordStats)
return;

recordLine("q|get_stats|" + key + "|" + joinFieldValues(arguments));
recordLine("q|get_stats|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordGenericGetStatsResponse(
Expand Down Expand Up @@ -702,7 +700,7 @@ void Recorder::recordGenericClearStats(
if (!m_recordStats)
return;

recordLine("q|clear_stats|" + key + "|" + joinFieldValues(arguments));
recordLine("q|clear_stats|" + key + "|" + Globals::joinFieldValues(arguments));
}

void Recorder::recordGenericClearStatsResponse(
Expand All @@ -723,7 +721,7 @@ void Recorder::recordNotification(
{
SWSS_LOG_ENTER();

recordLine("n|" + name + "|" + serializedNotification + "|" + joinFieldValues(values));
recordLine("n|" + name + "|" + serializedNotification + "|" + Globals::joinFieldValues(values));
}

void Recorder::recordRemove(
Expand Down Expand Up @@ -937,7 +935,7 @@ void Recorder::recordObjectTypeGetAvailability(
attrList,
false);

SWSS_LOG_DEBUG("Query arguments: switch: %s, attributes: %s", key.c_str(), joinFieldValues(values).c_str());
SWSS_LOG_DEBUG("Query arguments: switch: %s, attributes: %s", key.c_str(), Globals::joinFieldValues(values).c_str());

recordObjectTypeGetAvailability(key, values);
}
Expand Down
9 changes: 3 additions & 6 deletions lib/src/RedisRemoteSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ using namespace saimeta;
using namespace sairediscommon;
using namespace std::placeholders;

std::string joinFieldValues(
_In_ const std::vector<swss::FieldValueTuple> &values);

std::vector<swss::FieldValueTuple> serialize_counter_id_list(
_In_ const sai_enum_metadata_t *stats_enum,
_In_ uint32_t count,
Expand Down Expand Up @@ -887,7 +884,7 @@ sai_status_t RedisRemoteSaiInterface::objectTypeGetAvailability(
SWSS_LOG_DEBUG(
"Query arguments: switch: %s, attributes: %s",
strSwitchId.c_str(),
joinFieldValues(entry).c_str());
Globals::joinFieldValues(entry).c_str());

// Syncd will pop this argument off before trying to deserialize the attribute list

Expand Down Expand Up @@ -1534,7 +1531,7 @@ sai_status_t RedisRemoteSaiInterface::bulkSet(
{
auto entry = SaiAttributeList::serialize_attr_list(object_type, 1, &attr_list[idx], false);

std::string str_attr = joinFieldValues(entry);
std::string str_attr = Globals::joinFieldValues(entry);

swss::FieldValueTuple value(serialized_object_ids[idx], str_attr);

Expand Down Expand Up @@ -1632,7 +1629,7 @@ sai_status_t RedisRemoteSaiInterface::bulkCreate(
entry.push_back(null);
}

std::string str_attr = joinFieldValues(entry);
std::string str_attr = Globals::joinFieldValues(entry);

swss::FieldValueTuple fvtNoStatus(serialized_object_ids[idx] , str_attr);

Expand Down
23 changes: 0 additions & 23 deletions lib/src/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,29 +730,6 @@ std::shared_ptr<Context> Sai::getContext(
return it->second;
}

std::string joinFieldValues(
_In_ const std::vector<swss::FieldValueTuple> &values)
{
SWSS_LOG_ENTER();

std::stringstream ss;

for (size_t i = 0; i < values.size(); ++i)
{
const std::string &str_attr_id = fvField(values[i]);
const std::string &str_attr_value = fvValue(values[i]);

if (i != 0)
{
ss << "|";
}

ss << str_attr_id << "=" << str_attr_value;
}

return ss.str();
}

std::vector<swss::FieldValueTuple> serialize_counter_id_list(
_In_ const sai_enum_metadata_t *stats_enum,
_In_ uint32_t count,
Expand Down
28 changes: 3 additions & 25 deletions lib/src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern "C" {

#include "meta/sai_serialize.h"
#include "meta/SaiAttributeList.h"
#include "meta/Globals.h"

#include <unistd.h>

Expand Down Expand Up @@ -578,29 +579,6 @@ void test_serialize_create_oid(int n)
std::cout << "ms: " << (double)us.count()/1000 << " / " << n << std::endl;
}

std::string joinFieldValues(
_In_ const std::vector<swss::FieldValueTuple> &values)
{
SWSS_LOG_ENTER();

std::stringstream ss;

for (size_t i = 0; i < values.size(); ++i)
{
const std::string &str_attr_id = fvField(values[i]);
const std::string &str_attr_value = fvValue(values[i]);

if (i != 0)
{
ss << "|";
}

ss << str_attr_id << "=" << str_attr_value;
}

return ss.str();
}

std::string serialize_bulk_create_route_entry(int per)
{
SWSS_LOG_ENTER();
Expand All @@ -618,7 +596,7 @@ std::string serialize_bulk_create_route_entry(int per)
std::vector<swss::FieldValueTuple> entry =
SaiAttributeList::serialize_attr_list(SAI_OBJECT_TYPE_ROUTE_ENTRY, list->get_attr_count(), list->get_attr_list(), false);

std::string str_attr = joinFieldValues(entry);
std::string str_attr = Globals::joinFieldValues(entry);

std::string str_status = sai_serialize_status(SAI_STATUS_NOT_EXECUTED);

Expand Down Expand Up @@ -678,7 +656,7 @@ std::string serialize_bulk_create_oid(int per)
std::vector<swss::FieldValueTuple> entry =
SaiAttributeList::serialize_attr_list(SAI_OBJECT_TYPE_VLAN, list->get_attr_count(), list->get_attr_list(), false);

std::string str_attr = joinFieldValues(entry);
std::string str_attr = Globals::joinFieldValues(entry);

std::string str_status = sai_serialize_status(SAI_STATUS_NOT_EXECUTED);

Expand Down
20 changes: 20 additions & 0 deletions meta/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ std::string Globals::getHardwareInfo(

return std::string((const char*)s8list.list, actualLength);
}

std::string Globals::joinFieldValues(
_In_ const std::vector<swss::FieldValueTuple>& values)
{
SWSS_LOG_ENTER();

std::stringstream ss;

for (size_t i = 0; i < values.size(); ++i)
{
if (i != 0)
{
ss << "|";
}

ss << fvField(values[i]) << "=" << fvValue(values[i]);
}

return ss.str();
}
4 changes: 4 additions & 0 deletions meta/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern "C" {
}

#include "swss/logger.h"
#include "swss/table.h"

#include <string>

Expand Down Expand Up @@ -34,6 +35,9 @@ namespace saimeta
static std::string getHardwareInfo(
_In_ uint32_t attrCount,
_In_ const sai_attribute_t *attrList);

static std::string joinFieldValues(
_In_ const std::vector<swss::FieldValueTuple>& values);
};
}

Expand Down

0 comments on commit cc5ab4c

Please sign in to comment.