Skip to content

Commit

Permalink
[flexcounter]: add support to change port/queue counter poll interval (
Browse files Browse the repository at this point in the history
…sonic-net#499)

Signed-off-by: Sihui Han <sihan@microsoft.com>
  • Loading branch information
sihuihan88 committed May 18, 2018
1 parent 8d810be commit 8c23538
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 3 deletions.
4 changes: 3 additions & 1 deletion orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ orchagent_SOURCES = \
request_parser.cpp \
vrforch.cpp \
countercheckorch.cpp \
flexcounterorch.cpp\
acltable.h \
aclorch.h \
bufferorch.h \
Expand All @@ -66,7 +67,8 @@ orchagent_SOURCES = \
crmorch.h
request_parser.h \
vrforch.h \
countercheckorch.h
countercheckorch.h \
flexcounterorch.h

orchagent_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
orchagent_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_SAI)
Expand Down
76 changes: 76 additions & 0 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <unordered_map>
#include "flexcounterorch.h"
#include "portsorch.h"
#include "select.h"
#include "notifier.h"
#include "redisclient.h"
#include "sai_serialize.h"

extern sai_port_api_t *sai_port_api;

extern PortsOrch *gPortsOrch;

unordered_map<string, string> flexCounterGroupMap =
{
{"PORT", PORT_STAT_COUNTER_FLEX_COUNTER_GROUP},
{"QUEUE", QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP},
};

FlexCounterOrch::FlexCounterOrch(DBConnector *db, vector<string> &tableNames):
Orch(db, tableNames),
m_flexCounterDb(new DBConnector(FLEX_COUNTER_DB, DBConnector::DEFAULT_UNIXSOCKET, 0)),
m_flexCounterGroupTable(new ProducerTable(m_flexCounterDb.get(), FLEX_COUNTER_GROUP_TABLE))
{
SWSS_LOG_ENTER();
}

FlexCounterOrch::~FlexCounterOrch(void)
{
SWSS_LOG_ENTER();
}

void FlexCounterOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();

if (!gPortsOrch->isInitDone())
{
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 data = kfvFieldsValues(t);

if (!flexCounterGroupMap.count(key))
{
SWSS_LOG_NOTICE("Invalid flex counter group input, %s", key.c_str());
consumer.m_toSync.erase(it++);
continue;
}

if (op == SET_COMMAND)
{
for (auto valuePair:data)
{
const auto &field = fvField(valuePair);
const auto &value = fvValue(valuePair);

if (field == POLL_INTERVAL_FIELD)
{
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(POLL_INTERVAL_FIELD, value);
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
}
/* In future add the support to disable/enable counter query here.*/
}
}

consumer.m_toSync.erase(it++);
}
}
24 changes: 24 additions & 0 deletions orchagent/flexcounterorch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef FLEXCOUNTER_ORCH_H
#define FLEXCOUNTER_ORCH_H

#include "orch.h"
#include "port.h"
#include "producertable.h"

extern "C" {
#include "sai.h"
}

class FlexCounterOrch: public Orch
{
public:
void doTask(Consumer &consumer);
FlexCounterOrch(DBConnector *db, vector<string> &tableNames);
virtual ~FlexCounterOrch(void);

private:
shared_ptr<DBConnector> m_flexCounterDb = nullptr;
shared_ptr<ProducerTable> m_flexCounterGroupTable = nullptr;
};

#endif
7 changes: 7 additions & 0 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ bool OrchDaemon::init()
m_orchList = { switch_orch, gCrmOrch, gPortsOrch, intfs_orch, gNeighOrch, gRouteOrch, copp_orch, tunnel_decap_orch, qos_orch, buffer_orch, mirror_orch, gAclOrch, gFdbOrch, vrf_orch };
m_select = new Select();


vector<string> flex_counter_tables = {
CFG_FLEX_COUNTER_TABLE_NAME
};

m_orchList.push_back(new FlexCounterOrch(m_configDb, flex_counter_tables));

vector<string> pfc_wd_tables = {
CFG_PFC_WD_TABLE_NAME
};
Expand Down
1 change: 1 addition & 0 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "crmorch.h"
#include "vrforch.h"
#include "countercheckorch.h"
#include "flexcounterorch.h"

using namespace swss;

Expand Down
2 changes: 0 additions & 2 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ extern CrmOrch *gCrmOrch;
#define DEFAULT_VLAN_ID 1
#define PORT_FLEX_STAT_COUNTER_POLL_MSECS "1000"
#define QUEUE_FLEX_STAT_COUNTER_POLL_MSECS "10000"
#define PORT_STAT_COUNTER_FLEX_COUNTER_GROUP "PORT_STAT_COUNTER"
#define QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_STAT_COUNTER"

static map<string, sai_port_fec_mode_t> fec_mode_map =
{
Expand Down
3 changes: 3 additions & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

#define FCS_LEN 4
#define VLAN_TAG_LEN 4
#define PORT_STAT_COUNTER_FLEX_COUNTER_GROUP "PORT_STAT_COUNTER"
#define QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP "QUEUE_STAT_COUNTER"


typedef std::vector<sai_uint32_t> PortSupportedSpeeds;

Expand Down

0 comments on commit 8c23538

Please sign in to comment.