Skip to content
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

Add support for route flow counter #2094

Merged
merged 17 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ orchagent_SOURCES = \
cbf/cbfnhgorch.cpp \
cbf/nhgmaporch.cpp \
routeorch.cpp \
routeflowcounterorch.cpp \
mplsrouteorch.cpp \
neighorch.cpp \
intfsorch.cpp \
Expand Down
1 change: 1 addition & 0 deletions orchagent/flex_counter/flex_counter_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const unordered_map<CounterType, string> FlexCounterManager::counter_id_field_lo
{ CounterType::ACL_COUNTER, ACL_COUNTER_ATTR_ID_LIST },
{ CounterType::TUNNEL, TUNNEL_COUNTER_ID_LIST },
{ CounterType::HOSTIF_TRAP, FLOW_COUNTER_ID_LIST },
{ CounterType::ROUTE, FLOW_COUNTER_ID_LIST },
Junchao-Mellanox marked this conversation as resolved.
Show resolved Hide resolved
};

FlexManagerDirectory g_FlexManagerDirectory;
Expand Down
1 change: 1 addition & 0 deletions orchagent/flex_counter/flex_counter_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class CounterType
ACL_COUNTER,
TUNNEL,
HOSTIF_TRAP,
ROUTE,
};

// FlexCounterManager allows users to manage a group of flex counters.
Expand Down
13 changes: 13 additions & 0 deletions orchagent/flex_counter/flow_counter_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,16 @@ void FlowCounterHandler::getGenericCounterStatIdList(std::unordered_set<std::str
counter_stats.emplace(sai_serialize_counter_stat(it));
}
}

bool FlowCounterHandler::queryRouteFlowCounterCapability()
{
sai_attr_capability_t capability;
sai_status_t status = sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_ROUTE_ENTRY, SAI_ROUTE_ENTRY_ATTR_COUNTER_ID, &capability);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN("Could not query route entry attribute SAI_ROUTE_ENTRY_ATTR_COUNTER_ID %d", status);
return false;
}

return capability.set_implemented;
}
1 change: 1 addition & 0 deletions orchagent/flex_counter/flow_counter_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class FlowCounterHandler
static bool createGenericCounter(sai_object_id_t &counter_id);
static bool removeGenericCounter(sai_object_id_t counter_id);
static void getGenericCounterStatIdList(std::unordered_set<std::string>& counter_stats);
static bool queryRouteFlowCounterCapability();
};
17 changes: 17 additions & 0 deletions orchagent/flexcounterorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "debugcounterorch.h"
#include "directory.h"
#include "copporch.h"
#include "routeorch.h"

extern sai_port_api_t *sai_port_api;

Expand All @@ -19,6 +20,7 @@ extern IntfsOrch *gIntfsOrch;
extern BufferOrch *gBufferOrch;
extern Directory<Orch*> gDirectory;
extern CoppOrch *gCoppOrch;
extern RouteOrch *gRouteOrch;

#define BUFFER_POOL_WATERMARK_KEY "BUFFER_POOL_WATERMARK"
#define PORT_KEY "PORT"
Expand All @@ -29,6 +31,7 @@ extern CoppOrch *gCoppOrch;
#define ACL_KEY "ACL"
#define TUNNEL_KEY "TUNNEL"
#define FLOW_CNT_TRAP_KEY "FLOW_CNT_TRAP"
#define FLOW_CNT_ROUTE_KEY "FLOW_CNT_ROUTE"

unordered_map<string, string> flexCounterGroupMap =
{
Expand All @@ -47,6 +50,7 @@ unordered_map<string, string> flexCounterGroupMap =
{"ACL", ACL_COUNTER_FLEX_COUNTER_GROUP},
{"TUNNEL", TUNNEL_STAT_COUNTER_FLEX_COUNTER_GROUP},
{FLOW_CNT_TRAP_KEY, HOSTIF_TRAP_COUNTER_FLEX_COUNTER_GROUP},
{FLOW_CNT_ROUTE_KEY, ROUTE_FLOW_COUNTER_FLEX_COUNTER_GROUP},
};


Expand Down Expand Up @@ -175,6 +179,19 @@ void FlexCounterOrch::doTask(Consumer &consumer)
m_hostif_trap_counter_enabled = false;
}
}
if (gRouteOrch && gRouteOrch->getRouteFlowCounterSupported() && key == FLOW_CNT_ROUTE_KEY)
{
if (value == "enable" && !m_route_flow_counter_enabled)
{
m_route_flow_counter_enabled = true;
gRouteOrch->generateRouteFlowStats();
}
else if (value == "disable" && m_route_flow_counter_enabled)
{
gRouteOrch->clearRouteFlowStats();
m_route_flow_counter_enabled = false;
}
}
vector<FieldValueTuple> fieldValues;
fieldValues.emplace_back(FLEX_COUNTER_STATUS_FIELD, value);
m_flexCounterGroupTable->set(flexCounterGroupMap[key], fieldValues);
Expand Down
3 changes: 2 additions & 1 deletion orchagent/flexcounterorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ class FlexCounterOrch: public Orch
bool getPortCountersState() const;
bool getPortBufferDropCountersState() const;
bool getHostIfTrapCounterState() const {return m_hostif_trap_counter_enabled;}
bool getRouteFlowCountersState() const {return m_route_flow_counter_enabled;}
bool bake() override;


private:
std::shared_ptr<swss::DBConnector> m_flexCounterDb = nullptr;
std::shared_ptr<swss::ProducerTable> m_flexCounterGroupTable = nullptr;
bool m_port_counter_enabled = false;
bool m_port_buffer_drop_counter_enabled = false;
bool m_hostif_trap_counter_enabled = false;
bool m_route_flow_counter_enabled = false;
Table m_flexCounterConfigTable;
};

