-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[aclorch] add generic AclOrch::updateAclRule() method (#1993)
- What I did I added generic AclOrch::updateAclRule() implementation. This implementation takes a newly constructed shared_ptr<AclRule> provided by the user, calculates a difference between priority, matches and actions and calls sai_acl_api->set_acl_entry_attribute() for those attributes that were changed. The derivatives of AclRule can customize the behaviour of AclRule::update(const AclRule& updatedRule) by polymorphic override, although in that case the derivative needs dynamic_cast the updatedRule to a concrete derivative type. Added unit test to cover update scenario. Currently this new API is not used by any clients nor handling ACL_RULE table updates. This API will be used by PBH ACL rule update flow. - Why I did it To support the scenario for updating PBH ACL rule in the future. - How I verified it Temporary changed the ACL_RULE table update to leverage this new API and tested updates through CONFIG_DB and unit test coverage. Signed-off-by: Stepan Blyshchak <stepanb@nvidia.com>
- Loading branch information
1 parent
4f6cb05
commit da21172
Showing
10 changed files
with
783 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include "saiattr.h" | ||
|
||
#include <swss/logger.h> | ||
#include <sai_serialize.h> | ||
|
||
SaiAttrWrapper::SaiAttrWrapper(sai_object_type_t objectType, const sai_attribute_t& attr) | ||
{ | ||
auto meta = sai_metadata_get_attr_metadata(objectType, attr.id); | ||
if (!meta) | ||
{ | ||
SWSS_LOG_THROW("Failed to get attribute %d metadata", attr.id); | ||
} | ||
|
||
init(objectType, *meta, attr); | ||
} | ||
|
||
SaiAttrWrapper::~SaiAttrWrapper() | ||
{ | ||
if (m_meta) | ||
{ | ||
sai_deserialize_free_attribute_value(m_meta->attrvaluetype, m_attr); | ||
} | ||
} | ||
|
||
SaiAttrWrapper::SaiAttrWrapper(const SaiAttrWrapper& other) | ||
{ | ||
init(other.m_objectType, *other.m_meta, other.m_attr); | ||
} | ||
|
||
SaiAttrWrapper& SaiAttrWrapper::operator=(const SaiAttrWrapper& other) | ||
{ | ||
init(other.m_objectType, *other.m_meta, other.m_attr); | ||
return *this; | ||
} | ||
|
||
SaiAttrWrapper::SaiAttrWrapper(SaiAttrWrapper&& other) | ||
{ | ||
swap(std::move(other)); | ||
} | ||
|
||
SaiAttrWrapper& SaiAttrWrapper::operator=(SaiAttrWrapper&& other) | ||
{ | ||
swap(std::move(other)); | ||
return *this; | ||
} | ||
|
||
bool SaiAttrWrapper::operator<(const SaiAttrWrapper& other) const | ||
{ | ||
return m_serializedAttr < other.m_serializedAttr; | ||
} | ||
|
||
const sai_attribute_t& SaiAttrWrapper::getSaiAttr() const | ||
{ | ||
return m_attr; | ||
} | ||
|
||
std::string SaiAttrWrapper::toString() const | ||
{ | ||
return m_serializedAttr; | ||
} | ||
|
||
sai_attr_id_t SaiAttrWrapper::getAttrId() const | ||
{ | ||
return m_attr.id; | ||
} | ||
|
||
void SaiAttrWrapper::swap(SaiAttrWrapper&& other) | ||
{ | ||
m_objectType = other.m_objectType; | ||
m_meta = other.m_meta; | ||
m_attr = other.m_attr; | ||
m_serializedAttr = other.m_serializedAttr; | ||
other.m_attr = sai_attribute_t{}; | ||
other.m_serializedAttr.clear(); | ||
} | ||
|
||
void SaiAttrWrapper::init( | ||
sai_object_type_t objectType, | ||
const sai_attr_metadata_t& meta, | ||
const sai_attribute_t& attr) | ||
{ | ||
m_objectType = objectType; | ||
m_attr.id = attr.id; | ||
m_meta = &meta; | ||
|
||
m_serializedAttr = sai_serialize_attr_value(*m_meta, attr); | ||
|
||
// deserialize to actually preform a deep copy of attr | ||
// and attribute value's dynamically allocated lists. | ||
sai_deserialize_attr_value(m_serializedAttr, *m_meta, m_attr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
extern "C" | ||
{ | ||
#include <sai.h> | ||
#include <saimetadata.h> | ||
} | ||
|
||
#include <string> | ||
|
||
class SaiAttrWrapper | ||
{ | ||
public: | ||
SaiAttrWrapper() = default; | ||
|
||
SaiAttrWrapper(sai_object_type_t objectType, const sai_attribute_t& attr); | ||
SaiAttrWrapper(const SaiAttrWrapper& other); | ||
SaiAttrWrapper(SaiAttrWrapper&& other); | ||
SaiAttrWrapper& operator=(const SaiAttrWrapper& other); | ||
SaiAttrWrapper& operator=(SaiAttrWrapper&& other); | ||
virtual ~SaiAttrWrapper(); | ||
|
||
bool operator<(const SaiAttrWrapper& other) const; | ||
|
||
const sai_attribute_t& getSaiAttr() const; | ||
std::string toString() const; | ||
sai_attr_id_t getAttrId() const; | ||
|
||
private: | ||
|
||
void init( | ||
sai_object_type_t objectType, | ||
const sai_attr_metadata_t& meta, | ||
const sai_attribute_t& attr); | ||
void swap(SaiAttrWrapper&& other); | ||
|
||
sai_object_type_t m_objectType {SAI_OBJECT_TYPE_NULL}; | ||
const sai_attr_metadata_t* m_meta {nullptr}; | ||
sai_attribute_t m_attr {}; | ||
std::string m_serializedAttr; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.