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

Add config-read and run thread_birds with arguments. #265

Open
wants to merge 3 commits into
base: bird-import-proto
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 16 additions & 1 deletion common/controlplaneconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <nlohmann/json.hpp>

#include "balancer.h"
#include "define.h"
#include "scheduler.h"
#include "type.h"

Expand Down Expand Up @@ -104,6 +105,19 @@ class interface_t
common::globalBase::tFlow flow;
};

class bird_import_t
{
public:
SERIALIZABLE(socket, vrf);

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

std::string socket;
std::string vrf;
};

class config_t
{
public:
Expand All @@ -114,7 +128,7 @@ class config_t
nlohmann::json save() const;
*/

SERIALIZABLE(routeId, to_kernel_prefixes, vrf, tunnel_enabled, ignore_tables, ipv4_source_address, ipv6_source_address, udp_destination_port, local_prefixes, peers, interfaces);
SERIALIZABLE(routeId, to_kernel_prefixes, vrf, tunnel_enabled, ignore_tables, ipv4_source_address, ipv6_source_address, udp_destination_port, local_prefixes, peers, interfaces, bird_imports);

public:
tRouteId routeId;
Expand All @@ -128,6 +142,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 @@ -21,6 +21,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
20 changes: 20 additions & 0 deletions controlplane/controlplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,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 @@ -941,6 +953,14 @@ 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 @@ -106,6 +106,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
41 changes: 28 additions & 13 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 @@ -64,10 +64,6 @@ eResult rib_t::init()
rib_thread();
});

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

return eResult::success;
}

Expand Down Expand Up @@ -869,22 +865,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 @@ -34,6 +34,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 @@ -46,7 +48,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
Loading