Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swss] Add support for PoE feature #3238

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ cfgmgr/portmgrd
cfgmgr/sflowmgrd
cfgmgr/teammgrd
cfgmgr/vlanmgrd
cfgmgr/poemgrd
cfgmgr/vrfmgrd
cfgmgr/vxlanmgrd
cfgmgr/natmgrd
Expand Down
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if GCOV_ENABLED
SUBDIRS = gcovpreload fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd fdbsyncd orchagent swssconfig cfgmgr tests gearsyncd
SUBDIRS = gcovpreload fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd fdbsyncd orchagent swssconfig cfgmgr tests gearsyncd poesyncd
else
SUBDIRS = fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd fdbsyncd orchagent swssconfig cfgmgr tests gearsyncd
SUBDIRS = fpmsyncd neighsyncd portsyncd mclagsyncd natsyncd fdbsyncd orchagent swssconfig cfgmgr tests gearsyncd poesyncd
endif


Expand Down
9 changes: 8 additions & 1 deletion cfgmgr/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LIBNL_LIBS = -lnl-genl-3 -lnl-route-3 -lnl-3
SAIMETA_LIBS = -lsaimeta -lsaimetadata -lzmq
COMMON_LIBS = -lswsscommon -lpthread

bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd coppmgrd tunnelmgrd macsecmgrd fabricmgrd
bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd coppmgrd tunnelmgrd macsecmgrd fabricmgrd poemgrd

cfgmgrdir = $(datadir)/swss

Expand Down Expand Up @@ -101,6 +101,11 @@ macsecmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CF
macsecmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
macsecmgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS)

poemgrd_SOURCES = poemgrd.cpp poemgr.cpp $(COMMON_ORCH_SOURCE) shellcmd.h
poemgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
poemgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI) $(CFLAGS_ASAN)
poemgrd_LDADD = $(LDFLAGS_ASAN) $(COMMON_LIBS) $(SAIMETA_LIBS)

if GCOV_ENABLED
vlanmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
teammgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
Expand All @@ -116,6 +121,7 @@ natmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
coppmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
tunnelmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
macsecmgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
poemgrd_SOURCES += ../gcovpreload/gcovpreload.cpp
endif

if ASAN_ENABLED
Expand All @@ -133,5 +139,6 @@ coppmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
tunnelmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
macsecmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
fabricmgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
poemgrd_SOURCES += $(top_srcdir)/lib/asan.cpp
endif

50 changes: 50 additions & 0 deletions cfgmgr/poemgr.cpp
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);
}
}
28 changes: 28 additions & 0 deletions cfgmgr/poemgr.h
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
70 changes: 70 additions & 0 deletions cfgmgr/poemgrd.cpp
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;
}
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ AC_CONFIG_FILES([
fpmsyncd/Makefile
neighsyncd/Makefile
gearsyncd/Makefile
poesyncd/Makefile
fdbsyncd/Makefile
natsyncd/Makefile
portsyncd/Makefile
Expand Down
Loading
Loading