aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2022-12-01 16:29:08 +0100
committerMauro Sardara <msardara@cisco.com>2022-12-01 17:11:22 +0100
commit481d5124a127aec922acf6e8b8f2c76780142e2f (patch)
tree879e6d2ece4233777e067380295058adf51388f4
parenta5f7941f49160021506ecae0da090f0b204b75ea (diff)
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 <msardara@cisco.com>
-rw-r--r--libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc50
-rw-r--r--libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h11
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 <core/global_configuration.h>
#include <core/udp_connector.h>
+#include <hicn/transport/utils/uri.h>
#include <io_modules/hicn-light/hicn_forwarder_module.h>
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 <hicn/transport/core/io_module.h>
#include <hicn/transport/core/prefix.h>
+#include <libconfig.h++>
+
extern "C" {
#include <hicn/ctrl/hicn-light.h>
}
@@ -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<sockaddr> &&addr, uint32_t prefix_len,
std::string strategy);
+ void parseForwarderConfiguration(const libconfig::Setting &io_config,
+ std::error_code &ec);
+
private:
std::shared_ptr<UdpTunnelConnector> 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);