Skip to content

Commit

Permalink
Add voqstatsorch to synchronise ASIC's COUNTERS_DB and SSI's CHASSIS_…
Browse files Browse the repository at this point in the history
…COUNTERS_DB
  • Loading branch information
vivekverma-arista committed Aug 28, 2024
1 parent 29cea04 commit 119ae24
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 4 deletions.
4 changes: 2 additions & 2 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ orchagent_SOURCES = \
dash/dashaclgroupmgr.cpp \
dash/dashtagmgr.cpp \
dash/pbutils.cpp \
twamporch.cpp
twamporch.cpp \
voqstatsorch.cpp

orchagent_SOURCES += flex_counter/flex_counter_manager.cpp flex_counter/flex_counter_stat_manager.cpp flex_counter/flow_counter_handler.cpp flex_counter/flowcounterrouteorch.cpp
orchagent_SOURCES += debug_counter/debug_counter.cpp debug_counter/drop_counter.cpp
Expand Down Expand Up @@ -161,4 +162,3 @@ orchagent_SOURCES += $(top_srcdir)/lib/asan.cpp
routeresync_SOURCES += $(top_srcdir)/lib/asan.cpp
orchagent_restart_check_SOURCES += $(top_srcdir)/lib/asan.cpp
endif

2 changes: 1 addition & 1 deletion orchagent/chassisorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class ChassisOrch : public Orch, public Observer
VNetRouteOrch* m_vNetRouteOrch;
};

#endif
#endif
16 changes: 16 additions & 0 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define SAI_SWITCH_ATTR_CUSTOM_RANGE_BASE SAI_SWITCH_ATTR_CUSTOM_RANGE_START
#include "sairedis.h"
#include "chassisorch.h"
#include "voqstatsorch.h"

using namespace std;
using namespace swss;
Expand Down Expand Up @@ -195,6 +196,16 @@ bool OrchDaemon::init()
ChassisOrch* chassis_frontend_orch = new ChassisOrch(m_configDb, m_applDb, chassis_frontend_tables, vnet_rt_orch);
gDirectory.set(chassis_frontend_orch);

VoqStatsOrch* voqStatsOrch;
// Initialize voqstatsorch in case of chassis
if (gMySwitchType=="voq")
{
voqStatsOrch = new VoqStatsOrch(new DBConnector("COUNTERS_DB", 0),
new DBConnector("CHASSIS_COUNTERS_DB", 0, true),
vector<string>());
gDirectory.set(voqStatsOrch);
}

gIntfsOrch = new IntfsOrch(m_applDb, APP_INTF_TABLE_NAME, vrf_orch, m_chassisAppDb);
gNeighOrch = new NeighOrch(m_applDb, APP_NEIGH_TABLE_NAME, gIntfsOrch, gFdbOrch, gPortsOrch, m_chassisAppDb);

Expand Down Expand Up @@ -494,6 +505,11 @@ bool OrchDaemon::init()
m_orchList.push_back(evpn_nvo_orch);
m_orchList.push_back(vxlan_tunnel_map_orch);

if (gMySwitchType=="voq")
{
m_orchList.push_back(voqStatsOrch);
}

if (vxlan_tunnel_orch->isDipTunnelsSupported())
{
EvpnRemoteVnip2pOrch* evpn_remote_vni_orch = new EvpnRemoteVnip2pOrch(m_applDb, APP_VXLAN_REMOTE_VNI_TABLE_NAME);
Expand Down
10 changes: 10 additions & 0 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7335,6 +7335,11 @@ void PortsOrch::generateQueueMapPerPort(const Port& port, FlexCounterQueueStates
// flexcounter orch logic. Always enabled voq counters.
addQueueFlexCountersPerPortPerQueueIndex(port, queueIndex, true);
queuePortVector.emplace_back(id, sai_serialize_object_id(port.m_system_port_oid));

// Reverse map from oid to VOQ name
// id -> oid:0x15000000000582
// name -> Linecard|asic|EthernetXXX:VoqIdx
m_voq_name_map[id] = name.str();
}
else
{
Expand Down Expand Up @@ -9892,3 +9897,8 @@ void PortsOrch::doTask(swss::SelectableTimer &timer)
}
}

string PortsOrch::getVoqName(string voq)
{
return m_voq_name_map[voq];
}

5 changes: 5 additions & 0 deletions orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ class PortsOrch : public Orch, public Subject
bool setPortPtIntfId(const Port& port, sai_uint16_t intf_id);
bool setPortPtTimestampTemplate(const Port& port, sai_port_path_tracing_timestamp_type_t ts_type);

string getVoqName(string);

