-
Notifications
You must be signed in to change notification settings - Fork 549
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
Sflow orchagent changes #1012
Sflow orchagent changes #1012
Changes from 1 commit
9974a14
1714af3
5d20b8e
0a784d8
d4a2b52
7674af7
d31ccd1
082232d
b34b48e
ef110c3
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,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); | ||
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. Do we need to stop |
||
} | ||
it = consumer.m_toSync.erase(it); | ||
} | ||
} | ||
|
||
void SflowMgr::doTask(Consumer &consumer) | ||
{ | ||
SWSS_LOG_ENTER(); | ||
|
||
auto table = consumer.getTableName(); | ||
|
||
if(table == CFG_SFLOW_TABLE_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. space after |
||
{ | ||
handleSflowTableConfig(consumer); | ||
return; | ||
} | ||
|
||
auto it = consumer.m_toSync.begin(); | ||
while (it != consumer.m_toSync.end()) | ||
prsunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
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); | ||
} | ||
} |
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; | ||
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. Why is this a Table?. It is |
||
ProducerStateTable m_appSflowTable; | ||
ProducerStateTable m_appSflowSessionTable; | ||
|
||
void doTask(Consumer &consumer); | ||
void handleSflowTableConfig(Consumer &consumer); | ||
}; | ||
|
||
} |
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; | ||
} |
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 you create a map with enum values. You can refer vxlanorch.cpp/crmorch.cpp.