Skip to content

Commit 2115a99

Browse files
Shuotian Chenglguohan
Shuotian Cheng
authored andcommitted
[teammgrd]: Add teammgrd to manage LAG related configurations (sonic-net#626)
teammgrd will monitor configuration changes in CFG_LAG_TABLE_NAME and CFG_LAG_MEMBER_TABLE_NAME. It supports creation/removal of LAGs as well as membership changes of the LAG members. Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent e1cc0de commit 2115a99

12 files changed

+691
-103
lines changed

cfgmgr/Makefile.am

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
INCLUDES = -I $(top_srcdir) -I $(top_srcdir)/orchagent -I $(top_srcdir)/warmrestart
22
CFLAGS_SAI = -I /usr/include/sai
33

4-
bin_PROGRAMS = vlanmgrd portmgrd intfmgrd buffermgrd vrfmgrd
4+
bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd
55

66
if DEBUG
77
DBGFLAGS = -ggdb -DDEBUG
@@ -15,6 +15,12 @@ vlanmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
1515
vlanmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
1616
vlanmgrd_LDADD = -lswsscommon
1717

18+
teammgrd_SOURCES = teammgrd.cpp teammgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp \
19+
shellcmd.h $(top_srcdir)/warmrestart/warm_restart.cpp $(top_srcdir)/warmrestart/warm_restart.h
20+
teammgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
21+
teammgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
22+
teammgrd_LDADD = -lswsscommon
23+
1824
portmgrd_SOURCES = portmgrd.cpp portmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp shellcmd.h
1925
portmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
2026
portmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)

cfgmgr/portmgr.cpp

+38-59
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <string>
2-
31
#include "logger.h"
42
#include "dbconnector.h"
53
#include "producerstatetable.h"
@@ -15,57 +13,27 @@ using namespace swss;
1513
PortMgr::PortMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames) :
1614
Orch(cfgDb, tableNames),
1715
m_cfgPortTable(cfgDb, CFG_PORT_TABLE_NAME),
18-
m_cfgLagTable(cfgDb, CFG_LAG_TABLE_NAME),
16+
m_cfgLagMemberTable(cfgDb, CFG_LAG_MEMBER_TABLE_NAME),
1917
m_statePortTable(stateDb, STATE_PORT_TABLE_NAME),
20-
m_stateLagTable(stateDb, STATE_LAG_TABLE_NAME),
21-
m_appPortTable(appDb, APP_PORT_TABLE_NAME),
22-
m_appLagTable(appDb, APP_LAG_TABLE_NAME)
18+
m_appPortTable(appDb, APP_PORT_TABLE_NAME)
2319
{
2420
}
2521

26-
bool PortMgr::setPortMtu(const string &table, const string &alias, const string &mtu)
22+
bool PortMgr::setPortMtu(const string &alias, const string &mtu)
2723
{
2824
stringstream cmd;
2925
string res;
3026

27+
// ip link set dev <port_name> mtu <mtu>
3128
cmd << IP_CMD << " link set dev " << alias << " mtu " << mtu;
3229
EXEC_WITH_ERROR_THROW(cmd.str(), res);
3330

34-
if (table == CFG_PORT_TABLE_NAME)
35-
{
36-
// Set the port MTU in application database to update both
37-
// the port MTU and possibly the port based router interface MTU
38-
vector<FieldValueTuple> fvs;
39-
FieldValueTuple fv("mtu", mtu);
40-
fvs.push_back(fv);
41-
m_appPortTable.set(alias, fvs);
42-
}
43-
else if (table == CFG_LAG_TABLE_NAME)
44-
{
45-
// Set the port channel MTU in application database to update
46-
// the LAG based router interface MTU in orchagent
47-
vector<FieldValueTuple> fvs;
48-
FieldValueTuple fv("mtu", mtu);
49-
fvs.push_back(fv);
50-
m_appLagTable.set(alias, fvs);
51-
52-
m_cfgLagTable.get(alias, fvs);
53-
for (auto fv: fvs)
54-
{
55-
// Set the port channel members MTU in application database
56-
// to update the port MTU in orchagent
57-
if (fvField(fv) == "members")
58-
{
59-
for (auto member : tokenize(fvValue(fv), ','))
60-
{
61-
vector<FieldValueTuple> member_fvs;
62-
FieldValueTuple member_fv("mtu", mtu);
63-
member_fvs.push_back(member_fv);
64-
m_appPortTable.set(member, member_fvs);
65-
}
66-
}
67-
}
68-
}
31+
// Set the port MTU in application database to update both
32+
// the port MTU and possibly the port based router interface MTU
33+
vector<FieldValueTuple> fvs;
34+
FieldValueTuple fv("mtu", mtu);
35+
fvs.push_back(fv);
36+
m_appPortTable.set(alias, fvs);
6937

7038
return true;
7139
}
@@ -75,31 +43,26 @@ bool PortMgr::setPortAdminStatus(const string &alias, const bool up)
7543
stringstream cmd;
7644
string res;
7745

46+
// ip link set dev <port_name> [up|down]
7847
cmd << IP_CMD << " link set dev " << alias << (up ? " up" : " down");
7948
EXEC_WITH_ERROR_THROW(cmd.str(), res);
8049

50+
vector<FieldValueTuple> fvs;
51+
FieldValueTuple fv("admin_status", (up ? "up" : "down"));
52+
fvs.push_back(fv);
53+
m_appPortTable.set(alias, fvs);
54+
8155
return true;
8256
}
8357

