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

[cbf] Add class-based forwarding support #1963

Merged
merged 29 commits into from
Nov 16, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixes
TACappleman committed Nov 13, 2021

Verified

This commit was signed with the committer’s verified signature.
kenjis kenjis
commit 93d726b3ef6c6c3da59174f15dc55a4c36b21d2f
15 changes: 14 additions & 1 deletion orchagent/cbf/cbfnhgorch.cpp
Original file line number Diff line number Diff line change
@@ -314,7 +314,13 @@ bool CbfNhg::sync()

if (nhg_attr.value.oid == SAI_NULL_OBJECT_ID)
{
SWSS_LOG_WARN("FC to NHG map index %s does not exist", m_selection_map.c_str());
SWSS_LOG_ERROR("FC to NHG map index %s does not exist", m_selection_map.c_str());
return false;
}

if ((unsigned int)gNhgMapOrch->getLargestNhIndex(m_selection_map) > m_members.size())
{
SWSS_LOG_ERROR("FC to NHG map references more NHG members than exist in group %s", m_key.c_str());
return false;
}

@@ -525,6 +531,13 @@ bool CbfNhg::update(const vector<string> &members, const string &selection_map)
m_members.emplace(member, CbfNhgMember(member, index++));
}

if ((unsigned int)gNhgMapOrch->getLargestNhIndex(m_selection_map) > m_members.size())
{
SWSS_LOG_ERROR("FC to NHG map references more NHG members than exist in group %s",
m_key.c_str());
return false;
}

/* Sync the new members. */
if (!syncMembers({members.begin(), members.end()}))
{
26 changes: 23 additions & 3 deletions orchagent/cbf/nhgmaporch.cpp
Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@ extern sai_switch_api_t *sai_switch_api;

uint64_t NhgMapOrch::m_max_nhg_map_count = 0;

NhgMapEntry::NhgMapEntry(sai_object_id_t _id, uint32_t _ref_count) : id(_id), ref_count(_ref_count)
NhgMapEntry::NhgMapEntry(sai_object_id_t _id, uint32_t _ref_count, int _largest_nh_index) :
id(_id), ref_count(_ref_count), largest_nh_index(_largest_nh_index)
{
SWSS_LOG_ENTER();
}
@@ -68,15 +69,21 @@ void NhgMapOrch::doTask(Consumer &consumer)
else
{
/*
* Create the SAI map.
* Create the SAI map. Also track the largest index referenced by the map as we do.
*/
auto *fc_map = new sai_map_t[p.second.size()];
uint32_t ii = 0;
int largest_nh_index = 0;

for (const auto &fc_nh_idx : p.second)
{
fc_map[ii].key = fc_nh_idx.first;
fc_map[ii++].value = fc_nh_idx.second;

if (fc_nh_idx.second > largest_nh_index)
{
largest_nh_index = fc_nh_idx.second;
}
}

sai_map_list_t fc_map_list;
@@ -130,7 +137,8 @@ void NhgMapOrch::doTask(Consumer &consumer)
else
{
assert(nhg_map_id != SAI_NULL_OBJECT_ID);
m_syncdMaps.emplace(move(index), nhg_map_id);
NhgMapEntry entry(nhg_map_id, 0, largest_nh_index);
m_syncdMaps.emplace(move(index), entry);
}
}
}
@@ -239,6 +247,18 @@ sai_object_id_t NhgMapOrch::getMapId(const string &index) const
return it == m_syncdMaps.end() ? SAI_NULL_OBJECT_ID : it->second.id;
}

/*
* Return the largest NH index used by the map indexed by "index". If it does not exist, return 0.
*/
int NhgMapOrch::getLargestNhIndex(const string &index) const
{
SWSS_LOG_ENTER();

auto it = m_syncdMaps.find(index);

return it == m_syncdMaps.end() ? 0 : it->second.largest_nh_index;
}

/*
* Increase reference counter for a map.
*/
6 changes: 5 additions & 1 deletion orchagent/cbf/nhgmaporch.h
Original file line number Diff line number Diff line change
@@ -17,7 +17,10 @@ struct NhgMapEntry
/* Number of external objects referencing this next hop group map. */
uint32_t ref_count;

explicit NhgMapEntry(sai_object_id_t id, uint32_t _ref_count = 0);
/* The largest group index referenced by the map. */
int largest_nh_index;

explicit NhgMapEntry(sai_object_id_t id, uint32_t _ref_count, int _largest_nh_index);
};

class NhgMapOrch : public Orch
@@ -31,6 +34,7 @@ class NhgMapOrch : public Orch
* Return the SAI ID for the map indexed by "index". If it does not exist, return SAI_NULL_OBJECT_ID.
*/
sai_object_id_t getMapId(const string &key) const;
int getLargestNhIndex(const string &key) const;

