aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport')
-rw-r--r--libtransport/src/core/global_configuration.cc1
-rw-r--r--libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc29
-rw-r--r--libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h43
3 files changed, 69 insertions, 4 deletions
diff --git a/libtransport/src/core/global_configuration.cc b/libtransport/src/core/global_configuration.cc
index 9da37c2fa..f53e1f0e2 100644
--- a/libtransport/src/core/global_configuration.cc
+++ b/libtransport/src/core/global_configuration.cc
@@ -68,6 +68,7 @@ void GlobalConfiguration::parseConfiguration(const std::string& path) {
// variable comes first.
std::unique_lock<std::mutex> lck(cp_mtx_);
if (const char* env_c = std::getenv(GlobalConfiguration::conf_file)) {
+ conf_file_path_ = env_c;
parseTransportConfig(env_c);
} else if (!path.empty()) {
conf_file_path_ = path;
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..0d45ba49d 100644
--- a/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc
+++ b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc
@@ -14,6 +14,7 @@
*/
#include <core/udp_connector.h>
+#include <hicn/transport/utils/uri.h>
#include <io_modules/hicn-light/hicn_forwarder_module.h>
extern "C" {
@@ -24,15 +25,37 @@ namespace transport {
namespace core {
+HicnForwarderModule::ForwarderUrlInitializer
+ HicnForwarderModule::forwarder_url_initializer_;
+
HicnForwarderModule::HicnForwarderModule()
: IoModule(), connector_(nullptr), seq_(0) {}
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_initializer_.getForwarderUrl());
+
+ // Safechecks
+ CHECK(uri.getProtocol() == "hicn")
+ << "The protocol of the forwarder url should be hicn";
+ uint16_t port_min = (1 << 10);
+ uint16_t port_max = (1 << 16) - 1;
+
+ uint16_t 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(); }
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..2378b93f8 100644
--- a/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h
+++ b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h
@@ -15,9 +15,12 @@
#pragma once
+#include <core/global_configuration.h>
#include <hicn/transport/core/io_module.h>
#include <hicn/transport/core/prefix.h>
+#include <libconfig.h++>
+
extern "C" {
#include <hicn/ctrl/hicn-light.h>
}
@@ -95,11 +98,49 @@ class HicnForwarderModule : public IoModule {
std::unique_ptr<sockaddr> &&addr, uint32_t prefix_len,
std::string strategy);
+ static void parseForwarderConfiguration(const libconfig::Setting &io_config,
+ std::error_code &ec);
+ static std::string initForwarderUrl();
+
private:
std::shared_ptr<UdpTunnelConnector> connector_;
-
/* Sequence number used for sending control messages */
uint32_t seq_;
+
+ class ForwarderUrlInitializer {
+ static inline char default_hicnlight_url[] = "hicn://127.0.0.1:9695";
+ static inline char hicnlight_configuration_section[] = "hicnlight";
+
+ public:
+ ForwarderUrlInitializer()
+ : forwarder_url_(ForwarderUrlInitializer::default_hicnlight_url) {
+ using namespace std::placeholders;
+ GlobalConfiguration::getInstance().registerConfigurationParser(
+ ForwarderUrlInitializer::hicnlight_configuration_section,
+ std::bind(&ForwarderUrlInitializer::parseForwarderConfiguration, this,
+ _1, _2));
+ }
+
+ std::string getForwarderUrl() { return forwarder_url_; }
+
+ private:
+ void 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_;
+ }
+ }
+
+ // Url of the forwarder
+ std::string forwarder_url_;
+ };
+
+ static ForwarderUrlInitializer forwarder_url_initializer_;
};
extern "C" IoModule *create_module(void);