Skip to content

configDB enforcer for interface #357

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

Merged
merged 7 commits into from
Nov 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -43,6 +43,7 @@ deps/
teamsyncd/teamsyncd
fpmsyncd/fpmsyncd
intfsyncd/intfsyncd
cfgagent/intfconfd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you rename to intfmgr?

The role of confd, orchagent, syncd are blurred, it is hard to have a clear cuts of different roles they are playing, so mgr can include all functions, which manages both asic and linux setup. therefore I prefer mgr name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will rename them to intfmgr and vlanmgr. For switch table level configuration, besides switchmgr process itself, the configuration may be used by multiple function modules like VLAN.

I plan to keep the class name of VlanConf, IntfConf and SwitchConf, let me know if you have other suggestions.

neighsyncd/neighsyncd
portsyncd/portsyncd
orchagent/orchagent
Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = fpmsyncd neighsyncd intfsyncd portsyncd orchagent swssconfig
SUBDIRS = fpmsyncd neighsyncd intfsyncd portsyncd orchagent swssconfig cfgagent

if HAVE_LIBTEAM
SUBDIRS += teamsyncd
Expand Down
17 changes: 17 additions & 0 deletions cfgagent/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent
CFLAGS_SAI = -I /usr/include/sai

bin_PROGRAMS = intfconfd

if DEBUG
DBGFLAGS = -ggdb -DDEBUG
else
DBGFLAGS = -g
endif


intfconfd_SOURCES = intfconfd.cpp intfconf.cpp $(top_srcdir)/orchagent/orchbase.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

orchbase [](start = 71, length = 8)

Is this file missing in the PR? Why not added it in the same directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in PR #360

intfconfd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
intfconfd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
intfconfd_LDADD = -lswsscommon

126 changes: 126 additions & 0 deletions cfgagent/intfconf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#include <string.h>
#include "logger.h"
#include "dbconnector.h"
#include "producerstatetable.h"
#include "tokenize.h"
#include "ipprefix.h"
#include "intfconf.h"
#include "exec.h"

using namespace std;
using namespace swss;

#define VLAN_PREFIX "Vlan"
#define LAG_PREFIX "PortChannel"

IntfConf::IntfConf(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, vector<string> tableNames) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as requested above, can you rename to IntfMgr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So process and binary name will be changed to VlanMgr/IntfMgr/SwitchMgr, you want to change the internal class name to xxxMgr too? IntfConfd/VlanConfd were chosen per the offline meeting discussion. Yes, class name may be changed.

OrchBase(cfgDb, tableNames),
m_cfgIntfTable(cfgDb, CFG_INTF_TABLE_NAME, CONFIGDB_TABLE_NAME_SEPARATOR),
m_cfgVlanIntfTable(cfgDb, CFG_VLAN_INTF_TABLE_NAME, CONFIGDB_TABLE_NAME_SEPARATOR),
m_statePortTable(stateDb, STATE_PORT_TABLE_NAME, CONFIGDB_TABLE_NAME_SEPARATOR),
m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME, CONFIGDB_TABLE_NAME_SEPARATOR),
m_stateVlanTable(stateDb, STATE_VLAN_TABLE_NAME, CONFIGDB_TABLE_NAME_SEPARATOR),
m_appIntfTableProducer(appDb, APP_INTF_TABLE_NAME)
{
}

void IntfConf::syncCfgDB()
{
OrchBase::syncDB(CFG_INTF_TABLE_NAME, m_cfgIntfTable);
OrchBase::syncDB(CFG_VLAN_INTF_TABLE_NAME, m_cfgVlanIntfTable);
}

bool IntfConf::setIntfIp(string &alias, string &opCmd, string &ipPrefixStr)
{
string cmd, res;

cmd = "ip address " + opCmd + " ";
cmd += ipPrefixStr + " dev " + alias;
swss::exec(cmd, res);
return true;
}

bool IntfConf::isIntfStateOk(string &alias)
{
vector<FieldValueTuple> temp;

if (!alias.compare(0, strlen(VLAN_PREFIX), VLAN_PREFIX))
{
if (m_stateVlanTable.get(alias, temp))
{
SWSS_LOG_DEBUG("Port %s is ready\n", alias.c_str());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vlan is ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will fix it.

return true;
}
}
else if (!alias.compare(0, strlen(LAG_PREFIX), LAG_PREFIX))
{
if (m_stateLagTable.get(alias, temp))
{
SWSS_LOG_DEBUG("Lag %s is ready\n", alias.c_str());
return true;
}
}
else if (m_statePortTable.get(alias, temp))
{
SWSS_LOG_DEBUG("Port %s is ready\n", alias.c_str());
return true;
}

return false;
}
void IntfConf::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;

