-
Notifications
You must be signed in to change notification settings - Fork 580
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
Changes from 2 commits
3ed4cc8
7c7764c
ac1b6ba
416f4f4
16bfac1
c24f0c0
0b0b686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this file missing in the PR? Why not added it in the same directory? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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) : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as requested above, can you rename to IntfMgr There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vlan is ready. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
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 |
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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,7 @@ AC_CONFIG_FILES([ | |
teamsyncd/Makefile | ||
swssconfig/Makefile | ||
tests/Makefile | ||
cfgagent/Makefile | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
cfgmgr |
||
]) | ||
|
||
AC_OUTPUT |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.