/*
* Increase / Decrease reference counter for a map.
56 changes: 13 additions & 43 deletions orchagent/mplsrouteorch.cpp
Original file line number Diff line number Diff line change
@@ -253,25 +253,18 @@ void RouteOrch::doLabelTask(Consumer& consumer)
}
else
{
const NhgBase *nh_group;

if (gNhgOrch->hasNhg(nhg_index))
try
{
nh_group = &gNhgOrch->getNhg(nhg_index);
const NhgBase& nh_group = getNhg(nhg_index);
ctx.nhg = nh_group.getNhgKey();
ctx.using_temp_nhg = nh_group.isTemp();
}
else if (gCbfNhgOrch->hasNhg(nhg_index))
{
nh_group = &gCbfNhgOrch->getNhg(nhg_index);
}
else
catch (const std::out_of_range& e)
{
SWSS_LOG_ERROR("Next hop group %s does not exist", nhg_index.c_str());
++it;
continue;
}

ctx.nhg = nh_group->getNhgKey();
ctx.using_temp_nhg = nh_group->isTemp();
}

NextHopGroupKey& nhg = ctx.nhg;
@@ -485,23 +478,16 @@ bool RouteOrch::addLabelRoute(LabelRouteBulkContext& ctx, const NextHopGroupKey

if (!ctx.nhg_index.empty())
{
const NhgBase *nhg;

if (gNhgOrch->hasNhg(ctx.nhg_index))
{
nhg = &gNhgOrch->getNhg(ctx.nhg_index);
}
else if (gCbfNhgOrch->hasNhg(ctx.nhg_index))
try
{
nhg = &gCbfNhgOrch->getNhg(ctx.nhg_index);
const NhgBase& nhg = getNhg(ctx.nhg_index);
next_hop_id = nhg.getId();
}
else
catch(const std::out_of_range& e)
{
SWSS_LOG_WARN("Next hop group key %s does not exist", ctx.nhg_index.c_str());
return false;
}

next_hop_id = nhg->getId();
}
else if (nextHops.getSize() == 0)
{
@@ -761,13 +747,9 @@ bool RouteOrch::addLabelRoutePost(const LabelRouteBulkContext& ctx, const NextHo
{
increaseNextHopRefCount(nextHops);
}
else if (gNhgOrch->hasNhg(ctx.nhg_index))
{
gNhgOrch->incNhgRefCount(ctx.nhg_index);
}
else
{
gCbfNhgOrch->incNhgRefCount(ctx.nhg_index);
incNhgRefCount(ctx.nhg_index);
}

SWSS_LOG_INFO("Post create label %u with next hop(s) %s",
@@ -816,27 +798,19 @@ bool RouteOrch::addLabelRoutePost(const LabelRouteBulkContext& ctx, const NextHo
}
}
/* The next hop group is owned by (Cbf)NhgOrch. */
else if (gNhgOrch->hasNhg(it_route->second.nhg_index))
{
gNhgOrch->decNhgRefCount(it_route->second.nhg_index);
}
else
{
gCbfNhgOrch->decNhgRefCount(it_route->second.nhg_index);
decNhgRefCount(it_route->second.nhg_index);
}

/* Increase the ref_count for the next hop (group) entry */
if (ctx.nhg_index.empty())
{
increaseNextHopRefCount(nextHops);
}
else if (gNhgOrch->hasNhg(ctx.nhg_index))
{
gNhgOrch->incNhgRefCount(ctx.nhg_index);
}
else
{
gCbfNhgOrch->incNhgRefCount(ctx.nhg_index);
incNhgRefCount(ctx.nhg_index);
}

if (blackhole)
@@ -956,13 +930,9 @@ bool RouteOrch::removeLabelRoutePost(const LabelRouteBulkContext& ctx)
}
}
}
else if (gNhgOrch->hasNhg(it_route->second.nhg_index))
{
gNhgOrch->decNhgRefCount(it_route->second.nhg_index);
}
else
{
gCbfNhgOrch->decNhgRefCount(it_route->second.nhg_index);
decNhgRefCount(it_route->second.nhg_index);
}

SWSS_LOG_INFO("Remove label route %u with next hop(s) %s",
101 changes: 55 additions & 46 deletions orchagent/routeorch.cpp
Original file line number Diff line number Diff line change
@@ -761,25 +761,18 @@ void RouteOrch::doTask(Consumer& consumer)
}
else
{
const NhgBase *nh_group;

if (gNhgOrch->hasNhg(nhg_index))
{
nh_group = &gNhgOrch->getNhg(nhg_index);
}
else if (gCbfNhgOrch->hasNhg(nhg_index))
try
{
nh_group = &gCbfNhgOrch->getNhg(nhg_index);
const NhgBase& nh_group = getNhg(nhg_index);
nhg = nh_group.getNhgKey();
ctx.using_temp_nhg = nh_group.isTemp();
}
else
catch (const std::out_of_range& e)
{
SWSS_LOG_ERROR("Next hop group %s does not exist", nhg_index.c_str());
++it;
continue;
}

nhg = nh_group->getNhgKey();
ctx.using_temp_nhg = nh_group->isTemp();
}

