-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
19 changed files
with
2,126 additions
and
74 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,87 @@ | ||
#include <algorithm> | ||
#include <regex> | ||
#include <sstream> | ||
#include <string> | ||
#include <net/if.h> | ||
|
||
#include "logger.h" | ||
#include "tunnelmgr.h" | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
||
TunnelMgr::TunnelMgr(DBConnector *cfgDb, DBConnector *appDb, std::string tableName) : | ||
Orch(cfgDb, tableName), | ||
m_appIpInIpTunnelTable(appDb, APP_TUNNEL_DECAP_TABLE_NAME) | ||
{ | ||
} | ||
|
||
void TunnelMgr::doTask(Consumer &consumer) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
auto it = consumer.m_toSync.begin(); | ||
while (it != consumer.m_toSync.end()) | ||
{ | ||
bool task_result = false; | ||
|
||
KeyOpFieldsValuesTuple t = it->second; | ||
const vector<FieldValueTuple>& data = kfvFieldsValues(t); | ||
|
||
const std::string & op = kfvOp(t); | ||
|
||
if (op == SET_COMMAND) | ||
{ | ||
for (auto idx : data) | ||
{ | ||
const auto &field = fvField(idx); | ||
const auto &value = fvValue(idx); | ||
if (field == "tunnel_type") | ||
{ | ||
if (value == "IPINIP") | ||
{ | ||
task_result = doIpInIpTunnelTask(t); | ||
} | ||
} | ||
} | ||
} | ||
else if (op == DEL_COMMAND) | ||
{ | ||
/* TODO: Handle Tunnel delete for other tunnel types */ | ||
task_result = doIpInIpTunnelTask(t); | ||
} | ||
else | ||
{ | ||
SWSS_LOG_ERROR("Unknown operation: '%s'", op.c_str()); | ||
} | ||
|
||
if (task_result == true) | ||
{ | ||
it = consumer.m_toSync.erase(it); | ||
} | ||
else | ||
{ | ||
++it; | ||
} | ||
} | ||
} | ||
|
||
bool TunnelMgr::doIpInIpTunnelTask(const KeyOpFieldsValuesTuple & t) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
const std::string & TunnelName = kfvKey(t); | ||
const std::string & op = kfvOp(t); | ||
|
||
if (op == SET_COMMAND) | ||
{ | ||
m_appIpInIpTunnelTable.set(TunnelName, kfvFieldsValues(t)); | ||
} | ||
else | ||
{ | ||
m_appIpInIpTunnelTable.del(TunnelName); | ||
} | ||
|
||
SWSS_LOG_NOTICE("Tunnel %s task, op %s", TunnelName.c_str(), op.c_str()); | ||
return true; | ||
} |
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,23 @@ | ||
#pragma once | ||
|
||
#include "dbconnector.h" | ||
#include "producerstatetable.h" | ||
#include "orch.h" | ||
|
||
namespace swss { | ||
|
||
class TunnelMgr : public Orch | ||
{ | ||
public: | ||
TunnelMgr(DBConnector *cfgDb, DBConnector *appDb, std::string tableName); | ||
using Orch::doTask; | ||
|
||
private: | ||
void doTask(Consumer &consumer); | ||
|
||
bool doIpInIpTunnelTask(const KeyOpFieldsValuesTuple & t); | ||
|
||
ProducerStateTable m_appIpInIpTunnelTable; | ||
}; | ||
|
||
} |
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,86 @@ | ||
#include <unistd.h> | ||
#include <vector> | ||
#include <sstream> | ||
#include <fstream> | ||
#include <iostream> | ||
#include <mutex> | ||
#include <algorithm> | ||
|
||
#include "dbconnector.h" | ||
#include "select.h" | ||
#include "exec.h" | ||
#include "schema.h" | ||
#include "tunnelmgr.h" | ||
|
||
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("tunnelmgrd"); | ||
|
||
SWSS_LOG_NOTICE("--- Starting Tunnelmgrd ---"); | ||
|
||
try | ||
{ | ||
|
||
DBConnector cfgDb("CONFIG_DB", 0); | ||
DBConnector appDb("APPL_DB", 0); | ||
|
||
TunnelMgr tunnelmgr(&cfgDb, &appDb, CFG_TUNNEL_TABLE_NAME); | ||
|
||
std::vector<Orch *> cfgOrchList = {&tunnelmgr}; | ||
|
||
swss::Select s; | ||
for (Orch *o : cfgOrchList) | ||
{ | ||
s.addSelectables(o->getSelectables()); | ||
} | ||
|
||
SWSS_LOG_NOTICE("starting main loop"); | ||
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) | ||
{ | ||
tunnelmgr.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
Oops, something went wrong.