Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox committed Jan 5, 2022
1 parent 740af0a commit 607329f
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 142 deletions.
9 changes: 0 additions & 9 deletions orchagent/bulker.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class EntityBulker
attrs.emplace_back(std::piecewise_construct,
std::forward_as_tuple(*attr),
std::forward_as_tuple(object_status));
SWSS_LOG_WARN("Setting object status for %p SAI_STATUS_NOT_EXECUTED", object_status);
*object_status = SAI_STATUS_NOT_EXECUTED;
}

Expand Down Expand Up @@ -357,19 +356,16 @@ class EntityBulker
// Setting
if (!setting_entries.empty())
{
SWSS_LOG_WARN("Bulk setting entries...");
std::vector<Te> rs;
std::vector<sai_attribute_t> ts;
std::vector<sai_status_t*> status_vector;

for (auto const& i: setting_entries)
{
SWSS_LOG_WARN("Seting an entry...");
auto const& entry = i.first;
auto const& attrs = i.second;
for (auto const& ia: attrs)
{
SWSS_LOG_WARN("Put first attribute...");
auto const& attr = ia.first;
sai_status_t *object_status = ia.second;
if (*object_status == SAI_STATUS_NOT_EXECUTED)
Expand All @@ -383,10 +379,6 @@ class EntityBulker
flush_setting_entries(rs, ts, status_vector);
}
}
else
{
SWSS_LOG_WARN("Object status %p is not SAI_STATUS_NOT_EXECUTED, it is actually %s...", object_status, sai_serialize_status(*object_status).c_str());
}
}
}
flush_setting_entries(rs, ts, status_vector);
Expand Down Expand Up @@ -539,7 +531,6 @@ class EntityBulker
{
if (rs.empty())
{
SWSS_LOG_WARN("rs is empty...");
return SAI_STATUS_SUCCESS;
}
size_t count = rs.size();
Expand Down
20 changes: 0 additions & 20 deletions orchagent/flex_counter/flow_counter_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,6 @@ void FlowCounterHandler::getGenericCounterStatIdList(std::unordered_set<std::str
bool FlowCounterHandler::queryRouteFlowCounterCapability()
{
sai_attr_capability_t capability;
/*sai_status_t status = sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_COUNTER, SAI_COUNTER_STAT_PACKETS, &capability);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN("Could not query counter attribute SAI_COUNTER_STAT_PACKETS %d", status);
return false;
}
bool support_counter_stats_packets = capability.get_implemented;
status = sai_query_attribute_capability(gSwitchId, SAI_OBJECT_TYPE_COUNTER, SAI_COUNTER_STAT_BYTES, &capability);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN("Could not query counter attribute SAI_COUNTER_STAT_BYTES %d", status);
return false;
}
if (!support_counter_stats_packets && !capability.get_implemented)
{
return false;
}*/

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)
{
Expand Down
2 changes: 0 additions & 2 deletions orchagent/flex_counter/flow_counter_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +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();

};
4 changes: 3 additions & 1 deletion orchagent/orchdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,9 @@ bool OrchDaemon::init()
gP4Orch = new P4Orch(m_applDb, p4rt_tables, vrf_orch, gCoppOrch);
m_orchList.push_back(gP4Orch);

vector<string> route_pattern_tables = {CFG_FLOW_COUNTER_ROUTE_PATTERN_TABLE};
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);
Expand Down
171 changes: 74 additions & 97 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2586,22 +2586,19 @@ void RouteOrch::clearRouteFlowStats()
for (auto &entry : mBoundRouteCounters)
{
const auto& route_pattern = entry.first;
auto vrf_id = route_pattern.vrf_id;

for (auto &inner_entry : entry.second)
{
removeRountFlowCounterFromDB(vrf_id, inner_entry.first, inner_entry.second);
bulkUnbindFlowCounters(route_entry, attr, vrf_id, inner_entry.second, inner_entry.first, to_unbind);
removeRountFlowCounterFromDB(route_pattern.vrf_id, inner_entry.first, inner_entry.second);
bulkUnbindFlowCounters(route_entry, attr, route_pattern.vrf_id, inner_entry.second, inner_entry.first, to_unbind);
}
}

for (auto &entry : mPendingAddToFlexCntr)
{
const auto& route_pattern = entry.first;
auto vrf_id = route_pattern.vrf_id;
for (auto &inner_entry : entry.second)
{
bulkUnbindFlowCounters(route_entry, attr, vrf_id, inner_entry.second, inner_entry.first, to_unbind);
bulkUnbindFlowCounters(route_entry, attr, route_pattern.vrf_id, inner_entry.second, inner_entry.first, to_unbind);
}
}

Expand All @@ -2625,10 +2622,10 @@ void RouteOrch::updateRoutePattern(const std::string &pattern, size_t max_match_
return;
}

SWSS_LOG_NOTICE("Update route pattern to %s, max match count is %lu", pattern.c_str(), max_match_count);
auto insert_result = mRoutePatternSet.emplace(vrf_id, ip_prefix, max_match_count);
if (insert_result.second)
{
SWSS_LOG_NOTICE("Inserting route pattern %s, max match count is %lu", pattern.c_str(), max_match_count);
if (!validateRoutePattern(*insert_result.first))
{
mRoutePatternSet.erase(insert_result.first);
Expand All @@ -2639,11 +2636,73 @@ void RouteOrch::updateRoutePattern(const std::string &pattern, size_t max_match_
}
else
{
SWSS_LOG_NOTICE("Updating route pattern %s max match count to %lu", pattern.c_str(), max_match_count);
RoutePattern &existing = const_cast<RoutePattern &>(*insert_result.first);
onRoutePatternMaxMatchCountChange(existing, max_match_count);
}
}

void RouteOrch::removeRoutePattern(const std::string& pattern)
{
SWSS_LOG_ENTER();
sai_object_id_t vrf_id;
IpPrefix ip_prefix;
if (!parseRouteKey(pattern, '|', vrf_id, ip_prefix))
{
SWSS_LOG_ERROR("removeRoutePattern: Failed to parse route pattern: %s", pattern.c_str());
return;
}

SWSS_LOG_NOTICE("Removing route pattern %s", pattern.c_str());
RoutePattern route_pattern(vrf_id, ip_prefix, 0);
auto iter = mRoutePatternSet.find(route_pattern);
if (iter == mRoutePatternSet.end())
{
// Should not go to this branch, just in case
SWSS_LOG_ERROR("Trying to remove route pattern %s, but it does not exist", pattern.c_str());
return;
}
mRoutePatternSet.erase(iter);

auto unbound_iter = mUnboundRoutes.find(route_pattern);
if (unbound_iter != mUnboundRoutes.end())
{
mUnboundRoutes.erase(unbound_iter);
}

sai_route_entry_t route_entry;
route_entry.switch_id = gSwitchId;

sai_attribute_t attr;
attr.id = SAI_ROUTE_ENTRY_ATTR_COUNTER_ID;

std::list<RouteFlowCounterBulkContext> to_unbind;

auto cache_iter = mBoundRouteCounters.find(route_pattern);
if (cache_iter != mBoundRouteCounters.end())
{
for (auto &entry : cache_iter->second)
{
removeRountFlowCounterFromDB(vrf_id, entry.first, entry.second);
bulkUnbindFlowCounters(route_entry, attr, vrf_id, entry.second, entry.first, to_unbind);
}
mBoundRouteCounters.erase(cache_iter);
flushUnbindFlowCounters(to_unbind);
return;
}

auto pending_iter = mPendingAddToFlexCntr.find(route_pattern);
if (pending_iter != mPendingAddToFlexCntr.end())
{
for (auto &entry : pending_iter->second)
{
bulkUnbindFlowCounters(route_entry, attr, vrf_id, entry.second, entry.first, to_unbind);
}
mPendingAddToFlexCntr.erase(pending_iter);
flushUnbindFlowCounters(to_unbind);
}
}

bool RouteOrch::validateRoutePattern(const RoutePattern &route_pattern) const
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -2699,7 +2758,7 @@ void RouteOrch::createRouteFlowCounterByPattern(const RoutePattern &route_patter
{
if (current_bound_count >= route_pattern.max_match_count)
{
SWSS_LOG_WARN("Adding route entry to unbound cache, current bound=%lu, max allowed=%lu", current_bound_count, route_pattern.max_match_count); // TODO: Change level
SWSS_LOG_DEBUG("Adding route entry to unbound cache, current bound=%lu, max allowed=%lu", current_bound_count, route_pattern.max_match_count);
addUnboundRoutesToCache(route_pattern, ip_prefix);
continue;
}
Expand Down Expand Up @@ -2857,7 +2916,7 @@ void RouteOrch::onRoutePatternMaxMatchCountChange(RoutePattern &route_pattern, s
}

auto current_bound_count = getRouteFlowCounterSizeByPattern(route_pattern);
SWSS_LOG_DEBUG("Current bound count is %lu, new limit is %lu, old limit is %lu", current_bound_count, new_max_match_count, old_max_match_count);
SWSS_LOG_NOTICE("Current bound route flow counter count is %lu, new limit is %lu, old limit is %lu", current_bound_count, new_max_match_count, old_max_match_count);
if (new_max_match_count > old_max_match_count)
{
if (current_bound_count == old_max_match_count)
Expand All @@ -2875,68 +2934,6 @@ void RouteOrch::onRoutePatternMaxMatchCountChange(RoutePattern &route_pattern, s
}
}

void RouteOrch::removeRoutePattern(const std::string& pattern)
{
SWSS_LOG_ENTER();
sai_object_id_t vrf_id;
IpPrefix ip_prefix;
if (!parseRouteKey(pattern, '|', vrf_id, ip_prefix))
{
SWSS_LOG_ERROR("removeRoutePattern: Failed to parse route pattern: %s", pattern.c_str());
return;
}

SWSS_LOG_NOTICE("Removing route pattern %s", pattern.c_str());
RoutePattern route_pattern(vrf_id, ip_prefix, 0);
auto iter = mRoutePatternSet.find(route_pattern);
if (iter == mRoutePatternSet.end())
{
// Should not go to this branch, just in case
SWSS_LOG_ERROR("Trying to remove route pattern %s, but it does not exist", pattern.c_str());
return;
}
mRoutePatternSet.erase(iter);

auto unbound_iter = mUnboundRoutes.find(route_pattern);
if (unbound_iter != mUnboundRoutes.end())
{
mUnboundRoutes.erase(unbound_iter);
return;
}

sai_route_entry_t route_entry;
route_entry.switch_id = gSwitchId;

sai_attribute_t attr;
attr.id = SAI_ROUTE_ENTRY_ATTR_COUNTER_ID;

std::list<RouteFlowCounterBulkContext> to_unbind;

auto cache_iter = mBoundRouteCounters.find(route_pattern);
if (cache_iter != mBoundRouteCounters.end())
{
for (auto &entry : cache_iter->second)
{
removeRountFlowCounterFromDB(vrf_id, entry.first, entry.second);
bulkUnbindFlowCounters(route_entry, attr, vrf_id, entry.second, entry.first, to_unbind);
}
mBoundRouteCounters.erase(cache_iter);
flushUnbindFlowCounters(to_unbind);
return;
}

auto pending_iter = mPendingAddToFlexCntr.find(route_pattern);
if (pending_iter != mPendingAddToFlexCntr.end())
{
for (auto &entry : pending_iter->second)
{
bulkUnbindFlowCounters(route_entry, attr, vrf_id, entry.second, entry.first, to_unbind);
}
mPendingAddToFlexCntr.erase(pending_iter);
flushUnbindFlowCounters(to_unbind);
}
}

void RouteOrch::getRouteFlowCounterNameMapKey(sai_object_id_t vrf_id, IpPrefix ip_prefix, std::string &key)
{
SWSS_LOG_ENTER();
Expand All @@ -2953,7 +2950,7 @@ void RouteOrch::getRouteFlowCounterNameMapKey(sai_object_id_t vrf_id, IpPrefix i
void RouteOrch::doTask(SelectableTimer &timer)
{
SWSS_LOG_ENTER();
SWSS_LOG_WARN("Add flex counters, pending in queue: %lu", mPendingAddToFlexCntr.size()); // TODO: Change level
SWSS_LOG_NOTICE("Add flex counters, pending in queue: %lu", mPendingAddToFlexCntr.size());
string value;
std::string nameMapKey;
std::string pattern;
Expand Down Expand Up @@ -3114,7 +3111,7 @@ void RouteOrch::processRouteFlowCounterBinding()
}
}
} else {
// Remove DB entry
// Check if the entry is in mBoundRouteCounters
auto cache_iter = mBoundRouteCounters.find(route_pattern);
if (cache_iter != mBoundRouteCounters.end())
{
Expand Down Expand Up @@ -3142,11 +3139,10 @@ void RouteOrch::processRouteFlowCounterBinding()
}

mPendingUnbindRoutes.clear();
SWSS_LOG_WARN("Pending fill count = %lu", pending_fill.size());
SWSS_LOG_NOTICE("Pending fill route flow counter count = %lu", pending_fill.size());
for (const auto &route_pattern : pending_fill)
{
auto current_bound_count = getRouteFlowCounterSizeByPattern(route_pattern);
createRouteFlowCounterFromUnboundCacheByPattern(route_pattern, current_bound_count);
createRouteFlowCounterFromUnboundCacheByPattern(route_pattern, getRouteFlowCounterSizeByPattern(route_pattern));
}

std::list<RouteFlowCounterBulkContext> to_bind;
Expand All @@ -3159,7 +3155,7 @@ void RouteOrch::processRouteFlowCounterBinding()
{
if (current_bound_count >= route_pattern.max_match_count)
{
SWSS_LOG_WARN("Adding route entry to unbound cache, current bound=%lu, max allowed=%lu", current_bound_count, route_pattern.max_match_count); // TODO: Change level
SWSS_LOG_DEBUG("Adding route entry to unbound cache, current bound=%lu, max allowed=%lu", current_bound_count, route_pattern.max_match_count);
addUnboundRoutesToCache(route_pattern, ip_prefix);
continue;
}
Expand Down Expand Up @@ -3195,25 +3191,13 @@ bool RouteOrch::bulkBindFlowCounters(
SWSS_LOG_ERROR("Failed to create generic counter");
return false;
}
for (auto &ctx : to_bind)
{
auto &status = ctx.object_statuses.back();
SWSS_LOG_WARN("before bulkBindFlowCounters..., status pointer = %p, status = %s", &status, sai_serialize_status(status).c_str()); // TODO: REMOVE ME
}
copy(route_entry.destination, ip_prefix);
attr.value.oid = counter_oid;
to_bind.emplace_back(ip_prefix, counter_oid);
auto &ctx = to_bind.back();
ctx.object_statuses.emplace_back();
gRouteBulker.set_entry_attribute(&ctx.object_statuses.back(), &route_entry, &attr);
auto &status = ctx.object_statuses.back();
++current_bound_count;
SWSS_LOG_WARN("Bulk bind success..., status pointer = %p, status = %s", &status, sai_serialize_status(status).c_str()); // TODO: REMOVE ME
for (auto &ctx : to_bind)
{
auto &status = ctx.object_statuses.back();
SWSS_LOG_WARN("after bulkBindFlowCounters..., status pointer = %p, status = %s", &status, sai_serialize_status(status).c_str()); // TODO: REMOVE ME
}
return true;
}

Expand All @@ -3222,20 +3206,14 @@ void RouteOrch::flushBindFlowCounters(const RoutePattern &route_pattern, std::li
SWSS_LOG_ENTER();
if (gRouteBulker.setting_entries_count() > 0)
{
SWSS_LOG_WARN("Flushing counter bind...."); // TODO: REMOVE ME
for (auto &ctx : to_bind)
{
auto &status = ctx.object_statuses.back();
SWSS_LOG_WARN("Before flush..., status pointer = %p, status = %s", &status, sai_serialize_status(status).c_str()); // TODO: REMOVE ME
}
gRouteBulker.flush();
for(auto &ctx : to_bind)
{
auto it_status = ctx.object_statuses.begin();
sai_status_t status = *it_status++;
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_WARN("Failed to bind generic counter to route entry %s", ctx.ip_prefix.to_string().c_str());
SWSS_LOG_WARN("Failed to bind generic counter to route entry %s, status=%s", ctx.ip_prefix.to_string().c_str(), sai_serialize_status(status).c_str());
FlowCounterHandler::removeGenericCounter(ctx.counter_oid);
--bound_count;
}
Expand All @@ -3245,7 +3223,6 @@ void RouteOrch::flushBindFlowCounters(const RoutePattern &route_pattern, std::li
insertOrUpdateRouterFlowCounterCache(route_pattern, ctx.ip_prefix, ctx.counter_oid, mPendingAddToFlexCntr);
if (was_empty)
{
SWSS_LOG_WARN("Started counter update timer"); // TODO: REMOVE ME
mFlexCounterUpdTimer->start();
}
}
Expand Down
Loading

0 comments on commit 607329f

Please sign in to comment.