if (nhg.getSize() == 1 && nhg.hasIntfNextHop())
@@ -1637,23 +1630,16 @@ bool RouteOrch::addRoute(RouteBulkContext& ctx, const NextHopGroupKey &nextHops)
/* NhgOrch owns the NHG */
else if (!ctx.nhg_index.empty())
{
const NhgBase *nhg;

if (gNhgOrch->hasNhg(ctx.nhg_index))
try
{
nhg = &gNhgOrch->getNhg(ctx.nhg_index);
const NhgBase& nhg = getNhg(ctx.nhg_index);
next_hop_id = nhg.getId();
}
else if (gCbfNhgOrch->hasNhg(ctx.nhg_index))
{
nhg = &gCbfNhgOrch->getNhg(ctx.nhg_index);
}
else
catch(const std::out_of_range& e)
{
SWSS_LOG_INFO("Next hop group key %s does not exist", ctx.nhg_index.c_str());
return false;
}

next_hop_id = nhg->getId();
}
/* RouteOrch owns the NHG */
else if (nextHops.getSize() == 0)
@@ -2044,13 +2030,9 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
{
increaseNextHopRefCount(nextHops);
}
else if (gNhgOrch->hasNhg(ctx.nhg_index))
{
gNhgOrch->incNhgRefCount(ctx.nhg_index);
}
else
{
gCbfNhgOrch->incNhgRefCount(ctx.nhg_index);
incNhgRefCount(ctx.nhg_index);
}

SWSS_LOG_INFO("Post create route %s with next hop(s) %s",
@@ -2120,13 +2102,9 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
}
}
/* The next hop group is owned by (Cbf)NhgOrch. */
else if (gNhgOrch->hasNhg(it_route->second.nhg_index))
{
gNhgOrch->decNhgRefCount(it_route->second.nhg_index);
}
else
{
gCbfNhgOrch->decNhgRefCount(it_route->second.nhg_index);
decNhgRefCount(it_route->second.nhg_index);
}

if (blackhole)
@@ -2150,13 +2128,9 @@ bool RouteOrch::addRoutePost(const RouteBulkContext& ctx, const NextHopGroupKey
/* Increase the ref_count for the next hop (group) entry */
increaseNextHopRefCount(nextHops);
}
else if (gNhgOrch->hasNhg(ctx.nhg_index))
{
gNhgOrch->incNhgRefCount(ctx.nhg_index);
}
else
{
gCbfNhgOrch->incNhgRefCount(ctx.nhg_index);
incNhgRefCount(ctx.nhg_index);
}

SWSS_LOG_INFO("Post set route %s with next hop(s) %s",
@@ -2321,14 +2295,7 @@ bool RouteOrch::removeRoutePost(const RouteBulkContext& ctx)
/* Check if the next hop group is not owned by NhgOrch. */
else if (!it_route->second.nhg_index.empty())
{
if (gNhgOrch->hasNhg(it_route->second.nhg_index))
{
gNhgOrch->decNhgRefCount(it_route->second.nhg_index);
}
else
{
gCbfNhgOrch->decNhgRefCount(it_route->second.nhg_index);
}
decNhgRefCount(it_route->second.nhg_index);
}
/* The NHG is owned by RouteOrch */
else
@@ -2487,3 +2454,45 @@ bool RouteOrch::checkNextHopGroupCount()
{
return m_nextHopGroupCount < m_maxNextHopGroupCount;
}

const NhgBase &RouteOrch::getNhg(const std::string &nhg_index)
{
SWSS_LOG_ENTER();

try
{
return gNhgOrch->getNhg(nhg_index);
}
catch (const std::out_of_range& e)
{
return gCbfNhgOrch->getNhg(nhg_index);
}
}

void RouteOrch::incNhgRefCount(const std::string &nhg_index)
{
SWSS_LOG_ENTER();

if (gNhgOrch->hasNhg(nhg_index))
{
gNhgOrch->incNhgRefCount(nhg_index);
}
else
{
gCbfNhgOrch->incNhgRefCount(nhg_index);
}
}

void RouteOrch::decNhgRefCount(const std::string &nhg_index)
{
SWSS_LOG_ENTER();

if (gNhgOrch->hasNhg(nhg_index))
{
gNhgOrch->decNhgRefCount(nhg_index);
}
else
{
gCbfNhgOrch->decNhgRefCount(nhg_index);
}
}
6 changes: 6 additions & 0 deletions orchagent/routeorch.h
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@

typedef std::map<NextHopKey, sai_object_id_t> NextHopGroupMembers;

struct NhgBase;

struct NextHopGroupEntry
{
sai_object_id_t next_hop_group_id; // next hop group id
@@ -251,6 +253,10 @@ class RouteOrch : public Orch, public Subject

void doTask(Consumer& consumer);
void doLabelTask(Consumer& consumer);

const NhgBase &getNhg(const std::string& nhg_index);
void incNhgRefCount(const std::string& nhg_index);
void decNhgRefCount(const std::string& nhg_index);
};

#endif /* SWSS_ROUTEORCH_H */