diff --git a/common/controlplaneconfig.h b/common/controlplaneconfig.h index a763589f..d68a84f8 100644 --- a/common/controlplaneconfig.h +++ b/common/controlplaneconfig.h @@ -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: @@ -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 @@ -183,6 +210,7 @@ class config_t stream.push(local_prefixes); stream.push(peers); stream.push(interfaces); + stream.push(bird_imports); } public: @@ -197,6 +225,7 @@ class config_t std::set local_prefixes; ///< for fallback to default std::map peers; std::map interfaces; + std::vector bird_imports; }; } diff --git a/controlplane/configparser.cpp b/controlplane/configparser.cpp index af331d5e..a21d25ea 100644 --- a/controlplane/configparser.cpp +++ b/controlplane/configparser.cpp @@ -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& 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) @@ -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; diff --git a/controlplane/configparser.h b/controlplane/configparser.h index ad8af05f..65284ff9 100644 --- a/controlplane/configparser.h +++ b/controlplane/configparser.h @@ -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& 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& jsons); + void loadConfig_route_bird(controlplane::base_t& baseNext, std::vector& 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& jsons); void loadConfig_nat64stateless(controlplane::base_t& baseNext, const std::string& moduleId, const nlohmann::json& moduleJson, const std::string& rootFilePath, const std::map& jsons); diff --git a/controlplane/controlplane.cpp b/controlplane/controlplane.cpp index d8919c29..ad22d461 100644 --- a/controlplane/controlplane.cpp +++ b/controlplane/controlplane.cpp @@ -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; @@ -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(module)) { + rib->bird_import_get(); + rib->moduleStart(); + } + } } catch (const error_result_t& error) { diff --git a/controlplane/controlplane.h b/controlplane/controlplane.h index 8d038a22..89d3c593 100644 --- a/controlplane/controlplane.h +++ b/controlplane/controlplane.h @@ -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(); diff --git a/controlplane/rib.cpp b/controlplane/rib.cpp index 4d531545..a5379f3b 100644 --- a/controlplane/rib.cpp +++ b/controlplane/rib.cpp @@ -1,6 +1,6 @@ #include "rib.h" -#include "libbird.h" #include "controlplane.h" +#include "libbird.h" #include @@ -72,10 +72,6 @@ eResult rib_t::init() rib_thread(); }); - funcThreads.emplace_back([this]() { - bird_thread(); - }); - return eResult::success; } @@ -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); } } @@ -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}); } - } diff --git a/controlplane/rib.h b/controlplane/rib.h index a6f9d977..06f75332 100644 --- a/controlplane/rib.h +++ b/controlplane/rib.h @@ -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(); @@ -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;