Skip to content

Commit

Permalink
Fix based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stal76 committed Feb 17, 2025
1 parent 8336c86 commit d4674fe
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 44 deletions.
8 changes: 2 additions & 6 deletions common/controlplaneconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ class interface_t
class config_t
{
public:
config_t() :
vrf(YANET_RIB_VRF_DEFAULT),
tunnel_enabled(false)
{
}
config_t() = default;

/** @todo: tag:CP_MODULES
void load(const nlohmann::json& json);
Expand All @@ -123,7 +119,7 @@ class config_t
public:
tRouteId routeId;
std::set<common::ip_prefix_t> to_kernel_prefixes;
std::string vrf{"default"};
std::string vrf{YANET_RIB_VRF_DEFAULT};
bool tunnel_enabled{};
std::set<std::string> ignore_tables;
common::ipv4_address_t ipv4_source_address;
Expand Down
2 changes: 1 addition & 1 deletion common/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extern LogPriority logPriority;
#define YANET_RIB_PRIORITY_DEFAULT ((uint32_t)10000)
#define YANET_RIB_PRIORITY_ROUTE_TUNNEL_FALLBACK ((uint32_t)11000)
#define YANET_RIB_PRIORITY_ROUTE_REPEAT ((uint32_t)12000)
#define YANET_RIB_VRF_DEFAULT "default"
constexpr auto YANET_RIB_VRF_DEFAULT = "default";
#define YANET_RIB_VRF_MAX_NUMBER 64

#define YANET_DEFAULT_BGP_AS ((uint32_t)13238)
Expand Down
6 changes: 4 additions & 2 deletions controlplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ VrfIdStorage& cControlPlane::getVrfIdsStorage()
return vrfIds;
}

std::optional<tVrfId> VrfIdStorage::Get(const std::string& vrfName)
std::optional<tVrfId> VrfIdStorage::Get(const std::string& vrfName) const
{
if (vrfName.empty() || vrfName == YANET_RIB_VRF_DEFAULT)
{
Expand Down Expand Up @@ -1071,7 +1071,9 @@ tVrfId VrfIdStorage::GetOrCreateOrException(const std::string& vrfName, const st
std::optional<tVrfId> vrfId = GetOrCreate(vrfName);
if (!vrfId.has_value())
{
throw error_result_t(eResult::invalidVrfId, message + vrfName);
std::ostringstream oss;
oss << message << ": " << vrfName;
throw error_result_t(eResult::invalidVrfId, oss.str());
}
return *vrfId;
}
4 changes: 2 additions & 2 deletions controlplane/controlplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
class VrfIdStorage
{
public:
std::optional<tVrfId> Get(const std::string& vrfName);
std::optional<tVrfId> Get(const std::string& vrfName) const;
std::optional<tVrfId> GetOrCreate(const std::string& vrfName);
tVrfId GetOrCreateOrException(const std::string& vrfName, const std::string& message);

private:
std::shared_mutex mutex;
mutable std::shared_mutex mutex;
std::unordered_map<std::string, std::optional<tVrfId>> vrf_ids;
};

Expand Down
2 changes: 1 addition & 1 deletion controlplane/route.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class generation_t
}
}

bool is_ignored_table(const std::string& table_name) const
[[nodiscard]] bool is_ignored_table(const std::string& table_name) const
{
for (const auto& [name, module] : routes)
{
Expand Down
32 changes: 13 additions & 19 deletions dataplane/globalbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ eResult generation::init()
}

{
updater.vrf_route_lpm4 = std::make_unique<updater_vrf_lpm<uint32_t, vrf_lpm4>>("vrf_route.v4.lpm",
&dataPlane->memory_manager,
socketId);
updater.vrf_route_lpm4 = std::make_unique<updater_vrf_lpm4>("vrf_route.v4.lpm",
&dataPlane->memory_manager,
socketId);
result = updater.vrf_route_lpm4->init();
if (result != eResult::success)
{
Expand All @@ -246,9 +246,9 @@ eResult generation::init()
}

{
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);
updater.vrf_route_lpm6 = std::make_unique<updater_vrf_lpm6>("vrf_route.v6.lpm",
&dataPlane->memory_manager,
socketId);
result = updater.vrf_route_lpm6->init();
if (result != eResult::success)
{
Expand All @@ -259,9 +259,9 @@ eResult generation::init()
}

{
updater.vrf_route_tunnel_lpm4 = std::make_unique<updater_vrf_lpm<uint32_t, vrf_lpm4>>("vrf_route.tunnel.v4.lpm",
&dataPlane->memory_manager,
socketId);
updater.vrf_route_tunnel_lpm4 = std::make_unique<updater_vrf_lpm4>("vrf_route.tunnel.v4.lpm",
&dataPlane->memory_manager,
socketId);
result = updater.vrf_route_tunnel_lpm4->init();
if (result != eResult::success)
{
Expand All @@ -272,9 +272,9 @@ eResult generation::init()
}

{
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);
updater.vrf_route_tunnel_lpm6 = std::make_unique<updater_vrf_lpm6>("vrf_route.tunnel.v6.lpm",
&dataPlane->memory_manager,
socketId);
result = updater.vrf_route_tunnel_lpm6->init();
if (result != eResult::success)
{
Expand Down Expand Up @@ -828,13 +828,7 @@ static bool checkFlow(const common::globalBase::tFlow& flow)

eResult generation::updateLogicalPort(const common::idp::updateGlobalBase::updateLogicalPort::request& request)
{
const auto& logicalPortId = std::get<0>(request);
const auto& portId = std::get<1>(request);
const auto& vlanId = std::get<2>(request);
const auto& vrfId = std::get<3>(request);
const auto& etherAddress = std::get<4>(request);
const auto& promiscuousMode = std::get<5>(request);
const auto& flow = std::get<6>(request);
const auto& [logicalPortId, portId, vlanId, vrfId, etherAddress, promiscuousMode, flow] = request;

if (logicalPortId >= CONFIG_YADECAP_LOGICALPORTS_SIZE)
{
Expand Down
10 changes: 6 additions & 4 deletions dataplane/globalbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class generation
public:
using vrf_lpm4 = lpm4_24bit_8bit_atomic;
using vrf_lpm6 = lpm6_8x16bit_atomic;
using updater_vrf_lpm4 = updater_vrf_lpm<uint32_t, vrf_lpm4>;
using updater_vrf_lpm6 = updater_vrf_lpm<std::array<uint8_t, 16>, vrf_lpm6>;

generation(cDataPlane* dataPlane, const tSocketId& socketId);
~generation() = default;
Expand Down Expand Up @@ -218,10 +220,10 @@ class generation
std::unique_ptr<updater_lpm4_24bit_8bit> route_tunnel_lpm4;
std::unique_ptr<updater_lpm6_8x16bit> route_tunnel_lpm6;

std::unique_ptr<updater_vrf_lpm<uint32_t, vrf_lpm4>> vrf_route_lpm4;
std::unique_ptr<updater_vrf_lpm<std::array<uint8_t, 16>, vrf_lpm6>> vrf_route_lpm6;
std::unique_ptr<updater_vrf_lpm<uint32_t, vrf_lpm4>> vrf_route_tunnel_lpm4;
std::unique_ptr<updater_vrf_lpm<std::array<uint8_t, 16>, vrf_lpm6>> vrf_route_tunnel_lpm6;
std::unique_ptr<updater_vrf_lpm4> vrf_route_lpm4;
std::unique_ptr<updater_vrf_lpm6> vrf_route_lpm6;
std::unique_ptr<updater_vrf_lpm4> vrf_route_tunnel_lpm4;
std::unique_ptr<updater_vrf_lpm6> vrf_route_tunnel_lpm6;
} updater;

/// variables above are not needed for cWorker::mainThread()
Expand Down
26 changes: 21 additions & 5 deletions dataplane/updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "common.h"
#include "common/idp.h"
#include "common/static_vector.h"
#include "dynamic_table.h"
#include "hashtable.h"
#include "lpm.h"
Expand Down Expand Up @@ -673,10 +674,19 @@ class updater_array
template<typename Address, typename InnerLpmType>
class updater_vrf_lpm
{
public:
using stats_t = typename InnerLpmType::stats_t;
using UpdaterType = updater_lpm<Address, InnerLpmType>;

[[nodiscard]] memory_manager::unique_ptr<UpdaterType> Allocate(const std::string& name_vrf)
{
return memory_manager_->create_unique<UpdaterType>(name_.c_str(),
socket_id_,
sizeof(UpdaterType),
name_vrf.c_str(),
memory_manager_,
socket_id_);
}

public:
updater_vrf_lpm(const char* name,
dataplane::memory_manager* memory_manager,
tSocketId socket_id) :
Expand All @@ -688,6 +698,10 @@ class updater_vrf_lpm

eResult init()
{
for (size_t index = 0; index < updaters_.capacity(); index++)
{
updaters_.emplace_back(memory_manager::unique_ptr<UpdaterType>{nullptr, memory_manager_->deleter()});
}
return eResult::success;
}

Expand All @@ -702,8 +716,10 @@ class updater_vrf_lpm
}
if (updaters_[vrf] == nullptr)
{
std::string name = std::string(name_) + ".vrf" + std::to_string(vrf);
updaters_[vrf] = std::make_unique<UpdaterType>(name.c_str(), memory_manager_, socket_id_);
std::ostringstream oss;
oss << name_ << ".vrf" << vrf;
std::string name = oss.str();
updaters_[vrf] = Allocate(name);
if (updaters_[vrf] == nullptr)
{
return eResult::errorAllocatingMemory;
Expand Down Expand Up @@ -781,7 +797,7 @@ class updater_vrf_lpm
std::string name_;
dataplane::memory_manager* memory_manager_;
tSocketId socket_id_;
std::array<std::unique_ptr<UpdaterType>, YANET_RIB_VRF_MAX_NUMBER> updaters_;
utils::StaticVector<memory_manager::unique_ptr<UpdaterType>, YANET_RIB_VRF_MAX_NUMBER> updaters_;
};

}
8 changes: 4 additions & 4 deletions librib/libyabird.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void libyabird_t::set_state(const char* peer, int state)
common::icp::rib_update::clear request = {"bgp", std::nullopt};

std::get<1>(request) = {peer_address,
{"default", ///< @todo: vrf
{YANET_RIB_VRF_DEFAULT,
YANET_RIB_PRIORITY_DEFAULT}};

{
Expand Down Expand Up @@ -163,7 +163,7 @@ void libyabird_t::update(yanet_data_t* data)

{
common::icp::rib_update::eor request = {"bgp",
"default",
YANET_RIB_VRF_DEFAULT,
YANET_RIB_PRIORITY_DEFAULT,
peer_address,
table_name};
Expand Down Expand Up @@ -234,7 +234,7 @@ void libyabird_t::update(yanet_data_t* data)
std::holds_alternative<common::icp::rib_update::insert>(rib_request.back())))
{
common::icp::rib_update::insert request = {"bgp",
"default", ///< @todo: vrf
YANET_RIB_VRF_DEFAULT,
YANET_RIB_PRIORITY_DEFAULT,
{}};

Expand Down Expand Up @@ -293,7 +293,7 @@ void libyabird_t::update(yanet_data_t* data)
std::holds_alternative<common::icp::rib_update::remove>(rib_request.back())))
{
common::icp::rib_update::remove request = {"bgp",
"default", ///< @todo: vrf
YANET_RIB_VRF_DEFAULT,
YANET_RIB_PRIORITY_DEFAULT,
{}};
rib_request.emplace_back(request);
Expand Down

0 comments on commit d4674fe

Please sign in to comment.