summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorEnrico Loparco (eloparco) <eloparco@cisco.com>2022-09-14 08:58:55 +0000
committerEnrico Loparco (eloparco) <eloparco@cisco.com>2022-09-14 13:42:31 +0000
commitab38321508d886f0acd535f0f5f07a3d44e29591 (patch)
treea46dedcd2dce871cf8c381fd06e3c00c46cd3b27 /apps
parent6c9f120f028bcca93fd087afa648f653b208eb35 (diff)
feat(hicn-ping): allow usage of random prefixes/suffixes in hicn-ping
Ref: HICN-783 Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com> Change-Id: I41c804dd639ee15aee9619732f55e39a3baf1385
Diffstat (limited to 'apps')
-rw-r--r--apps/ping/src/ping_client.cc77
-rw-r--r--apps/ping/src/ping_server.cc90
2 files changed, 90 insertions, 77 deletions
diff --git a/apps/ping/src/ping_client.cc b/apps/ping/src/ping_client.cc
index 3e95b8896..747f4bd1b 100644
--- a/apps/ping/src/ping_client.cc
+++ b/apps/ping/src/ping_client.cc
@@ -20,6 +20,7 @@
#include <hicn/transport/interfaces/global_conf_interface.h>
#include <hicn/transport/interfaces/portal.h>
#include <hicn/transport/utils/chrono_typedefs.h>
+#include <hicn/transport/utils/traffic_generator.h>
#include <asio/signal_set.hpp>
#include <asio/steady_timer.hpp>
@@ -40,8 +41,11 @@ using Verifier = auth::AsymmetricVerifier;
class Configuration {
public:
- uint64_t num_int_manifest_suffixes_ =
- 0; // Number of suffixes in interest manifest
+ static constexpr char TRAFFIC_GENERATOR_RAND[] = "RANDOM";
+
+ uint32_t num_int_manifest_suffixes_ =
+ 0; // Number of suffixes in interest manifest (suffix in the header
+ // is not included in the count)
uint64_t interestLifetime_ = 500; // ms
uint64_t pingInterval_ = 1000000; // us
uint32_t maxPing_ = 10; // number of interests
@@ -49,6 +53,7 @@ class Configuration {
std::string name_ = "b001::1";
std::string certificate_;
std::string passphrase_;
+ std::string traffic_generator_type_;
uint16_t srcPort_ = 9695;
uint16_t dstPort_ = 8080;
bool verbose_ = false;
@@ -68,8 +73,7 @@ class Client : private interface::Portal::TransportCallback {
: signals_(io_service_, SIGINT),
config_(c),
timer_(std::make_unique<asio::steady_timer>(
- portal_.getThread().getIoService())),
- sequence_number_(config_->first_suffix_) {
+ portal_.getThread().getIoService())) {
// Let the main thread to catch SIGINT
signals_.async_wait(std::bind(&Client::afterSignal, this));
@@ -83,6 +87,15 @@ class Client : private interface::Portal::TransportCallback {
signer_ = std::make_unique<auth::SymmetricSigner>(
auth::CryptoSuite::HMAC_SHA256, c->passphrase_);
}
+
+ if (c->traffic_generator_type_ ==
+ std::string(Configuration::TRAFFIC_GENERATOR_RAND)) {
+ traffic_generator_ =
+ std::make_unique<RandomTrafficGenerator>(config_->maxPing_);
+ } else {
+ traffic_generator_ = std::make_unique<IncrSuffixTrafficGenerator>(
+ config_->name_, config_->first_suffix_, config_->maxPing_);
+ }
}
virtual ~Client() = default;
@@ -128,8 +141,8 @@ class Client : private interface::Portal::TransportCallback {
if (config_->verbose_) {
std::cout << "<<< recevied object. " << std::endl;
- std::cout << "<<< interest name: " << interest.getName()
- << " (n_suffixes=" << interest.numberOfSuffixes() << ")"
+ std::cout << "<<< interest name: " << interest.getName().getPrefix()
+ << " (n_suffixes=" << config_->num_int_manifest_suffixes_ << ")"
<< " src port: " << interest.getSrcPort()
<< " dst port: " << interest.getDstPort() << std::endl;
std::cout << "<<< object name: " << object.getName()
@@ -141,7 +154,8 @@ class Client : private interface::Portal::TransportCallback {
} else if (!config_->quiet_) {
std::cout << "<<< received object. " << std::endl;
std::cout << "<<< round trip: " << rtt << " [us]" << std::endl;
- std::cout << "<<< interest name: " << interest.getName() << std::endl;
+ std::cout << "<<< interest name: " << interest.getName().getPrefix()
+ << std::endl;
std::cout << "<<< object name: " << object.getName() << std::endl;
std::cout << "<<< content object size: "
<< object.payloadSize() + object.headerSize() << " [bytes]"
@@ -197,7 +211,10 @@ class Client : private interface::Portal::TransportCallback {
}
void doPing() {
- const Name interest_name(config_->name_, sequence_number_);
+ std::string name = traffic_generator_->getPrefix();
+ uint32_t sequence_number = traffic_generator_->getSuffix();
+ const Name interest_name(name, sequence_number);
+
hicn_packet_format_t format;
if (interest_name.getAddressFamily() == AF_INET) {
format = signer_ ? HICN_PACKET_FORMAT_IPV4_TCP_AH
@@ -217,12 +234,6 @@ class Client : private interface::Portal::TransportCallback {
interest->setSrcPort(config_->srcPort_);
interest->setDstPort(config_->dstPort_);
interest->setTTL(config_->ttl_);
- uint32_t seq_offset = 1;
- while (seq_offset <= config_->num_int_manifest_suffixes_ &&
- sequence_number_ + seq_offset < config_->maxPing_) {
- interest->appendSuffix(sequence_number_ + seq_offset);
- seq_offset++;
- }
if (config_->verbose_) {
std::cout << ">>> send interest " << interest->getName()
@@ -237,11 +248,15 @@ class Client : private interface::Portal::TransportCallback {
if (!config_->quiet_) std::cout << std::endl;
- send_timestamps_[sequence_number_] = utils::SteadyTime::now();
- for (uint64_t i = 1; i < seq_offset; i++)
- send_timestamps_[sequence_number_ + i] = utils::SteadyTime::now();
+ send_timestamps_[sequence_number] = utils::SteadyTime::now();
+ for (int i = 0; i < config_->num_int_manifest_suffixes_ &&
+ !traffic_generator_->hasFinished();
+ i++) {
+ uint32_t sequence_number = traffic_generator_->getSuffix();
- if (signer_) signer_->signPacket(interest.get());
+ interest->appendSuffix(sequence_number);
+ send_timestamps_[sequence_number] = utils::SteadyTime::now();
+ }
if (config_->dump_) {
std::cout << "----- interest dump -----" << std::endl;
@@ -250,13 +265,10 @@ class Client : private interface::Portal::TransportCallback {
}
interest->encodeSuffixes();
-
+ if (signer_) signer_->signPacket(interest.get());
portal_.sendInterest(interest, interest->getLifetime());
- sequence_number_ += seq_offset;
- sent_ += seq_offset;
-
- if (sent_ < config_->maxPing_) {
+ if (!traffic_generator_->hasFinished()) {
this->timer_->expires_from_now(
std::chrono::microseconds(config_->pingInterval_));
this->timer_->async_wait([this](const std::error_code e) {
@@ -269,18 +281,18 @@ class Client : private interface::Portal::TransportCallback {
void afterSignal() {
std::cout << "Stop ping" << std::endl;
- std::cout << "Sent: " << sent_ << " Received: " << received_
- << " Timeouts: " << timedout_ << std::endl;
+ std::cout << "Sent: " << traffic_generator_->getSentCount()
+ << " Received: " << received_ << " Timeouts: " << timedout_
+ << std::endl;
io_service_.stop();
}
void reset() {
timer_.reset(new asio::steady_timer(portal_.getThread().getIoService()));
- sequence_number_ = config_->first_suffix_;
+ traffic_generator_->reset();
last_jump_ = 0;
processed_ = 0;
state_ = SYN_STATE;
- sent_ = 0;
received_ = 0;
timedout_ = 0;
}
@@ -292,15 +304,14 @@ class Client : private interface::Portal::TransportCallback {
asio::signal_set signals_;
Configuration *config_;
std::unique_ptr<asio::steady_timer> timer_;
- uint32_t sequence_number_;
uint64_t last_jump_ = 0;
uint64_t processed_ = 0;
uint32_t state_ = SYN_STATE;
- uint32_t sent_ = 0;
uint32_t received_ = 0;
uint32_t timedout_ = 0;
Verifier verifier_;
std::unique_ptr<auth::Signer> signer_;
+ std::unique_ptr<TrafficGenerator> traffic_generator_;
};
void help() {
@@ -339,6 +350,9 @@ void help() {
std::cerr << "-F <conf_file> Path to optional configuration file for "
"libtransport"
<< std::endl;
+ std::cout << "-b <type> Traffic generator type. Use 'RANDOM' for "
+ "random prefixes and suffixes. Default: sequential suffixes."
+ << std::endl;
std::cout << "-H prints this message" << std::endl;
}
@@ -358,13 +372,16 @@ int start(int argc, char *argv[]) {
transport::interface::global_config::IoModuleConfiguration io_config;
io_config.name = "hicnlight_module";
- while ((opt = getopt(argc, argv, "a:j::t:i:m:s:d:n:l:f:c:SAOqVDHz:F:")) !=
+ while ((opt = getopt(argc, argv, "a:b:j::t:i:m:s:d:n:l:f:c:SAOqVDHz:F:")) !=
-1) {
switch (opt) {
case 'a':
c->num_int_manifest_suffixes_ = std::stoi(optarg);
c->passphrase_ = argv[optind];
break;
+ case 'b':
+ c->traffic_generator_type_ = optarg;
+ break;
case 't':
c->ttl_ = uint8_t(std::stoi(optarg));
break;
diff --git a/apps/ping/src/ping_server.cc b/apps/ping/src/ping_server.cc
index 876efd133..b91b2c612 100644
--- a/apps/ping/src/ping_server.cc
+++ b/apps/ping/src/ping_server.cc
@@ -40,6 +40,38 @@ using CryptoSuite = auth::CryptoSuite;
class CallbackContainer {
const std::size_t log2_content_object_buffer_size = 12;
+ private:
+ std::shared_ptr<ContentObject> createContentObject(const Name &name,
+ uint32_t lifetime,
+ const Interest &interest) {
+ auto &content_object = content_objects_[content_objects_index_++ & mask_];
+
+ content_object->setName(name);
+ content_object->setLifetime(lifetime);
+ content_object->setLocator(interest.getLocator());
+ content_object->setSrcPort(interest.getDstPort());
+ content_object->setDstPort(interest.getSrcPort());
+ content_object->setTTL(ttl_);
+
+ if (verbose_) {
+ std::cout << ">>> send object " << content_object->getName()
+ << " src port: " << content_object->getSrcPort()
+ << " dst port: " << content_object->getDstPort()
+ << " TTL: " << (int)content_object->getTTL() << std::endl;
+ } else if (!quiet_) {
+ std::cout << ">>> send object " << content_object->getName() << std::endl;
+ }
+
+ if (dump_) {
+ std::cout << "----- object dump -----" << std::endl;
+ content_object->dump();
+ std::cout << "-----------------------" << std::endl;
+ }
+
+ if (sign_ && signer_) signer_->signPacket(content_object.get());
+ return content_object;
+ }
+
public:
CallbackContainer(const Name &prefix, uint32_t object_size, bool verbose,
bool dump, bool quiet, uint8_t ttl, auth::Signer *signer,
@@ -109,58 +141,22 @@ class CallbackContainer {
std::cout << "-------------------------" << std::endl;
}
- uint32_t *suffix = interest.firstSuffix();
- uint32_t n_suffixes_in_manifest = interest.numberOfSuffixes();
- hicn_uword *request_bitmap = interest.getRequestBitmap();
if (!interest.isValid()) throw std::runtime_error("Bad interest format");
-
Name name = interest.getName();
- uint32_t pos = 0; // Position of current suffix in manifest
- do {
- // If suffix can be processed, i.e. no manifest with bitmap excluding it
- if (!interest.hasManifest() ||
- bitmap_is_set_no_check(request_bitmap, pos)) {
- auto &content_object =
- content_objects_[content_objects_index_++ & mask_];
-
- content_object->setName(interest.getName());
- content_object->setLifetime(lifetime);
- content_object->setLocator(interest.getLocator());
- content_object->setSrcPort(interest.getDstPort());
- content_object->setDstPort(interest.getSrcPort());
- content_object->setTTL(ttl_);
-
- if (verbose_) {
- std::cout << ">>> send object " << content_object->getName()
- << " src port: " << content_object->getSrcPort()
- << " dst port: " << content_object->getDstPort()
- << " TTL: " << (int)content_object->getTTL() << std::endl;
- } else if (!quiet_) {
- std::cout << ">>> send object " << content_object->getName()
- << std::endl;
- }
-
- if (dump_) {
- std::cout << "----- object dump -----" << std::endl;
- content_object->dump();
- std::cout << "-----------------------" << std::endl;
- }
-
- if (sign_ && signer_) {
- signer_->signPacket(content_object.get());
- }
-
- p.produce(*content_object);
- }
- if (interest.hasManifest()) {
- uint32_t seq = *suffix;
- suffix++;
+ if (!interest.hasManifest()) { // Single interest
+ auto content_object = createContentObject(name, lifetime, interest);
+ p.produce(*content_object);
+ } else { // Interest manifest
+ uint32_t _, *suffix = NULL;
+ interest_manifest_foreach_suffix(interest.getIntManifestHeader(), suffix,
+ _) {
+ name.setSuffix(*suffix);
- Name name = interest.getName();
- interest.setName(name.setSuffix(seq));
+ auto content_object = createContentObject(name, lifetime, interest);
+ p.produce(*content_object);
}
- } while (pos++ < n_suffixes_in_manifest);
+ }
if (!quiet_) std::cout << std::endl;
}