Expand Down
4 changes: 4 additions & 0 deletions orchagent/intfsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,8 @@ void IntfsOrch::addIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix)
{
gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);
}

gRouteOrch->onAddMiscRouteEntry(vrf_id, IpPrefix(ip_prefix.getIp().to_string()));
}

void IntfsOrch::removeIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix)
Expand Down Expand Up @@ -1301,6 +1303,8 @@ void IntfsOrch::removeIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_pref
{
gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);
}

gRouteOrch->onRemoveMiscRouteEntry(vrf_id, IpPrefix(ip_prefix.getIp().to_string()));
}

void IntfsOrch::addDirectedBroadcast(const Port &port, const IpPrefix &ip_prefix)
Expand Down
4 changes: 4 additions & 0 deletions orchagent/muxorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ static sai_status_t create_route(IpPrefix &pfx, sai_object_id_t nh)
gCrmOrch->incCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);
}

gRouteOrch->onAddMiscRouteEntry(gVirtualRouterId, pfx.getSubnet());

SWSS_LOG_NOTICE("Created tunnel route to %s ", pfx.to_string().c_str());
return status;
}
Expand Down Expand Up @@ -158,6 +160,8 @@ static sai_status_t remove_route(IpPrefix &pfx)
gCrmOrch->decCrmResUsedCounter(CrmResourceType::CRM_IPV6_ROUTE);
}

gRouteOrch->onRemoveMiscRouteEntry(gVirtualRouterId, pfx.getSubnet());

SWSS_LOG_NOTICE("Removed tunnel route to %s ", pfx.to_string().c_str());
return status;
}
Expand Down
7 changes: 7 additions & 0 deletions orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,13 @@ bool OrchDaemon::init()
gP4Orch = new P4Orch(m_applDb, p4rt_tables, vrf_orch, gCoppOrch);
m_orchList.push_back(gP4Orch);

static const vector<string> route_pattern_tables = {
CFG_FLOW_COUNTER_ROUTE_PATTERN_TABLE_NAME,
};
auto *route_flow_counter_orch = new RouteFlowCounterOrch(m_configDb, route_pattern_tables);
m_orchList.push_back(route_flow_counter_orch);
gDirectory.set(route_flow_counter_orch);

if (WarmStart::isWarmStart())
{
bool suc = warmRestoreAndSyncUp();
Expand Down
1 change: 1 addition & 0 deletions orchagent/orchdaemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "intfsorch.h"
#include "neighorch.h"
#include "routeorch.h"
#include "routeflowcounterorch.h"
#include "nhgorch.h"
#include "cbf/cbfnhgorch.h"
#include "cbf/nhgmaporch.h"
Expand Down
69 changes: 69 additions & 0 deletions orchagent/routeflowcounterorch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "dbconnector.h"
Junchao-Mellanox marked this conversation as resolved.
Show resolved Hide resolved
#include "directory.h"
#include "flow_counter_handler.h"
#include "routeorch.h"
#include "routeflowcounterorch.h"
#include "schema.h"
#include "table.h"

#include <string>

extern Directory<Orch*> gDirectory;
extern RouteOrch *gRouteOrch;
#define ROUTE_PATTERN_MAX_MATCH_COUNT_FIELD "max_match_count"
#define ROUTE_PATTERN_DEFAULT_MAX_MATCH_COUNT 30

RouteFlowCounterOrch::RouteFlowCounterOrch(swss::DBConnector *db, const std::vector<std::string> &tableNames):
Orch(db, tableNames)
{
SWSS_LOG_ENTER();
}

RouteFlowCounterOrch::~RouteFlowCounterOrch()
{
SWSS_LOG_ENTER();
}

void RouteFlowCounterOrch::doTask(Consumer &consumer)
{
SWSS_LOG_ENTER();
if (!gRouteOrch || !gRouteOrch->getRouteFlowCounterSupported())
{
return;
}

auto it = consumer.m_toSync.begin();
while (it != consumer.m_toSync.end())
{
KeyOpFieldsValuesTuple t = it->second;

const auto &key = kfvKey(t);
const auto &op = kfvOp(t);
const auto &data = kfvFieldsValues(t);
if (op == SET_COMMAND)
{
size_t maxMatchCount = ROUTE_PATTERN_DEFAULT_MAX_MATCH_COUNT;
for (auto valuePair : data)
{
const auto &field = fvField(valuePair);
const auto &value = fvValue(valuePair);
if (field == ROUTE_PATTERN_MAX_MATCH_COUNT_FIELD)
{
maxMatchCount = (size_t)std::stoul(value);
if (maxMatchCount == 0)
{
SWSS_LOG_WARN("Max match count for route pattern cannot be 0, set it to default value 30");
maxMatchCount = ROUTE_PATTERN_DEFAULT_MAX_MATCH_COUNT;
}
}
}

gRouteOrch->addRoutePattern(key, maxMatchCount);
}
else if (op == DEL_COMMAND)
{
gRouteOrch->removeRoutePattern(key);
}
consumer.m_toSync.erase(it++);
}
}
11 changes: 11 additions & 0 deletions orchagent/routeflowcounterorch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "orch.h"

class RouteFlowCounterOrch : public Orch
{
public:
RouteFlowCounterOrch(swss::DBConnector *db, const std::vector<std::string> &tableNames);
virtual ~RouteFlowCounterOrch(void);
void doTask(Consumer &consumer) override;
};
Loading