From 481d5124a127aec922acf6e8b8f2c76780142e2f Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Thu, 1 Dec 2022 16:29:08 +0100 Subject: feat(libtransport): add configuration section for hicnlight io_module And add configuration for hicnlight url. Ticket: HICN-819 Change-Id: I0c2557ca49078e1e405d078da2768372e5f44525 Signed-off-by: Mauro Sardara --- .../io_modules/hicn-light/hicn_forwarder_module.cc | 50 ++++++++++++++++++++-- .../io_modules/hicn-light/hicn_forwarder_module.h | 11 ++++- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc index ae8aebec6..b26c8973b 100644 --- a/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc +++ b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc @@ -13,7 +13,9 @@ * limitations under the License. */ +#include #include +#include #include extern "C" { @@ -25,14 +27,42 @@ namespace transport { namespace core { HicnForwarderModule::HicnForwarderModule() - : IoModule(), connector_(nullptr), seq_(0) {} + : IoModule(), + connector_(nullptr), + seq_(0), + forwarder_url_(default_hicnlight_url) { + using namespace std::placeholders; + GlobalConfiguration::getInstance().registerConfigurationParser( + hicnlight_configuration_section, + std::bind(&HicnForwarderModule::parseForwarderConfiguration, this, _1, + _2)); +} HicnForwarderModule::~HicnForwarderModule() {} void HicnForwarderModule::connect(bool is_consumer) { - connector_->connect("localhost", 9695); - connector_->setRole(is_consumer ? Connector::Role::CONSUMER - : Connector::Role::PRODUCER); + if (!connector_->isConnected()) { + // Parse forwarder URI + utils::Uri uri; + uri.parse(forwarder_url_); + + // Safechecks + CHECK(uri.getProtocol() == "hicn") + << "The protocol of the forwarder url should be hicn"; + auto port_min = (1 << 10); + auto port_max = (1 << 16); + + auto port = std::stoul(uri.getPort()); + + CHECK(port > port_min && port < port_max) + << "The port should be between " << port_min << " and " << port_max; + + VLOG(1) << "Connecting to " << uri.getLocator() << ":" << uri.getPort(); + + connector_->connect(uri.getLocator(), port); + connector_->setRole(is_consumer ? Connector::Role::CONSUMER + : Connector::Role::PRODUCER); + } } bool HicnForwarderModule::isConnected() { return connector_->isConnected(); } @@ -43,6 +73,18 @@ void HicnForwarderModule::send(Packet &packet) { connector_->send(packet); } +void HicnForwarderModule::parseForwarderConfiguration( + const libconfig::Setting &forwarder_config, std::error_code &ec) { + using namespace libconfig; + + // forwarder url hicn://127.0.0.1:12345 + if (forwarder_config.exists("forwarder_url")) { + // Get number of threads + forwarder_config.lookupValue("forwarder_url", forwarder_url_); + VLOG(1) << "Forwarder URL from config file: " << forwarder_url_; + } +} + void HicnForwarderModule::send(const utils::MemBuf::Ptr &packet) { counters_.tx_packets++; counters_.tx_bytes += packet->length(); diff --git a/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h index 0d6acb484..5ebac9568 100644 --- a/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h +++ b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h @@ -18,6 +18,8 @@ #include #include +#include + extern "C" { #include } @@ -30,6 +32,8 @@ class UdpTunnelConnector; class HicnForwarderModule : public IoModule { static constexpr std::uint16_t interface_mtu = 1500; + static inline char default_hicnlight_url[] = "hicn://127.0.0.1:9695"; + static inline char hicnlight_configuration_section[] = "hicnlight"; public: #if 0 @@ -95,11 +99,16 @@ class HicnForwarderModule : public IoModule { std::unique_ptr &&addr, uint32_t prefix_len, std::string strategy); + void parseForwarderConfiguration(const libconfig::Setting &io_config, + std::error_code &ec); + private: std::shared_ptr connector_; - /* Sequence number used for sending control messages */ uint32_t seq_; + + // Url of the forwarder + std::string forwarder_url_; }; extern "C" IoModule *create_module(void); -- cgit 1.2.3-korg