Skip to content

Commit

Permalink
Add config-read and run thread_birds with arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Markuu-s committed Dec 28, 2024
1 parent 8581dc1 commit 17e89f6
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 16 deletions.
29 changes: 29 additions & 0 deletions common/controlplaneconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ class interface_t
common::globalBase::tFlow flow;
};

class bird_import_t
{
public:
void pop(common::stream_in_t& stream)
{
stream.pop(socket);
stream.pop(vrf);
stream.pop(flow);
}

void push(common::stream_out_t& stream) const
{
stream.push(socket);
stream.push(vrf);
stream.push(flow);
}

public:
inline static const std::string socketStr = "socket";
inline static const std::string vrfStr = "vrf";

std::string socket;
std::string vrf;
common::globalBase::tFlow flow;
};

class config_t
{
public:
Expand Down Expand Up @@ -168,6 +194,7 @@ class config_t
stream.pop(local_prefixes);
stream.pop(peers);
stream.pop(interfaces);
stream.pop(bird_imports);
}

void push(common::stream_out_t& stream) const
Expand All @@ -183,6 +210,7 @@ class config_t
stream.push(local_prefixes);
stream.push(peers);
stream.push(interfaces);
stream.push(bird_imports);
}

public:
Expand All @@ -197,6 +225,7 @@ class config_t
std::set<common::ip_prefix_t> local_prefixes; ///< for fallback to default
std::map<uint32_t, std::string> peers;
std::map<std::string, interface_t> interfaces;
std::vector<bird_import_t> bird_imports;
};

}
Expand Down
33 changes: 33 additions & 0 deletions controlplane/configparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ controlplane::base_t config_parser_t::loadConfig(const std::string& rootFilePath
return baseNext;
}

void config_parser_t::loadConfig_route_bird(controlplane::base_t& baseNext,
std::vector<controlplane::route::bird_import_t>& birdsImport,
const nlohmann::json& birdJson)
{
using BirdImport = controlplane::route::bird_import_t;
for (const auto& elemJson : birdJson)
{
BirdImport import;

if (exist(elemJson, BirdImport::socketStr))
{
import.socket = elemJson[BirdImport::socketStr];
}

if (exist(elemJson, BirdImport::vrfStr))
{
import.vrf = elemJson[BirdImport::vrfStr];
}

birdsImport.push_back(import);
YANET_LOG_INFO("loadConfig_route_bird: socket(%s), vrf(%s)\n",
import.socket.data(),
import.vrf.data());
}
}

void config_parser_t::loadConfig_logicalPort(controlplane::base_t& baseNext,
const std::string& moduleId,
const nlohmann::json& moduleJson)
Expand Down Expand Up @@ -367,6 +393,13 @@ void config_parser_t::loadConfig_route(controlplane::base_t& baseNext,
route.tunnel_enabled = false;
}

if (exist(moduleJson, "birdImport"))
{
loadConfig_route_bird(baseNext,
route.bird_imports,
moduleJson["birdImport"]);
}

//

route.routeId = routeId;
Expand Down
1 change: 1 addition & 0 deletions controlplane/configparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class config_parser_t
void loadConfig_logicalPort(controlplane::base_t& baseNext, const std::string& moduleId, const nlohmann::json& moduleJson);
void loadConfig_route(controlplane::base_t& baseNext, const std::string& moduleId, const nlohmann::json& moduleJson, const std::string& rootFilePath, const std::map<std::string, nlohmann::json>& jsons);
void loadConfig_route_peers(controlplane::base_t& baseNext, controlplane::route::config_t& route, const nlohmann::json& json, const std::string& rootFilePath, const std::map<std::string, nlohmann::json>& jsons);
void loadConfig_route_bird(controlplane::base_t& baseNext, std::vector<controlplane::route::bird_import_t>& birdsImport, const nlohmann::json& birdJson);
void loadConfig_decap(controlplane::base_t& baseNext, const std::string& moduleId, const nlohmann::json& moduleJson);
void loadConfig_nat64stateful(controlplane::base_t& baseNext, const std::string& moduleId, const nlohmann::json& moduleJson, const std::string& rootFilePath, const std::map<std::string, nlohmann::json>& jsons);
void loadConfig_nat64stateless(controlplane::base_t& baseNext, const std::string& moduleId, const nlohmann::json& moduleJson, const std::string& rootFilePath, const std::map<std::string, nlohmann::json>& jsons);
Expand Down
18 changes: 18 additions & 0 deletions controlplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,18 @@ common::icp::controlplane_values::response cControlPlane::controlplane_values()
return response;
}

common::icp::route_config::response cControlPlane::getRoute() const
{
common::icp::route_config::response response;

{
auto current_guard = generations.current_lock_guard();
response = generations.current().routes;
}

return response;
}

