Skip to content

Commit

Permalink
Added forwarding of route information from controlplane to dataplane
Browse files Browse the repository at this point in the history
  • Loading branch information
stal76 committed Dec 22, 2024
1 parent 46e33be commit 22de5cc
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 32 deletions.
7 changes: 4 additions & 3 deletions common/idp.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ using remove = std::vector<ip_prefix_t>;

using clear = std::tuple<>;

using request = std::vector<std::variant<insert,
remove,
clear>>;
using request = std::vector<std::tuple<tVrfId,
std::variant<insert,
remove,
clear>>>;
}

namespace updateGlobalBase
Expand Down
24 changes: 17 additions & 7 deletions controlplane/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ eResult route_t::init()
{
common::idp::updateGlobalBase::request globalbase;
globalbase.emplace_back(common::idp::updateGlobalBase::requestType::route_lpm_update,
common::idp::lpm::request({common::idp::lpm::clear()}));
common::idp::lpm::request({{0, common::idp::lpm::clear()}}));
dataplane.updateGlobalBase(std::move(globalbase));
}

Expand Down Expand Up @@ -1015,7 +1015,12 @@ void route_t::prefix_flush_prefixes(common::idp::updateGlobalBase::request& glob

for (auto& [vrf, priority_current_update] : prefixes)
{
YANET_GCC_BUG_UNUSED(vrf); ///< @todo: VRF
std::optional<tVrfId> vrfId = controlPlane->getVrfIdsStorage().GetOrCreate(vrf);
if (!vrfId.has_value())
{
YANET_LOG_DEBUG("Can't get id for vrf: '%s'\n", vrf.c_str());
continue;
}

auto& [priority_current, update] = priority_current_update;

Expand All @@ -1032,7 +1037,7 @@ void route_t::prefix_flush_prefixes(common::idp::updateGlobalBase::request& glob

if (lpm_remove.size())
{
lpm_request.emplace_back(lpm_remove);
lpm_request.emplace_back(*vrfId, lpm_remove);
}
}

Expand All @@ -1054,7 +1059,7 @@ void route_t::prefix_flush_prefixes(common::idp::updateGlobalBase::request& glob

if (lpm_insert.size())
{
lpm_request.emplace_back(lpm_insert);
lpm_request.emplace_back(*vrfId, lpm_insert);
}
}
}
Expand All @@ -1081,7 +1086,12 @@ void route_t::tunnel_prefix_flush_prefixes(common::idp::updateGlobalBase::reques

for (auto& [vrf, priority_current_update] : tunnel_prefixes)
{
YANET_GCC_BUG_UNUSED(vrf); ///< @todo: VRF
std::optional<tVrfId> vrfId = controlPlane->getVrfIdsStorage().GetOrCreate(vrf);
if (!vrfId.has_value())
{
YANET_LOG_DEBUG("Can't get id for vrf: '%s'\n", vrf.c_str());
continue;
}

auto& [priority_current, update] = priority_current_update;

Expand All @@ -1098,7 +1108,7 @@ void route_t::tunnel_prefix_flush_prefixes(common::idp::updateGlobalBase::reques

if (lpm_remove.size())
{
lpm_request.emplace_back(lpm_remove);
lpm_request.emplace_back(*vrfId, lpm_remove);
}
}

Expand All @@ -1120,7 +1130,7 @@ void route_t::tunnel_prefix_flush_prefixes(common::idp::updateGlobalBase::reques

if (lpm_insert.size())
{
lpm_request.emplace_back(lpm_insert);
lpm_request.emplace_back(*vrfId, lpm_insert);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions dataplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ common::idp::limits::response cControlPlane::limits()
globalBase->updater.route_lpm6->limits(response);
globalBase->updater.route_tunnel_lpm4->limits(response);
globalBase->updater.route_tunnel_lpm6->limits(response);
globalBase->updater.vrf_route_lpm4->limits(response);
globalBase->updater.vrf_route_lpm6->limits(response);
globalBase->updater.vrf_route_tunnel_lpm4->limits(response);
globalBase->updater.vrf_route_tunnel_lpm6->limits(response);

globalBase->updater.acl.network_table->limits(response);
globalBase->updater.acl.transport_table->limits(response);
Expand Down
184 changes: 162 additions & 22 deletions dataplane/globalbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,58 @@ eResult generation::init()
route_tunnel_lpm6 = updater.route_tunnel_lpm6->pointer();
}

{
updater.vrf_route_lpm4 = std::make_unique<updater_vrf_lpm<uint32_t, vrf_lpm4>>("vrf_route.v4.lpm",
&dataPlane->memory_manager,
socketId);
result = updater.vrf_route_lpm4->init();
if (result != eResult::success)
{
return result;
}

vrf_route_lpm4.Update(updater.vrf_route_lpm4->GetLpms());
}

{
updater.vrf_route_lpm6 = std::make_unique<updater_vrf_lpm<std::array<uint8_t, 16>, vrf_lpm6>>("vrf_route.v6.lpm",
&dataPlane->memory_manager,
socketId);
result = updater.vrf_route_lpm6->init();
if (result != eResult::success)
{
return result;
}

vrf_route_lpm6.Update(updater.vrf_route_lpm6->GetLpms());
}

{
updater.vrf_route_tunnel_lpm4 = std::make_unique<updater_vrf_lpm<uint32_t, vrf_lpm4>>("vrf_route.tunnel.v4.lpm",
&dataPlane->memory_manager,
socketId);
result = updater.vrf_route_tunnel_lpm4->init();
if (result != eResult::success)
{
return result;
}

vrf_route_tunnel_lpm4.Update(updater.vrf_route_tunnel_lpm4->GetLpms());
}

{
updater.vrf_route_tunnel_lpm6 = std::make_unique<updater_vrf_lpm<std::array<uint8_t, 16>, vrf_lpm6>>("vrf_route.tunnel.v6.lpm",
&dataPlane->memory_manager,
socketId);
result = updater.vrf_route_tunnel_lpm6->init();
if (result != eResult::success)
{
return result;
}

vrf_route_tunnel_lpm6.Update(updater.vrf_route_tunnel_lpm6->GetLpms());
}

return result;
}

Expand Down Expand Up @@ -1711,23 +1763,43 @@ eResult generation::route_lpm_update(const common::idp::updateGlobalBase::route_
{
eResult result = eResult::success;

for (const auto& action : request)
for (const auto& [vrfId, action] : request)
{
if (const auto update = std::get_if<common::idp::lpm::insert>(&action))
{
for (const auto& [prefix, value_id] : *update)
{
if (prefix.is_ipv4())
{
result = updater.route_lpm4->insert(prefix.get_ipv4().address(),
prefix.get_ipv4().mask(),
value_id);
if (vrfId == 0)
{
result = updater.route_lpm4->insert(prefix.get_ipv4().address(),
prefix.get_ipv4().mask(),
value_id);
}
else
{
result = updater.vrf_route_lpm4->insert(vrfId,
prefix.get_ipv4().address(),
prefix.get_ipv4().mask(),
value_id);
}
}
else
{
result = updater.route_lpm6->insert(prefix.get_ipv6().address(),
prefix.get_ipv6().mask(),
value_id);
if (vrfId == 0)
{
result = updater.route_lpm6->insert(prefix.get_ipv6().address(),
prefix.get_ipv6().mask(),
value_id);
}
else
{
result = updater.vrf_route_lpm6->insert(vrfId,
prefix.get_ipv6().address(),
prefix.get_ipv6().mask(),
value_id);
}
}

if (result != eResult::success)
Expand All @@ -1742,13 +1814,31 @@ eResult generation::route_lpm_update(const common::idp::updateGlobalBase::route_
{
if (prefix.is_ipv4())
{
result = updater.route_lpm4->remove(prefix.get_ipv4().address(),
prefix.get_ipv4().mask());
if (vrfId == 0)
{
result = updater.route_lpm4->remove(prefix.get_ipv4().address(),
prefix.get_ipv4().mask());
}
else
{
result = updater.vrf_route_lpm4->remove(vrfId,
prefix.get_ipv4().address(),
prefix.get_ipv4().mask());
}
}
else
{
result = updater.route_lpm6->remove(prefix.get_ipv6().address(),
prefix.get_ipv6().mask());
if (vrfId == 0)
{
result = updater.route_lpm6->remove(prefix.get_ipv6().address(),
prefix.get_ipv6().mask());
}
else
{
result = updater.vrf_route_lpm6->remove(vrfId,
prefix.get_ipv6().address(),
prefix.get_ipv6().mask());
}
}

if (result != eResult::success)
Expand All @@ -1764,13 +1854,19 @@ eResult generation::route_lpm_update(const common::idp::updateGlobalBase::route_
updater.route_lpm4->clear();
updater.route_lpm6->clear();

updater.vrf_route_lpm4->clear();
updater.vrf_route_lpm6->clear();

return eResult::success;
}
}

route_lpm4 = updater.route_lpm4->pointer();
route_lpm6 = updater.route_lpm6->pointer();

vrf_route_lpm4.Update(updater.vrf_route_lpm4->GetLpms());
vrf_route_lpm6.Update(updater.vrf_route_lpm6->GetLpms());

return result;
}

Expand Down Expand Up @@ -1877,23 +1973,43 @@ eResult generation::route_tunnel_lpm_update(const common::idp::updateGlobalBase:
{
eResult result = eResult::success;

for (const auto& action : request)
for (const auto& [vrfId, action] : request)
{
if (const auto update = std::get_if<common::idp::lpm::insert>(&action))
{
for (const auto& [prefix, value_id] : *update)
{
if (prefix.is_ipv4())
{
result = updater.route_tunnel_lpm4->insert(prefix.get_ipv4().address(),
prefix.get_ipv4().mask(),
value_id);
if (vrfId == 0)
{
result = updater.route_tunnel_lpm4->insert(prefix.get_ipv4().address(),
prefix.get_ipv4().mask(),
value_id);
}
else
{
result = updater.vrf_route_tunnel_lpm4->insert(vrfId,
prefix.get_ipv4().address(),
prefix.get_ipv4().mask(),
value_id);
}
}
else
{
result = updater.route_tunnel_lpm6->insert(prefix.get_ipv6().address(),
prefix.get_ipv6().mask(),
value_id);
if (vrfId == 0)
{
result = updater.route_tunnel_lpm6->insert(prefix.get_ipv6().address(),
prefix.get_ipv6().mask(),
value_id);
}
else
{
result = updater.vrf_route_tunnel_lpm6->insert(vrfId,
prefix.get_ipv6().address(),
prefix.get_ipv6().mask(),
value_id);
}
}

if (result != eResult::success)
Expand All @@ -1908,13 +2024,31 @@ eResult generation::route_tunnel_lpm_update(const common::idp::updateGlobalBase:
{
if (prefix.is_ipv4())
{
result = updater.route_tunnel_lpm4->remove(prefix.get_ipv4().address(),
prefix.get_ipv4().mask());
if (vrfId == 0)
{
result = updater.route_tunnel_lpm4->remove(prefix.get_ipv4().address(),
prefix.get_ipv4().mask());
}
else
{
result = updater.vrf_route_tunnel_lpm4->remove(vrfId,
prefix.get_ipv4().address(),
prefix.get_ipv4().mask());
}
}
else
{
result = updater.route_tunnel_lpm6->remove(prefix.get_ipv6().address(),
prefix.get_ipv6().mask());
if (vrfId == 0)
{
result = updater.route_tunnel_lpm6->remove(prefix.get_ipv6().address(),
prefix.get_ipv6().mask());
}
else
{
result = updater.vrf_route_tunnel_lpm6->remove(vrfId,
prefix.get_ipv6().address(),
prefix.get_ipv6().mask());
}
}

if (result != eResult::success)
Expand All @@ -1930,13 +2064,19 @@ eResult generation::route_tunnel_lpm_update(const common::idp::updateGlobalBase:
updater.route_tunnel_lpm4->clear();
updater.route_tunnel_lpm6->clear();

updater.vrf_route_tunnel_lpm4->clear();
updater.vrf_route_tunnel_lpm6->clear();

return eResult::success;
}
}

route_tunnel_lpm4 = updater.route_tunnel_lpm4->pointer();
route_tunnel_lpm6 = updater.route_tunnel_lpm6->pointer();

vrf_route_tunnel_lpm4.Update(updater.vrf_route_tunnel_lpm4->GetLpms());
vrf_route_tunnel_lpm6.Update(updater.vrf_route_tunnel_lpm6->GetLpms());

return result;
}

Expand Down
Loading

0 comments on commit 22de5cc

Please sign in to comment.