-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add poesyncd daemon Parse PoE-related configs *What I did* Add support for PoE based on sonic-sairedis support of multiple switches. *How I verified it* Builds and tests using VS builds. Signed-off-by: Serhiy Boiko <[email protected]>
- Loading branch information
1 parent
43ac585
commit 36cb50a
Showing
23 changed files
with
1,564 additions
and
5 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
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,50 @@ | ||
#include "poemgr.h" | ||
#include "logger.h" | ||
#include "tokenize.h" | ||
#include "warm_restart.h" | ||
#include "converter.h" | ||
|
||
using namespace swss; | ||
|
||
PoeMgr::PoeMgr(DBConnector *appDb, DBConnector *cfgDb, const std::vector<std::string> &poeTables) : | ||
Orch(cfgDb, poeTables), | ||
m_appPoeTable(appDb, APP_POE_TABLE_NAME) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
} | ||
|
||
void PoeMgr::doTask(Consumer &consumer) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
std::string table_name = consumer.getTableName(); | ||
if (table_name != CFG_POE_TABLE_NAME) | ||
{ | ||
SWSS_LOG_ERROR("Unknown config table %s ", table_name.c_str()); | ||
throw std::runtime_error("PoeMgr doTask failure."); | ||
} | ||
|
||
auto it = consumer.m_toSync.begin(); | ||
while (it != consumer.m_toSync.end()) | ||
{ | ||
KeyOpFieldsValuesTuple t = it->second; | ||
std::string alias = kfvKey(t); | ||
std::string op = kfvOp(t); | ||
|
||
SWSS_LOG_NOTICE("TABLE key: %s : %s", alias.c_str(), op.c_str()); | ||
if (op == SET_COMMAND) | ||
{ | ||
SWSS_LOG_NOTICE("Add PoE port: %s", alias.c_str()); | ||
m_appPoeTable.set(alias, kfvFieldsValues(t)); | ||
} | ||
else if (op == DEL_COMMAND) | ||
{ | ||
SWSS_LOG_NOTICE("Removing PoE port: %s", alias.c_str()); | ||
m_appPoeTable.del(alias); | ||
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR("Unknown operation type %s", op.c_str()); | ||
} | ||
it = consumer.m_toSync.erase(it); | ||
} | ||
} |
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,28 @@ | ||
#ifndef __POEMGR__ | ||
#define __POEMGR__ | ||
|
||
#include "dbconnector.h" | ||
#include "producerstatetable.h" | ||
#include "orch.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace swss { | ||
|
||
class PoeMgr : public Orch | ||
{ | ||
public: | ||
PoeMgr(DBConnector *appDb, DBConnector *cfgDb, const std::vector<std::string> &poeTables); | ||
using Orch::doTask; | ||
|
||
private: | ||
ProducerStateTable m_appPoeTable; | ||
|
||
void doTask(Consumer &consumer); | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif |
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,70 @@ | ||
#include <vector> | ||
|
||
#include "poemgr.h" | ||
#include "dbconnector.h" | ||
#include "select.h" | ||
#include "warm_restart.h" | ||
|
||
using namespace swss; | ||
|
||
/* select() function timeout retry time, in millisecond */ | ||
#define SELECT_TIMEOUT 1000 | ||
|
||
|
||
int main(int argc, char **argv) | ||
{ | ||
Logger::linkToDbNative("poemgrd"); | ||
SWSS_LOG_ENTER(); | ||
|
||
SWSS_LOG_NOTICE("--- Starting poemgrd ---"); | ||
|
||
try | ||
{ | ||
std::vector<std::string> cfg_tables = { | ||
CFG_POE_TABLE_NAME, | ||
}; | ||
|
||
DBConnector cfgDb("CONFIG_DB", 0); | ||
DBConnector appDb("APPL_DB", 0); | ||
|
||
WarmStart::initialize("poemgrd", "swss"); | ||
WarmStart::checkWarmStart("poemgrd", "swss"); | ||
|
||
PoeMgr manager(&appDb, &cfgDb, cfg_tables); | ||
|
||
std::vector<Orch *> cfgOrchList = {&manager}; | ||
|
||
Select s; | ||
for (Orch *o : cfgOrchList) | ||
{ | ||
s.addSelectables(o->getSelectables()); | ||
} | ||
|
||
SWSS_LOG_NOTICE("starting main loop"); | ||
while (true) | ||
{ | ||
Selectable *sel; | ||
int ret; | ||
|
||
ret = s.select(&sel, SELECT_TIMEOUT); | ||
if (ret == Select::ERROR) | ||
{ | ||
SWSS_LOG_NOTICE("Error: %s!", strerror(errno)); | ||
continue; | ||
} | ||
if (ret == Select::TIMEOUT) | ||
{ | ||
manager.doTask(); | ||
continue; | ||
} | ||
|
||
auto *c = (Executor *)sel; | ||
c->execute(); | ||
} | ||
} | ||
catch(const std::exception &e) | ||
{ | ||
SWSS_LOG_ERROR("Runtime error: %s", e.what()); | ||
} | ||
return -1; | ||
} |
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.