summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2022-12-02 15:20:18 +0100
committerMauro Sardara <msardara@cisco.com>2022-12-02 15:46:48 +0000
commit4aeff8486824fecd830a1ecf0ef3abc6e58616a7 (patch)
tree12f5d818dcdfc8e5f9751e1788bd6d987647891d
parent481d5124a127aec922acf6e8b8f2c76780142e2f (diff)
feat: configure hicnlight port in libtransport and libconfig
Change-Id: Ib55747b4589150ce4a88938e28371c6cf5ab979b Signed-off-by: Mauro Sardara <msardara@cisco.com> Signed-off-by: Michele Papalini <micpapal@cisco.com>
-rw-r--r--ctrl/libhicnctrl/src/modules/hicn_light.c27
-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.h44
4 files changed, 65 insertions, 36 deletions
diff --git a/ctrl/libhicnctrl/src/modules/hicn_light.c b/ctrl/libhicnctrl/src/modules/hicn_light.c
index a652602c6..a2577c31b 100644
--- a/ctrl/libhicnctrl/src/modules/hicn_light.c
+++ b/ctrl/libhicnctrl/src/modules/hicn_light.c
@@ -118,8 +118,13 @@ static const struct in6_addr loopback_addr = IN6ADDR_LOOPBACK_INIT;
* \return 0 if parsing succeeded, a negative error value otherwise.
*/
static int hicnlight_parse_url(const char *url, struct sockaddr *sa) {
- /* FIXME URL parsing is currently not implemented */
- _ASSERT(!url);
+ char ip[100];
+ char protocol[100];
+ int port = PORT;
+ if (url) {
+ int ret = sscanf(url, "%99[^:]://%99[^:]:%99d[^/]", protocol, ip, &port);
+ if (ret == EOF) return -1;
+ }
#ifdef __linux__
srand(time(NULL) ^ getpid() ^ gettid());
@@ -137,15 +142,25 @@ static int hicnlight_parse_url(const char *url, struct sockaddr *sa) {
case AF_INET: {
struct sockaddr_in *sai = (struct sockaddr_in *)sa;
sai->sin_family = AF_INET;
- sai->sin_port = htons(PORT);
- sai->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ sai->sin_port = htons(port);
+ if (url) {
+ int ret = inet_pton(AF_INET, ip, &(sai->sin_addr.s_addr));
+ if (ret != 1) return -1;
+ } else {
+ sai->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ }
break;
}
case AF_INET6: {
struct sockaddr_in6 *sai6 = (struct sockaddr_in6 *)sa;
sai6->sin6_family = AF_INET6;
- sai6->sin6_port = htons(PORT);
- sai6->sin6_addr = loopback_addr;
+ sai6->sin6_port = htons(port);
+ if (url) {
+ int ret = inet_pton(AF_INET6, ip, &(sai6->sin6_addr));
+ if (ret != 1) return -1;
+ } else {
+ sai6->sin6_addr = loopback_addr;
+ }
break;
}
default:
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 b26c8973b..26e7c97e5 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,6 @@
* 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>
@@ -26,17 +25,11 @@ namespace transport {
namespace core {
+HicnForwarderModule::ForwarderUrlInitializer
+ HicnForwarderModule::forwarder_url_initializer_;
+
HicnForwarderModule::HicnForwarderModule()
- : 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));
-}
+ : IoModule(), connector_(nullptr), seq_(0) {}
HicnForwarderModule::~HicnForwarderModule() {}
@@ -44,7 +37,7 @@ void HicnForwarderModule::connect(bool is_consumer) {
if (!connector_->isConnected()) {
// Parse forwarder URI
utils::Uri uri;
- uri.parse(forwarder_url_);
+ uri.parse(forwarder_url_initializer_.getForwarderUrl());
// Safechecks
CHECK(uri.getProtocol() == "hicn")
@@ -73,18 +66,6 @@ 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 5ebac9568..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,6 +15,7 @@
#pragma once
+#include <core/global_configuration.h>
#include <hicn/transport/core/io_module.h>
#include <hicn/transport/core/prefix.h>
@@ -32,8 +33,6 @@ 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
@@ -99,16 +98,49 @@ 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);
+ 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_;
- // Url of the forwarder
- std::string forwarder_url_;
+ 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);