Skip to content

Commit

Permalink
[hash]: Handle review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Nazarii Hnydyn <[email protected]>
  • Loading branch information
nazariig committed Jun 1, 2023
1 parent 58f8df3 commit 6849bce
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 115 deletions.
4 changes: 2 additions & 2 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ orchagent_SOURCES = \
pbhorch.cpp \
saihelper.cpp \
saiattr.cpp \
switch/swcap.cpp \
switch/swhlpr.cpp \
switch/switch_capabilities.cpp \
switch/switch_helper.cpp \
switchorch.cpp \
pfcwdorch.cpp \
pfcactionhandler.cpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ extern "C" {
#include <schema.h>
#include <logger.h>

#include "swschema.h"
#include "swcap.h"
#include "switch_schema.h"
#include "switch_capabilities.h"

using namespace swss;

Expand Down Expand Up @@ -99,45 +99,45 @@ Table SwitchCapabilities::capTable(&stateDb, STATE_SWITCH_CAPABILITY_TABLE_NAME)

SwitchCapabilities::SwitchCapabilities()
{
this->queryHashCapabilities();
this->querySwitchCapabilities();
queryHashCapabilities();
querySwitchCapabilities();

this->writeHashCapabilitiesToDb();
this->writeSwitchCapabilitiesToDb();
writeHashCapabilitiesToDb();
writeSwitchCapabilitiesToDb();
}

bool SwitchCapabilities::isSwitchEcmpHashSupported() const
{
const auto &nativeHashFieldList = this->hashCapabilities.nativeHashFieldList;
const auto &ecmpHash = this->switchCapabilities.ecmpHash;
const auto &nativeHashFieldList = hashCapabilities.nativeHashFieldList;
const auto &ecmpHash = switchCapabilities.ecmpHash;

return nativeHashFieldList.isAttrSupported && ecmpHash.isAttrSupported;
}

bool SwitchCapabilities::isSwitchLagHashSupported() const
{
const auto &nativeHashFieldList = this->hashCapabilities.nativeHashFieldList;
const auto &lagHash = this->switchCapabilities.lagHash;
const auto &nativeHashFieldList = hashCapabilities.nativeHashFieldList;
const auto &lagHash = switchCapabilities.lagHash;

return nativeHashFieldList.isAttrSupported && lagHash.isAttrSupported;
}

bool SwitchCapabilities::validateSwitchHashFieldCap(const std::set<sai_native_hash_field_t> &hfSet) const
{
if (!this->hashCapabilities.nativeHashFieldList.isEnumSupported)
if (!hashCapabilities.nativeHashFieldList.isEnumSupported)
{
return true;
}

if (this->hashCapabilities.nativeHashFieldList.hfSet.empty())
if (hashCapabilities.nativeHashFieldList.hfSet.empty())
{
SWSS_LOG_ERROR("Failed to validate hash field: no hash field capabilities");
return false;
}

for (const auto &cit : hfSet)
{
if (this->hashCapabilities.nativeHashFieldList.hfSet.count(cit) == 0)
if (hashCapabilities.nativeHashFieldList.hfSet.count(cit) == 0)
{
SWSS_LOG_ERROR("Failed to validate hash field: value(%s) is not supported");
return false;
Expand All @@ -149,7 +149,7 @@ bool SwitchCapabilities::validateSwitchHashFieldCap(const std::set<sai_native_ha

FieldValueTuple SwitchCapabilities::makeHashFieldCapDbEntry() const
{
const auto &nativeHashFieldList = this->hashCapabilities.nativeHashFieldList;
const auto &nativeHashFieldList = hashCapabilities.nativeHashFieldList;

auto field = SWITCH_CAPABILITY_HASH_NATIVE_HASH_FIELD_LIST_FIELD;
auto value = nativeHashFieldList.isEnumSupported ? toStr(nativeHashFieldList.hfSet) : "N/A";
Expand All @@ -160,15 +160,15 @@ FieldValueTuple SwitchCapabilities::makeHashFieldCapDbEntry() const
FieldValueTuple SwitchCapabilities::makeEcmpHashCapDbEntry() const
{
auto field = SWITCH_CAPABILITY_ECMP_HASH_CAPABLE_FIELD;
auto value = toStr(this->isSwitchEcmpHashSupported());
auto value = toStr(isSwitchEcmpHashSupported());

return FieldValueTuple(field, value);
}

FieldValueTuple SwitchCapabilities::makeLagHashCapDbEntry() const
{
auto field = SWITCH_CAPABILITY_LAG_HASH_CAPABLE_FIELD;
auto value = toStr(this->isSwitchLagHashSupported());
auto value = toStr(isSwitchLagHashSupported());

return FieldValueTuple(field, value);
}
Expand Down Expand Up @@ -199,7 +199,7 @@ void SwitchCapabilities::queryHashNativeHashFieldListEnumCapabilities()
SWSS_LOG_ENTER();

std::vector<sai_int32_t> hfList;
auto status = this->queryEnumCapabilitiesSai(
auto status = queryEnumCapabilitiesSai(
hfList, SAI_OBJECT_TYPE_HASH, SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST
);
if (status != SAI_STATUS_SUCCESS)
Expand All @@ -211,13 +211,13 @@ void SwitchCapabilities::queryHashNativeHashFieldListEnumCapabilities()
return;
}

auto &hfSet = this->hashCapabilities.nativeHashFieldList.hfSet;
auto &hfSet = hashCapabilities.nativeHashFieldList.hfSet;
std::transform(
hfList.cbegin(), hfList.cend(), std::inserter(hfSet, hfSet.begin()),
[](sai_int32_t value) { return static_cast<sai_native_hash_field_t>(value); }
);

this->hashCapabilities.nativeHashFieldList.isEnumSupported = true;
hashCapabilities.nativeHashFieldList.isEnumSupported = true;
}

void SwitchCapabilities::queryHashNativeHashFieldListAttrCapabilities()
Expand All @@ -226,7 +226,7 @@ void SwitchCapabilities::queryHashNativeHashFieldListAttrCapabilities()

sai_attr_capability_t attrCap;

auto status = this->queryAttrCapabilitiesSai(
auto status = queryAttrCapabilitiesSai(
attrCap, SAI_OBJECT_TYPE_HASH, SAI_HASH_ATTR_NATIVE_HASH_FIELD_LIST
);
if (status != SAI_STATUS_SUCCESS)
Expand All @@ -247,13 +247,13 @@ void SwitchCapabilities::queryHashNativeHashFieldListAttrCapabilities()
return;
}

this->hashCapabilities.nativeHashFieldList.isAttrSupported = true;
hashCapabilities.nativeHashFieldList.isAttrSupported = true;
}

void SwitchCapabilities::queryHashCapabilities()
{
this->queryHashNativeHashFieldListEnumCapabilities();
this->queryHashNativeHashFieldListAttrCapabilities();
queryHashNativeHashFieldListEnumCapabilities();
queryHashNativeHashFieldListAttrCapabilities();
}

void SwitchCapabilities::querySwitchEcmpHashCapabilities()
Expand All @@ -262,7 +262,7 @@ void SwitchCapabilities::querySwitchEcmpHashCapabilities()

sai_attr_capability_t attrCap;

auto status = this->queryAttrCapabilitiesSai(
auto status = queryAttrCapabilitiesSai(
attrCap, SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_ECMP_HASH
);
if (status != SAI_STATUS_SUCCESS)
Expand All @@ -283,7 +283,7 @@ void SwitchCapabilities::querySwitchEcmpHashCapabilities()
return;
}

this->switchCapabilities.ecmpHash.isAttrSupported = true;
switchCapabilities.ecmpHash.isAttrSupported = true;
}

void SwitchCapabilities::querySwitchLagHashCapabilities()
Expand All @@ -292,7 +292,7 @@ void SwitchCapabilities::querySwitchLagHashCapabilities()

sai_attr_capability_t attrCap;

auto status = this->queryAttrCapabilitiesSai(
auto status = queryAttrCapabilitiesSai(
attrCap, SAI_OBJECT_TYPE_SWITCH, SAI_SWITCH_ATTR_LAG_HASH
);
if (status != SAI_STATUS_SUCCESS)
Expand All @@ -313,13 +313,13 @@ void SwitchCapabilities::querySwitchLagHashCapabilities()
return;
}

this->switchCapabilities.lagHash.isAttrSupported = true;
switchCapabilities.lagHash.isAttrSupported = true;
}

void SwitchCapabilities::querySwitchCapabilities()
{
this->querySwitchEcmpHashCapabilities();
this->querySwitchLagHashCapabilities();
querySwitchEcmpHashCapabilities();
querySwitchLagHashCapabilities();
}

void SwitchCapabilities::writeHashCapabilitiesToDb()
Expand All @@ -329,7 +329,7 @@ void SwitchCapabilities::writeHashCapabilitiesToDb()
auto key = SwitchCapabilities::capTable.getKeyName(SWITCH_CAPABILITY_KEY);

std::vector<FieldValueTuple> fvList = {
this->makeHashFieldCapDbEntry()
makeHashFieldCapDbEntry()
};

SwitchCapabilities::capTable.set(SWITCH_CAPABILITY_KEY, fvList);
Expand All @@ -344,8 +344,8 @@ void SwitchCapabilities::writeSwitchCapabilitiesToDb()
auto key = SwitchCapabilities::capTable.getKeyName(SWITCH_CAPABILITY_KEY);

std::vector<FieldValueTuple> fvList = {
this->makeEcmpHashCapDbEntry(),
this->makeLagHashCapDbEntry()
makeEcmpHashCapDbEntry(),
makeLagHashCapDbEntry()
};

SwitchCapabilities::capTable.set(SWITCH_CAPABILITY_KEY, fvList);
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <tokenize.h>
#include <logger.h>

#include "swschema.h"
#include "swhlpr.h"
#include "switch_schema.h"
#include "switch_helper.h"

using namespace swss;

Expand Down Expand Up @@ -40,12 +40,12 @@ static const std::unordered_map<std::string, sai_native_hash_field_t> swHashHash

const SwitchHash& SwitchHelper::getSwHash() const
{
return this->swHash;
return swHash;
}

void SwitchHelper::setSwHash(const SwitchHash &hash)
{
this->swHash = hash;
swHash = hash;
}

template<typename T>
Expand Down Expand Up @@ -88,12 +88,12 @@ bool SwitchHelper::parseSwHashFieldList(T &obj, const std::string &field, const

bool SwitchHelper::parseSwHashEcmpHash(SwitchHash &hash, const std::string &field, const std::string &value) const
{
return this->parseSwHashFieldList(hash.ecmp_hash, field, value);
return parseSwHashFieldList(hash.ecmp_hash, field, value);
}

bool SwitchHelper::parseSwHashLagHash(SwitchHash &hash, const std::string &field, const std::string &value) const
{
return this->parseSwHashFieldList(hash.lag_hash, field, value);
return parseSwHashFieldList(hash.lag_hash, field, value);
}

bool SwitchHelper::parseSwHash(SwitchHash &hash) const
Expand All @@ -107,14 +107,14 @@ bool SwitchHelper::parseSwHash(SwitchHash &hash) const

if (field == SWITCH_HASH_ECMP_HASH)
{
if (!this->parseSwHashEcmpHash(hash, field, value))
if (!parseSwHashEcmpHash(hash, field, value))
{
return false;
}
}
else if (field == SWITCH_HASH_LAG_HASH)
{
if (!this->parseSwHashLagHash(hash, field, value))
if (!parseSwHashLagHash(hash, field, value))
{
return false;
}
Expand All @@ -125,7 +125,7 @@ bool SwitchHelper::parseSwHash(SwitchHash &hash) const
}
}

return this->validateSwHash(hash);
return validateSwHash(hash);
}

bool SwitchHelper::validateSwHash(SwitchHash &hash) const
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "swcnt.h"
#include "switch_container.h"

class SwitchHelper final
{
Expand Down
File renamed without changes.
Loading

0 comments on commit 6849bce

Please sign in to comment.