Skip to content

Commit c39a4b1

Browse files
authored
Mux/IPTunnel orchagent changes (#1497)
Introduce TunnelMgr Daemon and Mux orchagent Added support to enable/disable neighbors via NeighOrch Added support to create/remove nexthop tunnels Added support for ACL handling for Mux state
1 parent bc8df0e commit c39a4b1

19 files changed

+2126
-74
lines changed

cfgmgr/Makefile.am

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CFLAGS_SAI = -I /usr/include/sai
33
LIBNL_CFLAGS = -I/usr/include/libnl3
44
LIBNL_LIBS = -lnl-genl-3 -lnl-route-3 -lnl-3
55

6-
bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd coppmgrd
6+
bin_PROGRAMS = vlanmgrd teammgrd portmgrd intfmgrd buffermgrd vrfmgrd nbrmgrd vxlanmgrd sflowmgrd natmgrd coppmgrd tunnelmgrd
77

88
cfgmgrdir = $(datadir)/swss
99

@@ -76,3 +76,8 @@ coppmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
7676
coppmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
7777
coppmgrd_LDADD = -lswsscommon
7878

79+
tunnelmgrd_SOURCES = tunnelmgrd.cpp tunnelmgr.cpp $(top_srcdir)/orchagent/orch.cpp $(top_srcdir)/orchagent/request_parser.cpp shellcmd.h
80+
tunnelmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
81+
tunnelmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
82+
tunnelmgrd_LDADD = -lswsscommon
83+

cfgmgr/tunnelmgr.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include <algorithm>
2+
#include <regex>
3+
#include <sstream>
4+
#include <string>
5+
#include <net/if.h>
6+
7+
#include "logger.h"
8+
#include "tunnelmgr.h"
9+
10+
using namespace std;
11+
using namespace swss;
12+
13+
TunnelMgr::TunnelMgr(DBConnector *cfgDb, DBConnector *appDb, std::string tableName) :
14+
Orch(cfgDb, tableName),
15+
m_appIpInIpTunnelTable(appDb, APP_TUNNEL_DECAP_TABLE_NAME)
16+
{
17+
}
18+
19+
void TunnelMgr::doTask(Consumer &consumer)
20+
{
21+
SWSS_LOG_ENTER();
22+
23+
auto it = consumer.m_toSync.begin();
24+
while (it != consumer.m_toSync.end())
25+
{
26+
bool task_result = false;
27+
28+
KeyOpFieldsValuesTuple t = it->second;
29+
const vector<FieldValueTuple>& data = kfvFieldsValues(t);
30+
31+
const std::string & op = kfvOp(t);
32+
33+
if (op == SET_COMMAND)
34+
{
35+
for (auto idx : data)
36+
{
37+
const auto &field = fvField(idx);
38+
const auto &value = fvValue(idx);
39+
if (field == "tunnel_type")
40+
{
41+
if (value == "IPINIP")
42+
{
43+
task_result = doIpInIpTunnelTask(t);
44+
}
45+
}
46+
}
47+
}
48+
else if (op == DEL_COMMAND)
49+
{
50+
/* TODO: Handle Tunnel delete for other tunnel types */
51+
task_result = doIpInIpTunnelTask(t);
52+
}
53+
else
54+
{
55+
SWSS_LOG_ERROR("Unknown operation: '%s'", op.c_str());
56+
}
57+
58+
if (task_result == true)
59+
{
60+
it = consumer.m_toSync.erase(it);
61+
}
62+
else
63+
{
64+
++it;
65+
}
66+
}
67+
}
68+
69+
bool TunnelMgr::doIpInIpTunnelTask(const KeyOpFieldsValuesTuple & t)
70+
{
71+
SWSS_LOG_ENTER();
72+
73+
const std::string & TunnelName = kfvKey(t);
74+
const std::string & op = kfvOp(t);
75+
76+
if (op == SET_COMMAND)
77+
{
78+
m_appIpInIpTunnelTable.set(TunnelName, kfvFieldsValues(t));
79+
}
80+
else
81+
{
82+
m_appIpInIpTunnelTable.del(TunnelName);
83+
}
84+
85+
SWSS_LOG_NOTICE("Tunnel %s task, op %s", TunnelName.c_str(), op.c_str());
86+
return true;
87+
}

cfgmgr/tunnelmgr.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include "dbconnector.h"
4+
#include "producerstatetable.h"
5+
#include "orch.h"
6+
7+
namespace swss {
8+
9+
class TunnelMgr : public Orch
10+
{
11+
public:
12+
TunnelMgr(DBConnector *cfgDb, DBConnector *appDb, std::string tableName);
13+
using Orch::doTask;
14+
15+
private:
16+
void doTask(Consumer &consumer);
17+
18+
bool doIpInIpTunnelTask(const KeyOpFieldsValuesTuple & t);
19+
20+
ProducerStateTable m_appIpInIpTunnelTable;
21+
};
22+
23+
}

cfgmgr/tunnelmgrd.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include <unistd.h>
2+
#include <vector>
3+
#include <sstream>
4+
#include <fstream>
5+
#include <iostream>
6+
#include <mutex>
7+
#include <algorithm>
8+
9+
#include "dbconnector.h"
10+
#include "select.h"
11+
#include "exec.h"
12+
#include "schema.h"
13+
#include "tunnelmgr.h"
14+
15+
using namespace std;
16+
using namespace swss;
17+
18+
/* select() function timeout retry time, in millisecond */
19+
#define SELECT_TIMEOUT 1000
20+
21+
/*
22+
* Following global variables are defined here for the purpose of
23+
* using existing Orch class which is to be refactored soon to
24+
* eliminate the direct exposure of the global variables.
25+
*
26+
* Once Orch class refactoring is done, these global variables
27+
* should be removed from here.
28+
*/
29+
int gBatchSize = 0;
30+
bool gSwssRecord = false;
31+
bool gLogRotate = false;
32+
ofstream gRecordOfs;
33+
string gRecordFile;
34+
/* Global database mutex */
35+
mutex gDbMutex;
36+
37+
int main(int argc, char **argv)
38+
{
39+
Logger::linkToDbNative("tunnelmgrd");
40+
41+
SWSS_LOG_NOTICE("--- Starting Tunnelmgrd ---");
42+
43+
try
44+
{
45+
46+
DBConnector cfgDb("CONFIG_DB", 0);
47+
DBConnector appDb("APPL_DB", 0);
48+
49+
TunnelMgr tunnelmgr(&cfgDb, &appDb, CFG_TUNNEL_TABLE_NAME);
50+
51+
std::vector<Orch *> cfgOrchList = {&tunnelmgr};
52+
53+
swss::Select s;
54+
for (Orch *o : cfgOrchList)
55+
{
56+
s.addSelectables(o->getSelectables());
57+
}
58+
59+
SWSS_LOG_NOTICE("starting main loop");
60+
while (true)
61+
{
62+
Selectable *sel;
63+
int ret;
64+
65+
ret = s.select(&sel, SELECT_TIMEOUT);
66+
if (ret == Select::ERROR)
67+
{
68+
SWSS_LOG_NOTICE("Error: %s!", strerror(errno));
69+
continue;
70+
}
71+
if (ret == Select::TIMEOUT)
72+
{
73+
tunnelmgr.doTask();
74+
continue;
75+
}
76+
77+
auto *c = (Executor *)sel;
78+
c->execute();
79+
}
80+
}
81+
catch(const std::exception &e)
82+
{
83+
SWSS_LOG_ERROR("Runtime error: %s", e.what());
84+
}
85+
return -1;
86+
}

orchagent/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ orchagent_SOURCES = \
6060
sfloworch.cpp \
6161
chassisorch.cpp \
6262
debugcounterorch.cpp \
63-
natorch.cpp
63+
natorch.cpp \
64+
muxorch.cpp
6465

6566
orchagent_SOURCES += flex_counter/flex_counter_manager.cpp flex_counter/flex_counter_stat_manager.cpp
6667
orchagent_SOURCES += debug_counter/debug_counter.cpp debug_counter/drop_counter.cpp

orchagent/aclorch.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,16 @@ bool AclRulePfcwd::validateAddMatch(string attr_name, string attr_value)
10141014
return AclRule::validateAddMatch(attr_name, attr_value);
10151015
}
10161016

