-
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.
Mgr changes Mgr changes 2 Test cases Changing Global to global optimizations Reverting copp changes clean up UT Fixes Addressing code review comments Updating UT Build fix Adding mgr changes
- Loading branch information
dgsudharsan
committed
Aug 21, 2019
1 parent
dc81a21
commit 9974a14
Showing
11 changed files
with
1,313 additions
and
4 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,117 @@ | ||
#include "logger.h" | ||
#include "dbconnector.h" | ||
#include "producerstatetable.h" | ||
#include "tokenize.h" | ||
#include "ipprefix.h" | ||
#include "sflowmgr.h" | ||
#include "exec.h" | ||
#include "shellcmd.h" | ||
|
||
using namespace std; | ||
using namespace swss; | ||
|
||
SflowMgr::SflowMgr(DBConnector *cfgDb, DBConnector *appDb, const vector<string> &tableNames) : | ||
Orch(cfgDb, tableNames), | ||
m_cfgSflowTable(cfgDb, CFG_SFLOW_TABLE_NAME), | ||
m_cfgSflowSessionTable(cfgDb, CFG_SFLOW_SESSION_TABLE_NAME), | ||
m_appSflowTable(appDb, APP_SFLOW_TABLE_NAME), | ||
m_appSflowSessionTable(appDb, APP_SFLOW_SESSION_TABLE_NAME), | ||
m_appSflowSpeedRateTable(appDb, APP_SFLOW_SAMPLE_RATE_TABLE_NAME) | ||
{ | ||
vector<FieldValueTuple> fieldValues; | ||
|
||
fieldValues.emplace_back(SFLOW_SAMPLE_RATE_KEY_400G, SFLOW_SAMPLE_RATE_VALUE_400G); | ||
fieldValues.emplace_back(SFLOW_SAMPLE_RATE_KEY_100G, SFLOW_SAMPLE_RATE_VALUE_100G); | ||
fieldValues.emplace_back(SFLOW_SAMPLE_RATE_KEY_50G, SFLOW_SAMPLE_RATE_VALUE_50G); | ||
fieldValues.emplace_back(SFLOW_SAMPLE_RATE_KEY_40G, SFLOW_SAMPLE_RATE_VALUE_40G); | ||
fieldValues.emplace_back(SFLOW_SAMPLE_RATE_KEY_25G, SFLOW_SAMPLE_RATE_VALUE_25G); | ||
fieldValues.emplace_back(SFLOW_SAMPLE_RATE_KEY_10G, SFLOW_SAMPLE_RATE_VALUE_10G); | ||
fieldValues.emplace_back(SFLOW_SAMPLE_RATE_KEY_1G, SFLOW_SAMPLE_RATE_VALUE_1G); | ||
|
||
m_appSflowSpeedRateTable.set("global", fieldValues); | ||
} | ||
|
||
void SflowMgr::handleSflowTableConfig(Consumer &consumer) | ||
{ | ||
stringstream cmd; | ||
string res; | ||
|
||
auto it = consumer.m_toSync.begin(); | ||
|
||
while (it != consumer.m_toSync.end()) | ||
{ | ||
auto t = it->second; | ||
|
||
string key = kfvKey(t); | ||
string op = kfvOp(t); | ||
auto values = kfvFieldsValues(t); | ||
|
||
if (op == SET_COMMAND) | ||
{ | ||
for (auto i : kfvFieldsValues(t)) | ||
{ | ||
if (fvField(i) == "admin_state") | ||
{ | ||
if (fvValue(i) == "enable") | ||
{ | ||
cmd << "service hsflowd restart"; | ||
} | ||
else | ||
{ | ||
cmd << "service hsflowd stop"; | ||
} | ||
|
||
int ret = swss::exec(cmd.str(), res); | ||
if (ret) | ||
{ | ||
SWSS_LOG_ERROR("Command '%s' failed with rc %d", cmd.str().c_str(), ret); | ||
} | ||
else | ||
{ | ||
SWSS_LOG_INFO("Command '%s' succeeded", cmd.str().c_str()); | ||
} | ||
} | ||
} | ||
m_appSflowTable.set(key, values); | ||
} | ||
else if(op == DEL_COMMAND) | ||
{ | ||
m_appSflowTable.del(key); | ||
} | ||
it = consumer.m_toSync.erase(it); | ||
} | ||
} | ||
|
||
void SflowMgr::doTask(Consumer &consumer) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
auto table = consumer.getTableName(); | ||
|
||
if(table == CFG_SFLOW_TABLE_NAME) | ||
{ | ||
handleSflowTableConfig(consumer); | ||
return; | ||
} | ||
|
||
auto it = consumer.m_toSync.begin(); | ||
while (it != consumer.m_toSync.end()) | ||
{ | ||
KeyOpFieldsValuesTuple t = it->second; | ||
|
||
string key = kfvKey(t); | ||
string op = kfvOp(t); | ||
auto values = kfvFieldsValues(t); | ||
|
||
if (op == SET_COMMAND) | ||
{ | ||
m_appSflowSessionTable.set(key, values); | ||
} | ||
else if (op == DEL_COMMAND) | ||
{ | ||
m_appSflowSessionTable.del(key); | ||
} | ||
|
||
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,50 @@ | ||
#pragma once | ||
|
||
#include "dbconnector.h" | ||
#include "orch.h" | ||
#include "producerstatetable.h" | ||
|
||
#include <map> | ||
#include <set> | ||
#include <string> | ||
|
||
namespace swss { | ||
|
||
/* Port default admin status is down */ | ||
#define DEFAULT_ADMIN_STATUS_STR "down" | ||
#define DEFAULT_MTU_STR "9100" | ||
|
||
#define SFLOW_SAMPLE_RATE_KEY_400G "400000" | ||
#define SFLOW_SAMPLE_RATE_KEY_100G "100000" | ||
#define SFLOW_SAMPLE_RATE_KEY_50G "50000" | ||
#define SFLOW_SAMPLE_RATE_KEY_40G "40000" | ||
#define SFLOW_SAMPLE_RATE_KEY_25G "25000" | ||
#define SFLOW_SAMPLE_RATE_KEY_10G "10000" | ||
#define SFLOW_SAMPLE_RATE_KEY_1G "1000" | ||
|
||
#define SFLOW_SAMPLE_RATE_VALUE_400G "40000" | ||
#define SFLOW_SAMPLE_RATE_VALUE_100G "10000" | ||
#define SFLOW_SAMPLE_RATE_VALUE_50G "5000" | ||
#define SFLOW_SAMPLE_RATE_VALUE_40G "4000" | ||
#define SFLOW_SAMPLE_RATE_VALUE_25G "2500" | ||
#define SFLOW_SAMPLE_RATE_VALUE_10G "1000" | ||
#define SFLOW_SAMPLE_RATE_VALUE_1G "100" | ||
|
||
class SflowMgr : public Orch | ||
{ | ||
public: | ||
SflowMgr(DBConnector *cfgDb, DBConnector *appDb, const vector<string> &tableNames); | ||
|
||
using Orch::doTask; | ||
private: | ||
Table m_cfgSflowTable; | ||
Table m_cfgSflowSessionTable; | ||
Table m_appSflowSpeedRateTable; | ||
ProducerStateTable m_appSflowTable; | ||
ProducerStateTable m_appSflowSessionTable; | ||
|
||
void doTask(Consumer &consumer); | ||
void handleSflowTableConfig(Consumer &consumer); | ||
}; | ||
|
||
} |
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 <fstream> | ||
#include <iostream> | ||
#include <mutex> | ||
#include <unistd.h> | ||
#include <vector> | ||
|
||
#include "exec.h" | ||
#include "sflowmgr.h" | ||
#include "schema.h" | ||
#include "select.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("sflowmgrd"); | ||
SWSS_LOG_ENTER(); | ||
|
||
SWSS_LOG_NOTICE("--- Starting sflowmgrd ---"); | ||
|
||
try | ||
{ | ||
vector<string> cfg_sflow_tables = { | ||
CFG_SFLOW_TABLE_NAME, | ||
CFG_SFLOW_SESSION_TABLE_NAME | ||
}; | ||
|
||
DBConnector cfgDb(CONFIG_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); | ||
DBConnector appDb(APPL_DB, DBConnector::DEFAULT_UNIXSOCKET, 0); | ||
|
||
SflowMgr sflowmgr(&cfgDb, &appDb, cfg_sflow_tables); | ||
|
||
vector<Orch *> cfgOrchList = {&sflowmgr}; | ||
|
||
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) | ||
{ | ||
sflowmgr.doTask(); | ||
continue; | ||
} | ||
|
||
auto *c = (Executor *)sel; | ||
c->execute(); | ||
} | ||
} | ||
catch (const 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
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.