-
Notifications
You must be signed in to change notification settings - Fork 522
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
Mux/IPTunnel orchagent changes #1497
Changes from 9 commits
59c2df0
0dc07ef
7b527fd
6ff07ac
6d545df
4fa72c4
0390536
fd20f0e
3adbe90
5b21dfa
cb52c21
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,88 @@ | ||
#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)); | ||
|
||
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. nit: extra line |
||
} | ||
else | ||
{ | ||
m_appIpInIpTunnelTable.del(TunnelName); | ||
} | ||
|
||
SWSS_LOG_NOTICE("Tunnel %s task, op %s", TunnelName.c_str(), op.c_str()); | ||
return true; | ||
} |
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); | ||
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. What about explicitly deleting the default and copy constructor. Also, calling destructor as default |
||
using Orch::doTask; | ||
|
||
private: | ||
void doTask(Consumer &consumer); | ||
|
||
bool doIpInIpTunnelTask(const KeyOpFieldsValuesTuple & t); | ||
|
||
ProducerStateTable m_appIpInIpTunnelTable; | ||
}; | ||
|
||
} |
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 | ||
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. What about the time unit to the name 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. This is the default value for all mgrs, keeping it for consistency |
||
|
||
/* | ||
* 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}; | ||
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. curious nit: style mismatch 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. Addressed |
||
|
||
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)); | ||
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. Any reason not to use SWSS_LOG_ERROR instead of NOTICE here for the error handling? 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. Same for all managers, keeping for consistency |
||
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; | ||
} |
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 we add a check for value == "IPINIP" before calling doIpInIpTunnelTask(t)? This way it is in parity with how the "SET_COMMAND" is handled that do check for the tunnel type.
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.
In the del operation we will not get the value