-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[portmgrd]: Add portmgrd to monitor port MTU configurations
In order to get rid of /etc/network/interfaces file and move all the configurations to the configuration database, MTU configurations are required to be put into the database and monitored by a specific daemon. This daemon portmgrd is to achieve this goal. Currently, this daemon will only listen to the port MTU configurations if existed in the database and then call the 'ip link' command to configure the kernel netdevs. It will also capture the admin status set in the configuration database and call the 'ip link' command to configure the kernel netdevs. The default MTUs, however, are set as the default value in the orchagent port.h file. The MTU value in the netlink message is anyway ignored. In the next stage, the change of the MTU will be supported so that the kernel host interface MTU will be reflected to the SAI port/router interface MTU. Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
- Loading branch information
Shu0T1an ChenG
committed
Aug 10, 2018
1 parent
d220a80
commit f4932ea
Showing
7 changed files
with
258 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include <string> | ||
#include "logger.h" | ||
#include "dbconnector.h" | ||
#include "producerstatetable.h" | ||
#include "tokenize.h" | ||
#include "ipprefix.h" | ||
#include "portmgr.h" | ||
#include "exec.h" | ||
#include "shellcmd.h" | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
||
PortMgr::PortMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames) : | ||
Orch(cfgDb, tableNames), | ||
m_cfgPortTable(cfgDb, CFG_PORT_TABLE_NAME), | ||
m_cfgLagTable(cfgDb, CFG_LAG_TABLE_NAME), | ||
m_statePortTable(stateDb, STATE_PORT_TABLE_NAME), | ||
m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME) | ||
{ | ||
} | ||
|
||
bool PortMgr::setPortMtu(const string &alias, const string &mtu) | ||
{ | ||
stringstream cmd; | ||
string res; | ||
|
||
cmd << IP_CMD << " link set dev " << alias << " mtu " << mtu; | ||
return exec(cmd.str(), res) == 0; | ||
} | ||
|
||
bool PortMgr::setPortAdminStatus(const string &alias, const bool up) | ||
{ | ||
stringstream cmd; | ||
string res; | ||
|
||
cmd << IP_CMD << " link set dev " << alias << (up ? " up" : " down"); | ||
return exec(cmd.str(), res) == 0; | ||
} | ||
|
||
bool PortMgr::isPortStateOk(const string &table, const string &alias) | ||
{ | ||
vector<FieldValueTuple> temp; | ||
|
||
if (table == CFG_PORT_TABLE_NAME) | ||
{ | ||
if (m_statePortTable.get(alias, temp)) | ||
{ | ||
SWSS_LOG_INFO("Port %s is ready", alias.c_str()); | ||
return true; | ||
} | ||
} | ||
else if (table == CFG_LAG_TABLE_NAME) | ||
{ | ||
if (m_stateLagTable.get(alias, temp)) | ||
{ | ||
SWSS_LOG_INFO("Lag %s is ready", alias.c_str()); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void PortMgr::doTask(Consumer &consumer) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
auto table = consumer.getTableName(); | ||
|
||
auto it = consumer.m_toSync.begin(); | ||
while (it != consumer.m_toSync.end()) | ||
{ | ||
KeyOpFieldsValuesTuple t = it->second; | ||
|
||
string alias = kfvKey(t); | ||
string op = kfvOp(t); | ||
|
||
if (op == SET_COMMAND) | ||
{ | ||
if (!isPortStateOk(table, alias)) | ||
{ | ||
SWSS_LOG_INFO("Port %s is not ready, pending", alias.c_str()); | ||
it++; | ||
continue; | ||
} | ||
|
||
for (auto i : kfvFieldsValues(t)) | ||
{ | ||
if (fvField(i) == "mtu") | ||
{ | ||
auto mtu = fvValue(i); | ||
setPortMtu(alias, mtu); | ||
SWSS_LOG_NOTICE("Configure %s MTU to %s", | ||
alias.c_str(), mtu.c_str()); | ||
} | ||
else if (fvField(i) == "admin_status") | ||
{ | ||
auto status = fvValue(i); | ||
setPortAdminStatus(alias, status == "up"); | ||
SWSS_LOG_NOTICE("Configure %s %s", | ||
alias.c_str(), status.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,33 @@ | ||
#ifndef __INTFMGR__ | ||
#define __INTFMGR__ | ||
|
||
#include "dbconnector.h" | ||
#include "producerstatetable.h" | ||
#include "orch.h" | ||
|
||
#include <map> | ||
#include <string> | ||
|
||
namespace swss { | ||
|
||
class PortMgr : public Orch | ||
{ | ||
public: | ||
PortMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames); | ||
using Orch::doTask; | ||
|
||
private: | ||
Table m_cfgPortTable; | ||
Table m_cfgLagTable; | ||
Table m_statePortTable; | ||
Table m_stateLagTable; | ||
|
||
void doTask(Consumer &consumer); | ||
bool setPortMtu(const string &alias, const string &mtu); | ||
bool setPortAdminStatus(const string &alias, const bool up); | ||
bool isPortStateOk(const string &table, const string &alias); | ||
}; | ||
|
||
} | ||
|
||
#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,89 @@ | ||
#include <unistd.h> | ||
#include <vector> | ||
#include <mutex> | ||
#include "dbconnector.h" | ||
#include "select.h" | ||
#include "exec.h" | ||
#include "schema.h" | ||
#include "portmgr.h" | ||
#include <fstream> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
||
/* select() function timeout retry time, in millisecond */ | ||
#define SELECT_TIMEOUT 1000 | ||
|
||
/* | ||
* Following global variables are defined here for the purpose of | ||
* using existing Orch class which is to be refactored soon to | ||
* eliminate the direct exposure of the global variables. | ||
* | ||
* Once Orch class refactoring is done, these global variables | ||
* should be removed from here. | ||
*/ | ||
int gBatchSize = 0; | ||
bool gSwssRecord = false; | ||
bool gLogRotate = false; | ||
ofstream gRecordOfs; | ||
string gRecordFile; | ||
/* Global database mutex */ | ||
mutex gDbMutex; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
Logger::linkToDbNative("portmgrd"); | ||
SWSS_LOG_ENTER(); | ||
|
||
SWSS_LOG_NOTICE("--- Starting portmgrd ---"); | ||
|
||
try | ||
{ | ||
vector<string> cfg_port_tables = { | ||
CFG_PORT_TABLE_NAME, | ||
CFG_LAG_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); | ||
|
||
PortMgr portmgr(&cfgDb, &appDb, &stateDb, cfg_port_tables); | ||
|
||
// TODO: add tables in stateDB which interface depends on to monitor list | ||
std::vector<Orch *> cfgOrchList = {&portmgr}; | ||
|
||
swss::Select s; | ||
for (Orch *o : cfgOrchList) | ||
{ | ||
s.addSelectables(o->getSelectables()); | ||
} | ||
|
||
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) | ||
{ | ||
portmgr.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
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