forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add asic compile/switch skeleton in redis/syncd (#9)
* Prevent copy and assignment for SaiAttributeList * Make sairedis threadsafe * Add asic compile/switch skeleton in redis/syncd * Add SaiAttribute class * Fix producer and consumer calls * Add more serialization types
- Loading branch information
Showing
13 changed files
with
356 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "saiattribute.h" | ||
|
||
#include "swss/logger.h" | ||
#include "saiserialize.h" | ||
|
||
#include "string.h" | ||
extern "C" { | ||
#include "sai.h" | ||
} | ||
|
||
SaiAttribute::SaiAttribute( | ||
_In_ const sai_object_type_t objectType, | ||
_In_ const swss::FieldValueTuple &value, | ||
_In_ bool onlyCount) : | ||
m_onlyCount(onlyCount), | ||
m_objectType(objectType) | ||
{ | ||
// TODO save those to make possible for copy constructor and assignment | ||
const std::string &strAttrId = fvField(value); | ||
const std::string &strAttrValue = fvValue(value); | ||
|
||
if (strAttrId == "NULL") | ||
{ | ||
SWSS_LOG_ERROR("NULL attribute passed"); | ||
|
||
exit(EXIT_FAILURE); | ||
} | ||
|
||
memset(&m_attr, 0, sizeof(sai_attribute_t)); | ||
|
||
int index = 0; | ||
sai_deserialize_primitive(strAttrId, index, m_attr.id); | ||
|
||
sai_status_t status = sai_get_serialization_type(m_objectType, m_attr.id, m_serializationType); | ||
|
||
if (status != SAI_STATUS_SUCCESS) | ||
{ | ||
SWSS_LOG_ERROR("failed to get serialization type for object type %lx, attribute id: %lx", | ||
m_objectType, | ||
m_attr.id); | ||
|
||
exit(EXIT_FAILURE); | ||
} | ||
|
||
index = 0; | ||
status = sai_deserialize_attr_value(strAttrValue, index, m_serializationType, m_attr, m_onlyCount); | ||
|
||
if (status != SAI_STATUS_SUCCESS) | ||
{ | ||
SWSS_LOG_ERROR("failed to deserialize attribute value: %s, serialization type: %d", | ||
strAttrValue.c_str(), | ||
m_serializationType); | ||
|
||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
SaiAttribute::~SaiAttribute() | ||
{ | ||
sai_status_t status = sai_deserialize_free_attribute_value(m_serializationType, m_attr); | ||
|
||
if (status != SAI_STATUS_SUCCESS) | ||
{ | ||
SWSS_LOG_ERROR("failed to deserialize free"); | ||
|
||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
sai_attribute_t* SaiAttribute::getAttr() | ||
{ | ||
// reference to member, we may need to | ||
// replace VID to RID or vice versa | ||
return &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,42 @@ | ||
#ifndef __SAI_ATTRIBUTE__ | ||
#define __SAI_ATTRIBUTE__ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include <hiredis/hiredis.h> | ||
#include "swss/dbconnector.h" | ||
#include "swss/table.h" | ||
#include "swss/logger.h" | ||
#include "sai.h" | ||
#include "saiserialize.h" | ||
#include "string.h" | ||
|
||
class SaiAttribute | ||
{ | ||
public: | ||
|
||
SaiAttribute( | ||
_In_ const sai_object_type_t objectType, | ||
_In_ const swss::FieldValueTuple &value, | ||
_In_ bool onlyCount); | ||
|
||
~SaiAttribute(); | ||
|
||
sai_attribute_t* getAttr(); | ||
|
||
private: | ||
|
||
SaiAttribute(const SaiAttribute&); | ||
SaiAttribute& operator=(const SaiAttribute&); | ||
|
||
bool m_onlyCount; | ||
|
||
sai_object_type_t m_objectType; | ||
sai_attribute_t m_attr; | ||
|
||
sai_attr_serialization_type_t m_serializationType; | ||
}; | ||
|
||
#endif // __SAI_ATTRIBUTE__ | ||
|
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
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
Oops, something went wrong.