Skip to content

Commit

Permalink
Add support for route flow counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox committed Jan 14, 2022
1 parent 691c37b commit e71c7fe
Show file tree
Hide file tree
Showing 20 changed files with 1,729 additions and 48 deletions.
1 change: 1 addition & 0 deletions orchagent/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ orchagent_SOURCES = \
cbf/cbfnhgorch.cpp \
cbf/nhgmaporch.cpp \
routeorch.cpp \
routepatternorch.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_MATCH, FLOW_COUNTER_ID_LIST },
};

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_MATCH,
};

// 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 && 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);
}
IpPrefix prefix = ip_prefix.getIp().to_string();
gRouteOrch->onAddOtherRouteEntry(vrf_id, prefix);
}

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);
}
IpPrefix prefix = ip_prefix.getIp().to_string();
gRouteOrch->onRemoveOtherRouteEntry(vrf_id, prefix);
}

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->onAddOtherRouteEntry(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->onRemoveOtherRouteEntry(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 @@ -610,6 +610,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,
};
auto *route_pattern_orch = new RoutePatternOrch(m_configDb, route_pattern_tables);
m_orchList.push_back(route_pattern_orch);
gDirectory.set(route_pattern_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 "routepatternorch.h"
#include "nhgorch.h"
#include "cbf/cbfnhgorch.h"
#include "cbf/nhgmaporch.h"
Expand Down
Loading

0 comments on commit e71c7fe

Please sign in to comment.