diff options
Diffstat (limited to 'apps/ping')
-rw-r--r-- | apps/ping/CMakeLists.txt | 8 | ||||
-rw-r--r-- | apps/ping/src/ping_client.cc | 218 | ||||
-rw-r--r-- | apps/ping/src/ping_server.cc | 136 |
3 files changed, 156 insertions, 206 deletions
diff --git a/apps/ping/CMakeLists.txt b/apps/ping/CMakeLists.txt index a094cebe3..ab3fdf56d 100644 --- a/apps/ping/CMakeLists.txt +++ b/apps/ping/CMakeLists.txt @@ -36,7 +36,9 @@ set(COMPILER_OPTIONS build_executable(hicn-ping-server SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/ping_server.cc LINK_LIBRARIES ${PING_LIBRARIES} - DEPENDS ${DEPENDENCIES} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} + DEPENDS ${DEPENDENCIES} ${THIRD_PARTY_DEPENDENCIES} COMPONENT ${HICN_APPS} LINK_FLAGS ${LINK_FLAGS} COMPILE_OPTIONS ${COMPILER_OPTIONS} @@ -48,7 +50,9 @@ set(COMPILER_OPTIONS build_executable(hicn-ping-client SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/ping_client.cc LINK_LIBRARIES ${PING_LIBRARIES} - DEPENDS ${DEPENDENCIES} + INCLUDE_DIRS + PRIVATE ${THIRD_PARTY_INCLUDE_DIRS} ${COMMON_INCLUDE_DIRS} + DEPENDS ${DEPENDENCIES} ${THIRD_PARTY_DEPENDENCIES} COMPONENT ${HICN_APPS} LINK_FLAGS ${LINK_FLAGS} COMPILE_OPTIONS ${COMPILER_OPTIONS} diff --git a/apps/ping/src/ping_client.cc b/apps/ping/src/ping_client.cc index 6599b74cb..539e84ada 100644 --- a/apps/ping/src/ping_client.cc +++ b/apps/ping/src/ping_client.cc @@ -13,6 +13,7 @@ * limitations under the License. */ +#include <hicn/apps/utils/logger.h> #include <hicn/transport/auth/signer.h> #include <hicn/transport/auth/verifier.h> #include <hicn/transport/core/global_object_pool.h> @@ -56,10 +57,7 @@ class Configuration { std::string traffic_generator_type_; uint16_t srcPort_ = 9695; uint16_t dstPort_ = 8080; - bool verbose_ = false; - bool dump_ = false; bool jump_ = false; - bool quiet_ = false; uint32_t jump_freq_ = 0; uint32_t jump_size_ = 0; uint8_t ttl_ = 64; @@ -101,7 +99,7 @@ class Client : private interface::Portal::TransportCallback { virtual ~Client() = default; void ping() { - std::cout << "start ping" << std::endl; + LoggerInfo() << "Starting ping..."; portal_.getThread().add([this]() { portal_.connect(); @@ -124,10 +122,10 @@ class Client : private interface::Portal::TransportCallback { if (verifier_.verifyPacket(&object)) { 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; + LoggerInfo() << "Verification time: " << dt.count(); + LoggerInfo() << "<<< Signature Ok."; } else { - std::cout << "<<< Signature verification failed!" << std::endl; + LoggerErr() << "<<< Signature verification failed!"; } } @@ -139,39 +137,38 @@ class Client : private interface::Portal::TransportCallback { send_timestamps_.erase(it); } - if (config_->verbose_) { - std::cout << "<<< recevied object. " << std::endl; - 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() - << " src port: " << object.getSrcPort() - << " dst port: " << object.getDstPort() << " path label " - << object.getPathLabel() << " (" - << (object.getPathLabel() >> 24) << ")" - << " TTL: " << (int)object.getTTL() << std::endl; - } else if (!config_->quiet_) { - std::cout << "<<< received object. " << std::endl; - std::cout << "<<< round trip: " << rtt << " [us]" << 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]" - << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << "<<< recevied object. "; + LoggerInfo() << "<<< interest name: " << interest.getName().getPrefix() + << " (n_suffixes=" << config_->num_int_manifest_suffixes_ + << ")" + << " src port: " << interest.getSrcPort() + << " dst port: " << interest.getDstPort(); + LoggerInfo() << "<<< object name: " << object.getName() + << " src port: " << object.getSrcPort() + << " dst port: " << object.getDstPort() << " path label " + << object.getPathLabel() << " (" + << (object.getPathLabel() >> 24) << ")" + << " TTL: " << (int)object.getTTL(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << "<<< received object. "; + LoggerInfo() << "<<< round trip: " << rtt << " [us]"; + LoggerInfo() << "<<< interest name: " << interest.getName().getPrefix(); + + LoggerInfo() << "<<< object name: " << object.getName(); + LoggerInfo() << "<<< content object size: " + << object.payloadSize() + object.headerSize() << " [bytes]"; } - if (config_->dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest.dump(); - std::cout << "-------------------------" << std::endl; - std::cout << "----- object dump -------" << std::endl; + LoggerInfo() << "-------------------------"; + LoggerInfo() << "----- object dump -------"; object.dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } - - if (!config_->quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; received_++; processed_++; @@ -181,32 +178,28 @@ class Client : private interface::Portal::TransportCallback { } void onTimeout(Interest::Ptr &interest, const Name &name) override { - if (config_->verbose_) { - std::cout << "### timeout for " << name - << " src port: " << interest->getSrcPort() - << " dst port: " << interest->getDstPort() << std::endl; - } else if (!config_->quiet_) { - std::cout << "### timeout for " << name << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << "### timeout for " << name + << " src port: " << interest->getSrcPort() + << " dst port: " << interest->getDstPort(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << "### timeout for " << name; } - if (config_->dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest->dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } - - if (!config_->quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; timedout_++; processed_++; - if (processed_ >= config_->maxPing_) { - afterSignal(); - } + if (processed_ >= config_->maxPing_) afterSignal(); } void onError(const std::error_code &ec) override { - std::cout << "Aborting ping due to internal error: " << ec.message() - << std::endl; + LoggerErr() << "Aborting ping due to internal error: " << ec.message(); afterSignal(); } @@ -235,18 +228,17 @@ class Client : private interface::Portal::TransportCallback { interest->setDstPort(config_->dstPort_); interest->setTTL(config_->ttl_); - if (config_->verbose_) { - std::cout << ">>> send interest " << interest->getName() - << " src port: " << interest->getSrcPort() - << " dst port: " << interest->getDstPort() - << " TTL: " << (int)interest->getTTL() - << " suffixes in manifest: " - << config_->num_int_manifest_suffixes_ << std::endl; - } else if (!config_->quiet_) { - std::cout << ">>> send interest " << interest->getName() << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << ">>> send interest " << interest->getName() + << " src port: " << interest->getSrcPort() + << " dst port: " << interest->getDstPort() + << " TTL: " << (int)interest->getTTL() + << " suffixes in manifest: " + << config_->num_int_manifest_suffixes_; + } else if (LoggerIsOn(1)) { + LoggerInfo() << ">>> send interest " << interest->getName(); } - - if (!config_->quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; send_timestamps_[sequence_number] = utils::SteadyTime::now(); for (uint32_t i = 0; i < config_->num_int_manifest_suffixes_ && @@ -258,10 +250,10 @@ class Client : private interface::Portal::TransportCallback { send_timestamps_[sequence_number] = utils::SteadyTime::now(); } - if (config_->dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest->dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } interest->encodeSuffixes(); @@ -280,10 +272,9 @@ class Client : private interface::Portal::TransportCallback { } void afterSignal() { - std::cout << "Stop ping" << std::endl; - std::cout << "Sent: " << traffic_generator_->getSentCount() - << " Received: " << received_ << " Timeouts: " << timedout_ - << std::endl; + LoggerInfo() << "Stopping ping..."; + LoggerInfo() << "Sent: " << traffic_generator_->getSentCount() + << " Received: " << received_ << " Timeouts: " << timedout_; io_service_.stop(); } @@ -315,45 +306,38 @@ class Client : private interface::Portal::TransportCallback { }; void help() { - std::cout << "usage: hicn-consumer-ping [options]" << std::endl; - std::cout << "PING options" << std::endl; - std::cout - << "-i <val> ping interval in microseconds (default 1000000ms)" - << std::endl; - std::cout << "-m <val> maximum number of pings to send (default 10)" - << std::endl; - std::cout << "-s <val> sorce port (default 9695)" << std::endl; - std::cout << "-d <val> destination port (default 8080)" << std::endl; - std::cout << "-t <val> set packet ttl (default 64)" << std::endl; - std::cout << "-a <val> <pass> set the passphrase and the number of " - "suffixes in interest manifest (default 0);" - << std::endl; - std::cout << " e.g. '-m 6 -a -2' sends two interest (0 and " - "3) with 2 suffixes each (1,2 and 4,5 respectively)" - << std::endl; - std::cout << "HICN options" << std::endl; - std::cout << "-n <val> hicn name (default b001::1)" << std::endl; - std::cout - << "-l <val> interest lifetime in milliseconds (default 500ms)" - << std::endl; - std::cout << "OUTPUT options" << std::endl; - 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 << "-q quiet, not prints (default false)" - << std::endl; - std::cerr << "-z <io_module> IO module to use. Default: hicnlight_module" - << std::endl; - 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; + LoggerInfo() << "usage: hicn-consumer-ping [options]"; + LoggerInfo() << "PING options"; + LoggerInfo() << "-i <val> ping interval in microseconds (default " + "1000000ms)"; + LoggerInfo() + << "-m <val> maximum number of pings to send (default 10)"; + LoggerInfo() << "-s <val> sorce port (default 9695)"; + LoggerInfo() << "-d <val> destination port (default 8080)"; + LoggerInfo() << "-t <val> set packet ttl (default 64)"; + LoggerInfo() << "-a <val> <pass> set the passphrase and the number of " + "suffixes in interest manifest (default 0);"; + LoggerInfo() + << " e.g. '-m 6 -a -2' sends two interest (0 and " + "3) with 2 suffixes each (1,2 and 4,5 respectively)"; + LoggerInfo() << "HICN options"; + LoggerInfo() << "-n <val> hicn name (default b001::1)"; + LoggerInfo() + << "-l <val> interest lifetime in milliseconds (default " + "500ms)"; + LoggerInfo() << "OUTPUT options"; + LoggerInfo() << "-V verbose, prints statistics about the " + "messagges sent and received (default false)"; + LoggerInfo() << "-D dump, dumps sent and received packets " + "(default false)"; + LoggerInfo() << "-q quiet, not prints (default false)"; + LoggerInfo() + << "-z <io_module> IO module to use. Default: hicnlight_module"; + LoggerInfo() << "-F <conf_file> Path to optional configuration file for " + "libtransport"; + LoggerInfo() << "-b <type> Traffic generator type. Use 'RANDOM' for " + "random prefixes and suffixes. Default: sequential suffixes."; + LoggerInfo() << "-H prints this message"; } int start(int argc, char *argv[]) { @@ -372,7 +356,7 @@ int start(int argc, char *argv[]) { transport::interface::global_config::IoModuleConfiguration io_config; io_config.name = "hicnlight_module"; - while ((opt = getopt(argc, argv, "a:b: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:SAOHz:F:")) != -1) { switch (opt) { case 'a': @@ -406,17 +390,6 @@ int start(int argc, char *argv[]) { case 'l': c->interestLifetime_ = std::stoi(optarg); break; - case 'V': - c->verbose_ = true; - break; - case 'D': - c->dump_ = true; - break; - case 'q': - c->quiet_ = true; - c->verbose_ = false; - c->dump_ = false; - break; case 'c': c->certificate_ = std::string(optarg); break; @@ -449,9 +422,8 @@ int start(int argc, char *argv[]) { ping->ping(); auto t1 = std::chrono::steady_clock::now(); - std::cout << "Elapsed time: " - << utils::SteadyTime::getDurationMs(t0, t1).count() << "ms" - << std::endl; + LoggerInfo() << "Elapsed time: " + << utils::SteadyTime::getDurationMs(t0, t1).count() << "ms"; #ifdef _WIN32 WSACleanup(); diff --git a/apps/ping/src/ping_server.cc b/apps/ping/src/ping_server.cc index 325ef675c..b2806ba64 100644 --- a/apps/ping/src/ping_server.cc +++ b/apps/ping/src/ping_server.cc @@ -21,6 +21,7 @@ #include <openssl/applink.c> #endif +#include <hicn/apps/utils/logger.h> #include <hicn/transport/auth/signer.h> #include <hicn/transport/auth/verifier.h> #include <hicn/transport/core/content_object.h> @@ -53,19 +54,19 @@ class CallbackContainer { 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 (LoggerIsOn(2)) { + LoggerInfo() << ">>> send object " << content_object->getName() + << " src port: " << content_object->getSrcPort() + << " dst port: " << content_object->getDstPort() + << " TTL: " << (int)content_object->getTTL(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << ">>> send object " << content_object->getName(); } - if (dump_) { - std::cout << "----- object dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- object dump -----"; content_object->dump(); - std::cout << "-----------------------" << std::endl; + LoggerInfo() << "-----------------------"; } if (sign_ && signer_) signer_->signPacket(content_object.get()); @@ -73,16 +74,13 @@ class CallbackContainer { } public: - CallbackContainer(const Name &prefix, uint32_t object_size, bool verbose, - bool dump, bool quiet, uint8_t ttl, auth::Signer *signer, - bool sign, std::string passphrase, uint32_t lifetime) + CallbackContainer(const Name &prefix, uint32_t object_size, uint8_t ttl, + auth::Signer *signer, bool sign, std::string passphrase, + 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), content_objects_index_(0), - verbose_(verbose), - dump_(dump), - quiet_(quiet), ttl_(ttl), signer_(signer), sign_(sign) { @@ -117,28 +115,27 @@ class CallbackContainer { if (verifier_->verifyPacket(&interest)) { 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; + LoggerInfo() << "Verification time: " << dt.count(); + LoggerInfo() << "<<< Signature Ok."; } else { - std::cout << "<<< Signature verification failed!" << std::endl; + LoggerErr() << "<<< Signature verification failed!"; } } - if (verbose_) { - std::cout << "<<< received interest " << interest.getName() - << " src port: " << interest.getSrcPort() - << " dst port: " << interest.getDstPort() - << "TTL: " << (int)interest.getTTL() - << " suffixes in manifest: " << interest.numberOfSuffixes() - << std::endl; - } else if (!quiet_) { - std::cout << "<<< received interest " << interest.getName() << std::endl; + if (LoggerIsOn(2)) { + LoggerInfo() << "<<< received interest " << interest.getName() + << " src port: " << interest.getSrcPort() + << " dst port: " << interest.getDstPort() + << "TTL: " << (int)interest.getTTL() + << " suffixes in manifest: " << interest.numberOfSuffixes(); + } else if (LoggerIsOn(1)) { + LoggerInfo() << "<<< received interest " << interest.getName(); } - if (dump_) { - std::cout << "----- interest dump -----" << std::endl; + if (LoggerIsOn(3)) { + LoggerInfo() << "----- interest dump -----"; interest.dump(); - std::cout << "-------------------------" << std::endl; + LoggerInfo() << "-------------------------"; } if (!interest.isValid()) throw std::runtime_error("Bad interest format"); @@ -160,7 +157,7 @@ class CallbackContainer { } } - if (!quiet_) std::cout << std::endl; + LoggerVerbose(1) << "\n"; } private: @@ -168,9 +165,6 @@ class CallbackContainer { std::vector<std::shared_ptr<ContentObject>> content_objects_; std::uint16_t mask_; std::uint16_t content_objects_index_; - bool verbose_; - bool dump_; - bool quiet_; uint8_t ttl_; auth::Signer *signer_; bool sign_; @@ -178,32 +172,27 @@ class CallbackContainer { }; 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 << "-l data lifetime" << 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::endl; - std::cout << "-D dump, dumps sent and received packets " - "(default false)" - << std::endl; - std::cout << "-q quiet, not prints (default false)" - << std::endl; - std::cerr << "-z <io_module> IO module to use. Default: hicnlight_module" - << std::endl; - std::cerr << "-F <conf_file> Path to optional configuration file for " - "libtransport" - << std::endl; + LoggerInfo() << "usage: hicn-preoducer-ping [options]"; + LoggerInfo() << "PING options"; + LoggerInfo() << "-s <val> object content size (default 1350B)"; + LoggerInfo() << "-n <val> hicn name (default b001::/64)"; + LoggerInfo() << "-l data lifetime"; + LoggerInfo() << "-t set ttl (default 64)"; + LoggerInfo() << "OUTPUT options"; + LoggerInfo() << "-V verbose, prints statistics about the " + "messagges sent " + " and received (default false)"; + LoggerInfo() << "-D dump, dumps sent and received packets " + "(default false)"; + LoggerInfo() << "-q quiet, not prints (default false)"; + LoggerInfo() + << "-z <io_module> IO module to use. Default: hicnlight_module"; + LoggerInfo() << "-F <conf_file> Path to optional configuration file for " + "libtransport"; #ifndef _WIN32 - std::cout << "-d daemon mode" << std::endl; + LoggerInfo() << "-d daemon mode"; #endif - std::cout << "-H prints this message" << std::endl; + LoggerInfo() << "-H prints this message"; } int main(int argc, char **argv) { @@ -216,9 +205,6 @@ int main(int argc, char **argv) { #endif std::string name_prefix = "b001::0/64"; std::string delimiter = "/"; - bool verbose = false; - bool dump = false; - bool quiet = false; uint32_t object_size = 1250; uint8_t ttl = 64; std::string keystore_path = "./rsa_crypto_material.p12"; @@ -233,9 +219,9 @@ int main(int argc, char **argv) { int opt; #ifndef _WIN32 - while ((opt = getopt(argc, argv, "a:s:n:t:l:qfrVDdHk:p:z:F:")) != -1) { + while ((opt = getopt(argc, argv, "a:s:n:t:l:frdHk:p:z:F:")) != -1) { #else - while ((opt = getopt(argc, argv, "s:n:t:l:qfrVDHk:p:z:F:")) != -1) { + while ((opt = getopt(argc, argv, "s:n:t:l:frHk:p:z:F:")) != -1) { #endif switch (opt) { case 'a': @@ -253,17 +239,6 @@ int main(int argc, char **argv) { case 'l': data_lifetime = std::stoi(optarg); break; - case 'V': - verbose = true; - break; - case 'D': - dump = true; - break; - case 'q': - verbose = false; - dump = false; - quiet = true; - break; #ifndef _WIN32 case 'd': daemon = true; @@ -319,13 +294,12 @@ int main(int argc, char **argv) { if (sign) { signer = std::make_unique<auth::AsymmetricSigner>(keystore_path, keystore_password); - stubs = - new CallbackContainer(n, object_size, verbose, dump, quiet, ttl, - signer.get(), sign, passphrase, data_lifetime); + stubs = new CallbackContainer(n, object_size, ttl, signer.get(), sign, + passphrase, data_lifetime); } else { auth::Signer *signer = nullptr; - stubs = new CallbackContainer(n, object_size, verbose, dump, quiet, ttl, - signer, sign, passphrase, data_lifetime); + stubs = new CallbackContainer(n, object_size, ttl, signer, sign, passphrase, + data_lifetime); } ProducerSocket p; @@ -346,7 +320,7 @@ int main(int argc, char **argv) { asio::signal_set signal_set(io_service, SIGINT); signal_set.async_wait( [&p, &io_service](const std::error_code &, const int &) { - std::cout << "STOPPING!!" << std::endl; + LoggerInfo() << "STOPPING!!"; p.stop(); io_service.stop(); }); |