aboutsummaryrefslogtreecommitdiffstats
path: root/apps/ping
diff options
context:
space:
mode:
Diffstat (limited to 'apps/ping')
-rw-r--r--apps/ping/.clang-format2
-rw-r--r--apps/ping/CMakeLists.txt31
-rw-r--r--apps/ping/src/ping_client.cc102
-rw-r--r--apps/ping/src/ping_server.cc101
4 files changed, 155 insertions, 81 deletions
diff --git a/apps/ping/.clang-format b/apps/ping/.clang-format
index cd21e2017..adc73c6fd 100644
--- a/apps/ping/.clang-format
+++ b/apps/ping/.clang-format
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2021 Cisco and/or its affiliates.
+# Copyright (c) 2021 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
diff --git a/apps/ping/CMakeLists.txt b/apps/ping/CMakeLists.txt
index 42f7f98c1..a094cebe3 100644
--- a/apps/ping/CMakeLists.txt
+++ b/apps/ping/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Copyright (c) 2021-2022 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
@@ -12,28 +12,45 @@
# limitations under the License.
if (NOT DISABLE_EXECUTABLES)
+##############################################################
+# Compiler options
+##############################################################
+set(COMPILER_OPTIONS
+ ${DEFAULT_COMPILER_OPTIONS}
+)
+
+##############################################################
+# Libraries to link
+##############################################################
list (APPEND PING_LIBRARIES
- ${LIBTRANSPORT_LIBRARIES}
- ${CMAKE_THREAD_LIBS_INIT}
- ${WSOCK32_LIBRARY}
- ${WS2_32_LIBRARY}
+ PRIVATE ${LIBHICN_LIBRARIES}
+ PRIVATE ${LIBTRANSPORT_LIBRARIES}
+ PRIVATE ${CMAKE_THREAD_LIBS_INIT}
+ PRIVATE ${WSOCK32_LIBRARY}
+ PRIVATE ${WS2_32_LIBRARY}
)
+##############################################################
+# Build ping server
+##############################################################
build_executable(hicn-ping-server
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/ping_server.cc
LINK_LIBRARIES ${PING_LIBRARIES}
- INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS}
DEPENDS ${DEPENDENCIES}
COMPONENT ${HICN_APPS}
LINK_FLAGS ${LINK_FLAGS}
+ COMPILE_OPTIONS ${COMPILER_OPTIONS}
)
+##############################################################
+# Build ping client
+##############################################################
build_executable(hicn-ping-client
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/ping_client.cc
LINK_LIBRARIES ${PING_LIBRARIES}
- INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS}
DEPENDS ${DEPENDENCIES}
COMPONENT ${HICN_APPS}
LINK_FLAGS ${LINK_FLAGS}
+ COMPILE_OPTIONS ${COMPILER_OPTIONS}
)
endif () \ No newline at end of file
diff --git a/apps/ping/src/ping_client.cc b/apps/ping/src/ping_client.cc
index 24e0bf3ed..0217f2f8c 100644
--- a/apps/ping/src/ping_client.cc
+++ b/apps/ping/src/ping_client.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -16,7 +16,9 @@
#include <hicn/transport/auth/verifier.h>
#include <hicn/transport/core/global_object_pool.h>
#include <hicn/transport/core/interest.h>
+#include <hicn/transport/interfaces/global_conf_interface.h>
#include <hicn/transport/interfaces/portal.h>
+#include <hicn/transport/utils/chrono_typedefs.h>
#include <asio/signal_set.hpp>
#include <asio/steady_timer.hpp>
@@ -32,7 +34,7 @@ namespace core {
namespace ping {
-typedef std::map<uint64_t, uint64_t> SendTimeMap;
+typedef std::map<uint64_t, utils::SteadyTime::TimePoint> SendTimeMap;
typedef auth::AsymmetricVerifier Verifier;
class Configuration {
@@ -77,17 +79,12 @@ class Configuration {
}
};
-class Client : interface::Portal::ConsumerCallback {
+class Client : interface::Portal::TransportCallback {
public:
- Client(Configuration *c)
- : portal_(), signals_(portal_.getIoService(), SIGINT) {
+ Client(Configuration *c) : portal_(), signals_(io_service_, SIGINT) {
// Let the main thread to catch SIGINT
- portal_.connect();
- portal_.setConsumerCallback(this);
-
signals_.async_wait(std::bind(&Client::afterSignal, this));
-
- timer_.reset(new asio::steady_timer(portal_.getIoService()));
+ timer_.reset(new asio::steady_timer(portal_.getThread().getIoService()));
config_ = c;
sequence_number_ = config_->first_suffix_;
last_jump_ = 0;
@@ -105,19 +102,28 @@ class Client : interface::Portal::ConsumerCallback {
void ping() {
std::cout << "start ping" << std::endl;
- doPing();
- portal_.runEventsLoop();
+
+ portal_.getThread().add([this]() {
+ portal_.connect();
+ portal_.registerTransportCallback(this);
+ doPing();
+ });
+
+ io_service_.run();
+ }
+
+ void onInterest(Interest &interest) override {
+ throw errors::RuntimeException("Unexpected interest received.");
}
void onContentObject(Interest &interest, ContentObject &object) override {
- uint64_t rtt = 0;
+ double rtt = 0;
if (!config_->certificate_.empty()) {
- auto t0 = std::chrono::steady_clock::now();
+ auto t0 = utils::SteadyTime::now();
if (verifier_.verifyPacket(&object)) {
- auto t1 = std::chrono::steady_clock::now();
- auto dt =
- std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0);
+ auto t1 = utils::SteadyTime::now();
+ auto dt = utils::SteadyTime::getDurationUs(t0, t1);
std::cout << "Verification time: " << dt.count() << std::endl;
std::cout << "<<< Signature Ok." << std::endl;
} else {
@@ -127,10 +133,9 @@ class Client : interface::Portal::ConsumerCallback {
auto it = send_timestamps_.find(interest.getName().getSuffix());
if (it != send_timestamps_.end()) {
- rtt = std::chrono::duration_cast<std::chrono::microseconds>(
- std::chrono::steady_clock::now().time_since_epoch())
- .count() -
- it->second;
+ rtt =
+ utils::SteadyTime::getDurationUs(it->second, utils::SteadyTime::now())
+ .count();
send_timestamps_.erase(it);
}
@@ -206,7 +211,11 @@ class Client : interface::Portal::ConsumerCallback {
}
}
- void onError(std::error_code ec) override {}
+ void onError(const std::error_code &ec) override {
+ std::cout << "Aborting ping due to internal error: " << ec.message()
+ << std::endl;
+ afterSignal();
+ }
void doPing() {
const Name interest_name(config_->name_, (uint32_t)sequence_number_);
@@ -254,10 +263,7 @@ class Client : interface::Portal::ConsumerCallback {
if (!config_->quiet_) std::cout << std::endl;
- send_timestamps_[sequence_number_] =
- std::chrono::duration_cast<std::chrono::microseconds>(
- std::chrono::steady_clock::now().time_since_epoch())
- .count();
+ send_timestamps_[sequence_number_] = utils::SteadyTime::now();
portal_.sendInterest(std::move(interest));
@@ -267,7 +273,11 @@ class Client : interface::Portal::ConsumerCallback {
if (sent_ < config_->maxPing_) {
this->timer_->expires_from_now(
std::chrono::microseconds(config_->pingInterval_));
- this->timer_->async_wait([this](const std::error_code e) { doPing(); });
+ this->timer_->async_wait([this](const std::error_code e) {
+ if (!e) {
+ doPing();
+ }
+ });
}
}
@@ -275,11 +285,11 @@ class Client : interface::Portal::ConsumerCallback {
std::cout << "Stop ping" << std::endl;
std::cout << "Sent: " << sent_ << " Received: " << received_
<< " Timeouts: " << timedout_ << std::endl;
- portal_.stopEventsLoop();
+ io_service_.stop();
}
void reset() {
- timer_.reset(new asio::steady_timer(portal_.getIoService()));
+ timer_.reset(new asio::steady_timer(portal_.getThread().getIoService()));
sequence_number_ = config_->first_suffix_;
last_jump_ = 0;
processed_ = 0;
@@ -291,6 +301,7 @@ class Client : interface::Portal::ConsumerCallback {
private:
SendTimeMap send_timestamps_;
+ asio::io_service io_service_;
interface::Portal portal_;
asio::signal_set signals_;
uint64_t sequence_number_;
@@ -337,6 +348,11 @@ void help() {
<< std::endl;
std::cout << "-q quiet, not prints (default false)"
<< std::endl;
+ std::cerr << "-z <io_module> IO module to use. Default: hicnlightng_module"
+ << std::endl;
+ std::cerr << "-F <conf_file> Path to optional configuration file for "
+ "libtransport"
+ << std::endl;
std::cout << "-H prints this message" << std::endl;
}
@@ -350,7 +366,11 @@ int main(int argc, char *argv[]) {
int opt;
std::string producer_certificate = "";
- while ((opt = getopt(argc, argv, "j::t:i:m:s:d:n:l:f:c:SAOqVDH")) != -1) {
+ std::string conf_file;
+ transport::interface::global_config::IoModuleConfiguration io_config;
+ io_config.name = "hicnlightng_module";
+
+ while ((opt = getopt(argc, argv, "j::t:i:m:s:d:n:l:f:c:SAOqVDHz:F:")) != -1) {
switch (opt) {
case 't':
c->ttl_ = (uint8_t)std::stoi(optarg);
@@ -406,6 +426,12 @@ int main(int argc, char *argv[]) {
case 'c':
c->certificate_ = std::string(optarg);
break;
+ case 'z':
+ io_config.name = optarg;
+ break;
+ case 'F':
+ conf_file = optarg;
+ break;
case 'H':
default:
help();
@@ -413,16 +439,24 @@ int main(int argc, char *argv[]) {
}
}
+ /**
+ * IO module configuration
+ */
+ io_config.set();
+
+ /**
+ * Parse config file
+ */
+ transport::interface::global_config::parseConfigurationFile(conf_file);
+
auto ping = std::make_unique<Client>(c);
auto t0 = std::chrono::steady_clock::now();
ping->ping();
auto t1 = std::chrono::steady_clock::now();
- std::cout
- << "Elapsed time: "
- << std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()
- << std::endl;
+ std::cout << "Elapsed time: "
+ << utils::SteadyTime::getDurationUs(t0, t1).count() << std::endl;
#ifdef _WIN32
WSACleanup();
diff --git a/apps/ping/src/ping_server.cc b/apps/ping/src/ping_server.cc
index baf9c6698..3ffbc7325 100644
--- a/apps/ping/src/ping_server.cc
+++ b/apps/ping/src/ping_server.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -21,10 +21,10 @@
#include <openssl/applink.c>
#endif
-#include <hicn/transport/auth/identity.h>
#include <hicn/transport/auth/signer.h>
#include <hicn/transport/core/content_object.h>
#include <hicn/transport/core/interest.h>
+#include <hicn/transport/interfaces/global_conf_interface.h>
#include <hicn/transport/utils/string_tokenizer.h>
#include <asio.hpp>
@@ -36,24 +36,13 @@ namespace interface {
using HashAlgorithm = core::HashAlgorithm;
using CryptoSuite = auth::CryptoSuite;
-auth::Identity setProducerIdentity(std::string keystore_name,
- std::string keystore_password,
- auth::CryptoHashType hash_algorithm) {
- if (access(keystore_name.c_str(), F_OK) != -1) {
- return auth::Identity(keystore_name, keystore_password, hash_algorithm);
- } else {
- return auth::Identity(keystore_name, keystore_password,
- CryptoSuite::RSA_SHA256, 1024, 365, "producer-test");
- }
-}
-
class CallbackContainer {
const std::size_t log2_content_object_buffer_size = 12;
public:
CallbackContainer(const Name &prefix, uint32_t object_size, bool verbose,
bool dump, bool quite, bool flags, bool reset, uint8_t ttl,
- auth::Identity *identity, bool sign, uint32_t lifetime)
+ auth::Signer *signer, bool sign, uint32_t lifetime)
: buffer_(object_size, 'X'),
content_objects_((std::uint32_t)(1 << log2_content_object_buffer_size)),
mask_((std::uint16_t)(1 << log2_content_object_buffer_size) - 1),
@@ -64,7 +53,7 @@ class CallbackContainer {
flags_(flags),
reset_(reset),
ttl_(ttl),
- identity_(identity),
+ signer_(signer),
sign_(sign) {
core::Packet::Format format;
@@ -151,8 +140,8 @@ class CallbackContainer {
if (!quite_) std::cout << std::endl;
- if (sign_) {
- identity_->getSigner()->signPacket(content_object.get());
+ if (sign_ && signer_) {
+ signer_->signPacket(content_object.get());
}
p.produce(*content_object);
@@ -170,33 +159,43 @@ class CallbackContainer {
bool flags_;
bool reset_;
uint8_t ttl_;
- auth::Identity *identity_;
+ auth::Signer *signer_;
bool sign_;
};
void help() {
std::cout << "usage: hicn-preoducer-ping [options]" << std::endl;
std::cout << "PING options" << std::endl;
- std::cout << "-s <val> object content size (default 1350B)" << std::endl;
- std::cout << "-n <val> hicn name (default b001::/64)" << std::endl;
- std::cout << "-f set tcp flags according to the flag received "
- "(default false)"
+ std::cout << "-s <val> object content size (default 1350B)"
<< std::endl;
- std::cout << "-l data lifetime" << std::endl;
- std::cout << "-r always reply with a reset flag (default false)"
+ std::cout << "-n <val> hicn name (default b001::/64)" << std::endl;
+ std::cout << "-f set tcp flags according to the flag received "
+ " (default false)"
<< std::endl;
- std::cout << "-t set ttl (default 64)" << std::endl;
+ std::cout << "-l data lifetime" << std::endl;
+ std::cout
+ << "-r always reply with a reset flag (default false)"
+ << std::endl;
+ std::cout << "-t set ttl (default 64)" << std::endl;
std::cout << "OUTPUT options" << std::endl;
- std::cout << "-V verbose, prints statistics about the messagges sent "
- "and received (default false)"
+ std::cout << "-V verbose, prints statistics about the "
+ "messagges sent "
+ " and received (default false)"
+ << std::endl;
+ std::cout << "-D dump, dumps sent and received packets "
+ "(default false)"
<< std::endl;
- std::cout << "-D dump, dumps sent and received packets (default false)"
+ std::cout << "-q quite, not prints (default false)"
+ << std::endl;
+ std::cerr << "-z <io_module> IO module to use. Default: hicnlightng_module"
+ << std::endl;
+ std::cerr << "-F <conf_file> Path to optional configuration file for "
+ "libtransport"
<< std::endl;
- std::cout << "-q quite, not prints (default false)" << std::endl;
#ifndef _WIN32
- std::cout << "-d daemon mode" << std::endl;
+ std::cout << "-d daemon mode" << std::endl;
#endif
- std::cout << "-H prints this message" << std::endl;
+ std::cout << "-H prints this message" << std::endl;
}
int main(int argc, char **argv) {
@@ -220,11 +219,15 @@ int main(int argc, char **argv) {
bool sign = false;
uint32_t data_lifetime = default_values::content_object_expiry_time;
+ std::string conf_file;
+ transport::interface::global_config::IoModuleConfiguration io_config;
+ io_config.name = "hicnlightng_module";
+
int opt;
#ifndef _WIN32
- while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDdHk:p:")) != -1) {
+ while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDdHk:p:z:F:")) != -1) {
#else
- while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDHk:p:")) != -1) {
+ while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDHk:p:z:F:")) != -1) {
#endif
switch (opt) {
case 's':
@@ -268,6 +271,12 @@ int main(int argc, char **argv) {
case 'p':
keystore_password = optarg;
break;
+ case 'z':
+ io_config.name = optarg;
+ break;
+ case 'F':
+ conf_file = optarg;
+ break;
case 'H':
default:
help();
@@ -281,6 +290,16 @@ int main(int argc, char **argv) {
}
#endif
+ /**
+ * IO module configuration
+ */
+ io_config.set();
+
+ /**
+ * Parse config file
+ */
+ transport::interface::global_config::parseConfigurationFile(conf_file);
+
core::Prefix producer_namespace(name_prefix);
utils::StringTokenizer tokenizer(name_prefix, delimiter);
@@ -290,21 +309,24 @@ int main(int argc, char **argv) {
if (object_size > 1350) object_size = 1350;
CallbackContainer *stubs;
- auth::Identity identity = setProducerIdentity(
- keystore_path, keystore_password, auth::CryptoHashType::SHA256);
+ std::unique_ptr<auth::AsymmetricSigner> signer;
if (sign) {
- stubs = new CallbackContainer(n, object_size, verbose, dump, quite, flags,
- reset, ttl, &identity, sign, data_lifetime);
+ signer = std::make_unique<auth::AsymmetricSigner>(keystore_path,
+ keystore_password);
+ stubs =
+ new CallbackContainer(n, object_size, verbose, dump, quite, flags,
+ reset, ttl, signer.get(), sign, data_lifetime);
} else {
- auth::Identity *identity = nullptr;
+ auth::Signer *signer = nullptr;
stubs = new CallbackContainer(n, object_size, verbose, dump, quite, flags,
- reset, ttl, identity, sign, data_lifetime);
+ reset, ttl, signer, sign, data_lifetime);
}
ProducerSocket p;
p.registerPrefix(producer_namespace);
+ p.setSocketOption(GeneralTransportOptions::MAKE_MANIFEST, false);
p.setSocketOption(GeneralTransportOptions::OUTPUT_BUFFER_SIZE, 0U);
p.setSocketOption(
ProducerCallbacksOptions::CACHE_MISS,
@@ -313,6 +335,7 @@ int main(int argc, char **argv) {
std::placeholders::_2, data_lifetime));
p.connect();
+ p.start();
asio::io_service io_service;
asio::signal_set signal_set(io_service, SIGINT);