84-
bool PortMgr::isPortStateOk(const string &table, const string &alias)
58+
bool PortMgr::isPortStateOk(const string &alias)
8559
{
8660
vector<FieldValueTuple> temp;
8761

88-
if (table == CFG_PORT_TABLE_NAME)
89-
{
90-
if (m_statePortTable.get(alias, temp))
91-
{
92-
SWSS_LOG_INFO("Port %s is ready", alias.c_str());
93-
return true;
94-
}
95-
}
96-
else if (table == CFG_LAG_TABLE_NAME)
62+
if (m_statePortTable.get(alias, temp))
9763
{
98-
if (m_stateLagTable.get(alias, temp))
99-
{
100-
SWSS_LOG_INFO("Lag %s is ready", alias.c_str());
101-
return true;
102-
}
64+
SWSS_LOG_INFO("Port %s is ready", alias.c_str());
65+
return true;
10366
}
10467

10568
return false;
@@ -119,9 +82,25 @@ void PortMgr::doTask(Consumer &consumer)
11982
string alias = kfvKey(t);
12083
string op = kfvOp(t);
12184

85+
// Skip port which is a member of a port channel
86+
vector<string> keys;
87+
m_cfgLagMemberTable.getKeys(keys);
88+
89+
for (auto key : keys)
90+
{
91+
auto tokens = tokenize(key, '|');
92+
auto member = tokens[1];
93+
94+
if (alias == member)
95+
{
96+
it = consumer.m_toSync.erase(it);
97+
continue;
98+
}
99+
}
100+
122101
if (op == SET_COMMAND)
123102
{
124-
if (!isPortStateOk(table, alias))
103+
if (!isPortStateOk(alias))
125104
{
126105
SWSS_LOG_INFO("Port %s is not ready, pending...", alias.c_str());
127106
it++;
@@ -133,7 +112,7 @@ void PortMgr::doTask(Consumer &consumer)
133112
if (fvField(i) == "mtu")
134113
{
135114
auto mtu = fvValue(i);
136-
setPortMtu(table, alias, mtu);
115+
setPortMtu(alias, mtu);
137116
SWSS_LOG_NOTICE("Configure %s MTU to %s",
138117
alias.c_str(), mtu.c_str());
139118
}

cfgmgr/portmgr.h

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#ifndef __INTFMGR__
2-
#define __INTFMGR__
1+
#pragma once
32

43
#include "dbconnector.h"
5-
#include "producerstatetable.h"
64
#include "orch.h"
5+
#include "producerstatetable.h"
76

87
#include <map>
8+
#include <set>
99
#include <string>
1010

1111
namespace swss {
@@ -14,22 +14,18 @@ class PortMgr : public Orch
1414
{
1515
public:
1616
PortMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, const vector<string> &tableNames);
17-
using Orch::doTask;
1817

18+
using Orch::doTask;
1919
private:
2020
Table m_cfgPortTable;
21-
Table m_cfgLagTable;
21+
Table m_cfgLagMemberTable;
2222
Table m_statePortTable;
23-
Table m_stateLagTable;
2423
ProducerStateTable m_appPortTable;
25-
ProducerStateTable m_appLagTable;
2624

2725
void doTask(Consumer &consumer);
28-
bool setPortMtu(const string &table, const string &alias, const string &mtu);
26+
bool setPortMtu(const string &alias, const string &mtu);
2927
bool setPortAdminStatus(const string &alias, const bool up);
30-
bool isPortStateOk(const string &table, const string &alias);
28+
bool isPortStateOk(const string &alias);
3129
};
3230

3331
}
34-
35-
#endif

cfgmgr/portmgrd.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
#include <fstream>
2+
#include <iostream>
3+
#include <mutex>
14
#include <unistd.h>
25
#include <vector>
3-
#include <mutex>
4-
#include "dbconnector.h"
5-
#include "select.h"
6+
67
#include "exec.h"
7-
#include "schema.h"
88
#include "portmgr.h"
9-
#include <fstream>
10-
#include <iostream>
9+
#include "schema.h"
10+
#include "select.h"
1111

1212
using namespace std;
1313
using namespace swss;
@@ -42,7 +42,6 @@ int main(int argc, char **argv)
4242
{
4343
vector<string> cfg_port_tables = {
4444
CFG_PORT_TABLE_NAME,
45-
CFG_LAG_TABLE_NAME,
4645
};
4746

4847
DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0);
@@ -52,7 +51,7 @@ int main(int argc, char **argv)
5251
PortMgr portmgr(&cfgDb, &appDb, &stateDb, cfg_port_tables);
5352

5453
// TODO: add tables in stateDB which interface depends on to monitor list
55-
std::vector<Orch *> cfgOrchList = {&portmgr};
54+
vector<Orch *> cfgOrchList = {&portmgr};
5655

5756
swss::Select s;
5857
for (Orch *o : cfgOrchList)
@@ -81,7 +80,7 @@ int main(int argc, char **argv)
8180
c->execute();
8281
}
8382
}
84-
catch(const std::exception &e)
83+
catch (const exception &e)
8584
{
8685
SWSS_LOG_ERROR("Runtime error: %s", e.what());
8786
}

cfgmgr/shellcmd.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define ECHO_CMD "/bin/echo"
77
#define BASH_CMD "/bin/bash"
88
#define GREP_CMD "/bin/grep"
9+
#define TEAMD_CMD "/usr/bin/teamd"
10+
#define TEAMDCTL_CMD "/usr/bin/teamdctl"
911

1012
#define EXEC_WITH_ERROR_THROW(cmd, res) ({ \
1113
int ret = swss::exec(cmd, res); \

0 commit comments

Comments
 (0)