string keySeparator = CONFIGDB_KEY_SEPARATOR;
vector<string> keys = tokenize(kfvKey(t), keySeparator[0]);
string alias(keys[0]);

if (alias.compare(0, strlen(VLAN_PREFIX), VLAN_PREFIX))
{
/* handle IP over vlan Only for now, skip the rest */
it = consumer.m_toSync.erase(it);
continue;
}

size_t pos = kfvKey(t).find(CONFIGDB_KEY_SEPARATOR);
if (pos == string::npos)
{
SWSS_LOG_DEBUG("Invalid key %s", kfvKey(t).c_str());
it = consumer.m_toSync.erase(it);
continue;
}
IpPrefix ip_prefix(kfvKey(t).substr(pos+1));

SWSS_LOG_DEBUG("intfs doTask: %s", (dumpTuple(consumer, t)).c_str());

string op = kfvOp(t);
if (op == SET_COMMAND)
{
/* Don't proceed if port/lag/VLAN is not ready yet */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add more comments here, retry. Later, we need to add subscriber for the state db to get notification when the port/lag/vlan is created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if (!isIntfStateOk(alias))
{
SWSS_LOG_DEBUG("Interface is not ready, skipping %s", kfvKey(t).c_str());
it++;
continue;
}
string opCmd("add");
string ipPrefixStr = ip_prefix.to_string();
setIntfIp(alias, opCmd, ipPrefixStr);
}
else if (op == DEL_COMMAND)
{
string opCmd("del");
string ipPrefixStr = ip_prefix.to_string();
setIntfIp(alias, opCmd, ipPrefixStr);
}

it = consumer.m_toSync.erase(it);
continue;
}
}
31 changes: 31 additions & 0 deletions cfgagent/intfconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef __INTFCONF__
#define __INTFCONF__

#include "dbconnector.h"
#include "producerstatetable.h"
#include "orchbase.h"

#include <map>
#include <string>

namespace swss {

class IntfConf : public OrchBase
{
public:
IntfConf(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, vector<string> tableNames);
void syncCfgDB();

private:
ProducerStateTable m_appIntfTableProducer;
Table m_cfgIntfTable, m_cfgVlanIntfTable;
Table m_statePortTable, m_stateLagTable, m_stateVlanTable;

bool setIntfIp(string &alias, string &opCmd, string &ipPrefixStr);
void doTask(Consumer &consumer);
bool isIntfStateOk(string &alias);
};

}

#endif
78 changes: 78 additions & 0 deletions cfgagent/intfconfd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include <unistd.h>
#include <vector>
#include "dbconnector.h"
#include "select.h"
#include "exec.h"
#include "schema.h"
#include "intfconf.h"

using namespace std;
using namespace swss;

/* select() function timeout retry time, in millisecond */
#define SELECT_TIMEOUT 1000

int main(int argc, char **argv)
{
Logger::linkToDbNative("intfconfd");
SWSS_LOG_ENTER();

SWSS_LOG_NOTICE("--- Starting intfconfd ---");

try
{
vector<string> cfg_intf_tables = {
CFG_INTF_TABLE_NAME,
CFG_LAG_INTF_TABLE_NAME,
CFG_VLAN_INTF_TABLE_NAME,
};

DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
DBConnector stateDb(STATE_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);

IntfConf intfconf(&cfgDb, &appDb, &stateDb, cfg_intf_tables);

// TODO: add tables in stateDB which interface depends on to monitor list
std::vector<OrchBase *> cfgOrchList = {&intfconf};

swss::Select s;
for (OrchBase *o : cfgOrchList)
{
s.addSelectables(o->getSelectables());
}

SWSS_LOG_NOTICE("starting main loop");
while (true)
{
Selectable *sel;
int fd, ret;

ret = s.select(&sel, &fd, SELECT_TIMEOUT);
if (ret == Select::ERROR)
{
SWSS_LOG_NOTICE("Error: %s!\n", strerror(errno));
continue;
}
if (ret == Select::TIMEOUT)
{
((OrchBase *)&intfconf)->doTask();
continue;
}

for (OrchBase *o : cfgOrchList)
{
TableConsumable *c = (TableConsumable *)sel;
if (o->hasSelectable(c))
{
o->execute(c->getTableName());
}
}
}
}
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 @@ -87,6 +87,7 @@ AC_CONFIG_FILES([
teamsyncd/Makefile
swssconfig/Makefile
tests/Makefile
cfgagent/Makefile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfgagent [](start = 4, length = 8)

cfgmgr

])

AC_OUTPUT