common::icp::getDecapPrefixes::response cControlPlane::command_getDecapPrefixes()
{
common::icp::getDecapPrefixes::response response;
Expand Down Expand Up @@ -924,6 +936,12 @@ eResult cControlPlane::loadConfig(const std::string& rootFilePath,
}

YANET_LOG_INFO("dataplane has been updated (stage 7)\n");
for(auto& module : modules) {
if (rib_t* rib = dynamic_cast<rib_t*>(module)) {
rib->bird_import_get();
rib->moduleStart();
}
}
}
catch (const error_result_t& error)
{
Expand Down
1 change: 1 addition & 0 deletions controlplane/controlplane.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class cControlPlane
common::icp::acl_unwind::response acl_unwind(const common::icp::acl_unwind::request& request) const;
common::icp::acl_lookup::response acl_lookup(const common::icp::acl_lookup::request& request) const;
common::icp::controlplane_values::response controlplane_values() const;
common::icp::route_config::response getRoute() const;

common::icp::getDecapPrefixes::response command_getDecapPrefixes();
common::icp::getNat64statelessTranslations::response command_getNat64statelessTranslations();
Expand Down
45 changes: 30 additions & 15 deletions controlplane/rib.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "rib.h"
#include "libbird.h"
#include "controlplane.h"
#include "libbird.h"

#include <fcntl.h>

Expand Down Expand Up @@ -72,10 +72,6 @@ eResult rib_t::init()
rib_thread();
});

funcThreads.emplace_back([this]() {
bird_thread();
});

return eResult::success;
}

Expand Down Expand Up @@ -586,14 +582,14 @@ void rib_t::rib_flush(bool force_flush)

controlPlane->route.prefix_update(vrf_priority, updated_prefix, proto_peer_table_name, destination);
controlPlane->route.tunnel_prefix_update(vrf_priority, updated_prefix, destination);
//controlPlane->route.linux_prefix_update(vrf_priority, updated_prefix, destination);
// controlPlane->route.linux_prefix_update(vrf_priority, updated_prefix, destination);
controlPlane->dregress.prefix_insert(vrf_priority, updated_prefix, destination);
}
else
{
controlPlane->route.prefix_update(vrf_priority, updated_prefix, {}, std::monostate()); // TODO: get rid of third parameter
controlPlane->route.tunnel_prefix_update(vrf_priority, updated_prefix, std::monostate());
//controlPlane->route.linux_prefix_update(vrf_priority, updated_prefix, std::monostate());
// controlPlane->route.linux_prefix_update(vrf_priority, updated_prefix, std::monostate());
controlPlane->dregress.prefix_remove(vrf_priority, updated_prefix);
}
}
Expand Down Expand Up @@ -880,22 +876,41 @@ void rib_t::rib_thread()

std::this_thread::sleep_for(std::chrono::milliseconds{200});
}
}

void rib_t::bird_import_get()
{
auto route = controlPlane->getRoute();
for (auto& [vrf, response] : route)
{
(void)vrf;
auto imports = response.bird_imports;

for (auto& import : imports)
{
funcThreads.emplace_back([this, import]() {
bird_thread(import.socket, import.vrf);
});
}
}
}

void rib_t::bird_thread()
void rib_t::bird_thread(const std::string& socket, const std::string& vrf)
{
while (!flagStop) {
read_bird_feed("/tmp/export.sock", "default", this);
YANET_LOG_DEBUG("Run bird thread: socket(%s), vrf(%s)\n",
socket.data(),
vrf.data());
while (!flagStop)
{
read_bird_feed(socket.c_str(), vrf.c_str(), this);

common::icp::rib_update::clear request = {"bgp", std::nullopt};
/* std::get<1>(request) = {peer_address,
{"default", ///< @todo: vrf
YANET_RIB_PRIORITY_DEFAULT}};
*/
/* std::get<1>(request) = {peer_address,
{"default", ///< @todo: vrf
YANET_RIB_PRIORITY_DEFAULT}};
*/
rib_clear(request);

std::this_thread::sleep_for(std::chrono::milliseconds{200});
}

}
4 changes: 3 additions & 1 deletion controlplane/rib.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class rib_t : public cModule
common::icp::rib_summary::response rib_summary();
common::icp::rib_prefixes::response rib_prefixes();

void bird_import_get();

common::icp::rib_lookup::response rib_lookup(const common::icp::rib_lookup::request& request);
common::icp::rib_get::response rib_get(const common::icp::rib_get::request& request);
common::icp::rib_save::response rib_save();
Expand All @@ -62,7 +64,7 @@ class rib_t : public cModule
void rib_eor(const common::icp::rib_update::eor& request);

void rib_thread();
void bird_thread();
void bird_thread(const std::string& socket, const std::string& vrf);

protected:
mutable std::mutex rib_update_mutex;
Expand Down

0 comments on commit 17e89f6

Please sign in to comment.