private:
unique_ptr<Table> m_counterTable;
unique_ptr<Table> m_counterSysPortTable;
Expand Down Expand Up @@ -323,6 +325,9 @@ class PortsOrch : public Orch, public Subject
map<string, Port> m_pluggedModulesPort;
map<string, vlan_members_t> m_portVlanMember;
map<string, std::vector<sai_object_id_t>> m_port_voq_ids;

map<string, string> m_voq_name_map;

/* mapping from SAI object ID to Name for faster
* retrieval of Port/VLAN from object ID for events
* coming from SAI
Expand Down
75 changes: 75 additions & 0 deletions orchagent/voqstatsorch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "orch.h"
#include "subscriberstatetable.h"
#include "voqstatsorch.h"
#include "portsorch.h"

using namespace swss;
using namespace std;

extern PortsOrch *gPortsOrch;
extern string gMyHostName;
extern string gMyAsicName;

VoqStatsOrch::VoqStatsOrch(
DBConnector *countersDb,
DBConnector *chassisCountersDb,
const std::vector<std::string> &tableNames) :
Orch(countersDb, tableNames),
m_voqCntrsTable(chassisCountersDb, CHASSIS_COUNTERS_VOQ)
{
auto consumerStateTable = new SubscriberStateTable(countersDb, COUNTERS_TABLE,
TableConsumable::DEFAULT_POP_BATCH_SIZE, default_orch_pri);
auto consumer = new Consumer(consumerStateTable, this, COUNTERS_TABLE);
Orch::addExecutor(consumer);
}

void VoqStatsOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();
auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
auto t = it->second;
const std::string & op = kfvOp(t);
const std::string & ip = kfvKey(t);
const std::vector<FieldValueTuple> fvt = kfvFieldsValues(t);

if (op == SET_COMMAND)
{
// ip is of the form oid:0x1010000000000d1
updateChassisCountersDb(ip, fvt);
}
else if(op == DEL_COMMAND)
{
SWSS_LOG_WARN("Unsupported op %s", op.c_str());
}
else
{
SWSS_LOG_ERROR("Unknown operation type %s\n", op.c_str());
}
it = consumer.m_toSync.erase(it);
}
}

void VoqStatsOrch::updateChassisCountersDb(const string & key, const std::vector<FieldValueTuple> & fvt)
{
SWSS_LOG_ENTER();
string voqName = gPortsOrch->getVoqName(key);
// if it wasn't a VOQ counter that fired the reactor then early return
if (voqName=="")
{
return;
}

// Construct the key for CHASSIS_COUNTERS_VOQ table
// Linecard1 | asic0 | Ethernet120 @ Linecard2 | asic1 : 7
// Where Linecard1 | asic0 | Ethernet120 is the sysport corresponding to the VOQ
// The VOQ physically exists on asic1 of Linecard2
// index is the VOQ index

string chassisCountersKey = voqName.substr(0,voqName.find(":")) + "@" + gMyHostName + "|" + gMyAsicName + voqName.substr(voqName.find(":"));
for (std::pair<std::basic_string<char>, std::basic_string<char> > i: fvt)
{
m_voqCntrsTable.hset(chassisCountersKey, i.first, i.second);
}
}
24 changes: 24 additions & 0 deletions orchagent/voqstatsorch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef SWSS_VOQSTATSORCH_H
#define SWSS_VOQSTATSORCH_H

#include "orch.h"
#include "dbconnector.h"
#include "table.h"

class VoqStatsOrch : public Orch
{
public:

VoqStatsOrch(
swss::DBConnector *countersDb,
swss::DBConnector *chassisCountersDb,
const std::vector<std::string> &tableNames);

private:

swss::Table m_voqCntrsTable;
virtual void doTask(Consumer &consumer);
void updateChassisCountersDb(const std::string &, const std::vector<swss::FieldValueTuple> &);
};

#endif
3 changes: 2 additions & 1 deletion tests/mock_tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ tests_SOURCES = aclorch_ut.cpp \
$(top_srcdir)/warmrestart/warmRestartAssist.cpp \
$(top_srcdir)/orchagent/dash/pbutils.cpp \
$(top_srcdir)/cfgmgr/coppmgr.cpp \
$(top_srcdir)/orchagent/twamporch.cpp
$(top_srcdir)/orchagent/twamporch.cpp \
$(top_srcdir)/orchagent/voqstatsorch.cpp

tests_SOURCES += $(FLEX_CTR_DIR)/flex_counter_manager.cpp $(FLEX_CTR_DIR)/flex_counter_stat_manager.cpp $(FLEX_CTR_DIR)/flow_counter_handler.cpp $(FLEX_CTR_DIR)/flowcounterrouteorch.cpp
tests_SOURCES += $(DEBUG_CTR_DIR)/debug_counter.cpp $(DEBUG_CTR_DIR)/drop_counter.cpp
Expand Down

0 comments on commit 119ae24

Please sign in to comment.