1017+
AclRuleMux::AclRuleMux(AclOrch *aclOrch, string rule, string table, acl_table_type_t type, bool createCounter) :
1018+
AclRuleL3(aclOrch, rule, table, type, createCounter)
1019+
{
1020+
}
1021+
1022+
bool AclRuleMux::validateAddMatch(string attr_name, string attr_value)
1023+
{
1024+
return AclRule::validateAddMatch(attr_name, attr_value);
1025+
}
1026+
10171027
AclRuleL3V6::AclRuleL3V6(AclOrch *aclOrch, string rule, string table, acl_table_type_t type) :
10181028
AclRuleL3(aclOrch, rule, table, type)
10191029
{

orchagent/aclorch.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define TABLE_TYPE_DTEL_FLOW_WATCHLIST "DTEL_FLOW_WATCHLIST"
3636
#define TABLE_TYPE_DTEL_DROP_WATCHLIST "DTEL_DROP_WATCHLIST"
3737
#define TABLE_TYPE_MCLAG "MCLAG"
38+
#define TABLE_TYPE_MUX "MUX"
3839

3940
#define RULE_PRIORITY "PRIORITY"
4041
#define MATCH_IN_PORTS "IN_PORTS"
@@ -115,7 +116,8 @@ typedef enum
115116
ACL_TABLE_CTRLPLANE,
116117
ACL_TABLE_DTEL_FLOW_WATCHLIST,
117118
ACL_TABLE_DTEL_DROP_WATCHLIST,
118-
ACL_TABLE_MCLAG
119+
ACL_TABLE_MCLAG,
120+
ACL_TABLE_MUX
119121
} acl_table_type_t;
120122

121123
typedef map<string, acl_table_type_t> acl_table_type_lookup_t;
@@ -272,6 +274,12 @@ class AclRulePfcwd: public AclRuleL3
272274
bool validateAddMatch(string attr_name, string attr_value);
273275
};
274276

277+
class AclRuleMux: public AclRuleL3
278+
{
279+
public:
280+
AclRuleMux(AclOrch *m_pAclOrch, string rule, string table, acl_table_type_t type, bool createCounter = false);
281+
bool validateAddMatch(string attr_name, string attr_value);
282+
};
275283

276284
class AclRuleMirror: public AclRule
277285
{

0 commit comments

Comments
 (0)