diff options
Diffstat (limited to 'apps/hiperf/src')
-rw-r--r-- | apps/hiperf/src/client.cc | 64 | ||||
-rw-r--r-- | apps/hiperf/src/client.h | 4 | ||||
-rw-r--r-- | apps/hiperf/src/common.h | 55 | ||||
-rw-r--r-- | apps/hiperf/src/main.cc | 17 | ||||
-rw-r--r-- | apps/hiperf/src/server.cc | 46 |
5 files changed, 109 insertions, 77 deletions
diff --git a/apps/hiperf/src/client.cc b/apps/hiperf/src/client.cc index 0e1f596c5..1ce5b4c55 100644 --- a/apps/hiperf/src/client.cc +++ b/apps/hiperf/src/client.cc @@ -26,6 +26,20 @@ namespace hiperf { class RTCCallback; class Callback; +using transport::auth::CryptoHashType; +using transport::core::Packet; +using transport::core::Prefix; +using transport::interface::ConsumerCallbacksOptions; +using transport::interface::ConsumerSocket; +using transport::interface::GeneralTransportOptions; +using transport::interface::ProducerSocket; +using transport::interface::ProductionProtocolAlgorithms; +using transport::interface::RaaqmTransportOptions; +using transport::interface::RtcTransportOptions; +using transport::interface::RtcTransportRecoveryStrategies; +using transport::interface::StrategyCallback; +using transport::interface::TransportStatistics; + /** * Hiperf client class: configure and setup an hicn consumer following the * ClientConfiguration. @@ -207,12 +221,14 @@ class HIperfClient::Impl { void checkReceivedRtcContent( [[maybe_unused]] const ConsumerSocket &c, - [[maybe_unused]] const ContentObject &content_object) const { + [[maybe_unused]] const transport::core::ContentObject &content_object) + const { // Nothing to do here } - void processLeavingInterest(const ConsumerSocket & /*c*/, - const Interest & /*interest*/) const { + void processLeavingInterest( + const ConsumerSocket & /*c*/, + const transport::core::Interest & /*interest*/) const { // Nothing to do here } @@ -470,7 +486,7 @@ class HIperfClient::Impl { int setupRTCSocket() { int ret = ERROR_SUCCESS; - configuration_.transport_protocol_ = RTC; + configuration_.transport_protocol_ = transport::interface::RTC; if (configuration_.relay_ && configuration_.parallel_flows_ == 1) { int production_protocol = ProductionProtocolAlgorithms::RTC_PROD; @@ -563,7 +579,7 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT, - (ConsumerContentObjectCallback)std::bind( + (transport::interface::ConsumerContentObjectCallback)std::bind( &Impl::ConsumerContext::checkReceivedRtcContent, this, std::placeholders::_1, std::placeholders::_2)); if (ret == SOCKET_OPTION_NOT_SET) { @@ -572,7 +588,8 @@ class HIperfClient::Impl { std::shared_ptr<TransportStatistics> transport_stats; ret = consumer_socket_->getSocketOption( - OtherOptions::STATISTICS, (TransportStatistics **)&transport_stats); + transport::interface::OtherOptions::STATISTICS, + (TransportStatistics **)&transport_stats); transport_stats->setAlpha(0.0); if (ret == SOCKET_OPTION_NOT_SET) { @@ -585,7 +602,7 @@ class HIperfClient::Impl { int setupRAAQMSocket() { int ret = ERROR_SUCCESS; - configuration_.transport_protocol_ = RAAQM; + configuration_.transport_protocol_ = transport::interface::RAAQM; consumer_socket_ = std::make_unique<ConsumerSocket>(configuration_.transport_protocol_); @@ -610,7 +627,7 @@ class HIperfClient::Impl { } int setupCBRSocket() { - configuration_.transport_protocol_ = CBR; + configuration_.transport_protocol_ = transport::interface::CBR; consumer_socket_ = std::make_unique<ConsumerSocket>(configuration_.transport_protocol_); @@ -621,7 +638,8 @@ class HIperfClient::Impl { public: int setup() { int ret; - std::shared_ptr<Verifier> verifier = std::make_shared<VoidVerifier>(); + std::shared_ptr<transport::auth::Verifier> verifier = + std::make_shared<transport::auth::VoidVerifier>(); if (configuration_.rtc_) { ret = setupRTCSocket(); @@ -669,7 +687,8 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::FWD_STRATEGY_CHANGE, (StrategyCallback)[]( - [[maybe_unused]] notification::Strategy strategy){ + [[maybe_unused]] transport::interface::notification::Strategy + strategy){ // nothing to do }); if (ret == SOCKET_OPTION_NOT_SET) { @@ -679,15 +698,16 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::REC_STRATEGY_CHANGE, (StrategyCallback)[]( - [[maybe_unused]] notification::Strategy strategy){ + [[maybe_unused]] transport::interface::notification::Strategy + strategy){ // nothing to do }); if (ret == SOCKET_OPTION_NOT_SET) { return ERROR_SETUP; } - ret = consumer_socket_->setSocketOption(CURRENT_WINDOW_SIZE, - configuration_.window_); + ret = consumer_socket_->setSocketOption( + transport::interface::CURRENT_WINDOW_SIZE, configuration_.window_); if (ret == SOCKET_OPTION_NOT_SET) { getOutputStream() << "ERROR -- Impossible to set the size of the window." @@ -696,13 +716,13 @@ class HIperfClient::Impl { } if (!configuration_.producer_certificate_.empty()) { - verifier = std::make_shared<AsymmetricVerifier>( + verifier = std::make_shared<transport::auth::AsymmetricVerifier>( configuration_.producer_certificate_); } if (!configuration_.passphrase_.empty()) { - verifier = - std::make_shared<SymmetricVerifier>(configuration_.passphrase_); + verifier = std::make_shared<transport::auth::SymmetricVerifier>( + configuration_.passphrase_); } verifier->setVerificationFailedCallback( @@ -716,10 +736,12 @@ class HIperfClient::Impl { } // Signer for aggregatd interests - std::shared_ptr<Signer> signer = std::make_shared<VoidSigner>(); + std::shared_ptr<transport::auth::Signer> signer = + std::make_shared<transport::auth::VoidSigner>(); if (!configuration_.aggr_interest_passphrase_.empty()) { - signer = std::make_shared<SymmetricSigner>( - CryptoSuite::HMAC_SHA256, configuration_.aggr_interest_passphrase_); + signer = std::make_shared<transport::auth::SymmetricSigner>( + transport::auth::CryptoSuite::HMAC_SHA256, + configuration_.aggr_interest_passphrase_); } ret = consumer_socket_->setSocketOption(GeneralTransportOptions::SIGNER, signer); @@ -734,7 +756,7 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::INTEREST_OUTPUT, - (ConsumerInterestCallback)std::bind( + (transport::interface::ConsumerInterestCallback)std::bind( &ConsumerContext::processLeavingInterest, this, std::placeholders::_1, std::placeholders::_2)); @@ -751,7 +773,7 @@ class HIperfClient::Impl { ret = consumer_socket_->setSocketOption( ConsumerCallbacksOptions::STATS_SUMMARY, - (ConsumerTimerCallback)std::bind( + (transport::interface::ConsumerTimerCallback)std::bind( &Impl::ConsumerContext::handleTimerExpiration, this, std::placeholders::_1, std::placeholders::_2)); diff --git a/apps/hiperf/src/client.h b/apps/hiperf/src/client.h index c4c6bc2ae..beecbd473 100644 --- a/apps/hiperf/src/client.h +++ b/apps/hiperf/src/client.h @@ -20,7 +20,7 @@ namespace hiperf { -class HIperfClient : private ::utils::NonCopyable { +class HIperfClient : public ::utils::NonCopyable { public: explicit HIperfClient(const ClientConfiguration &conf); @@ -33,4 +33,4 @@ class HIperfClient : private ::utils::NonCopyable { std::unique_ptr<Impl> impl_; }; -} // namespace hiperf
\ No newline at end of file +} // namespace hiperf diff --git a/apps/hiperf/src/common.h b/apps/hiperf/src/common.h index 1565e63f7..0f96bef1f 100644 --- a/apps/hiperf/src/common.h +++ b/apps/hiperf/src/common.h @@ -44,23 +44,22 @@ #ifndef ERROR_SUCCESS #define ERROR_SUCCESS 0 #endif -#define ERROR_SETUP -5 -#define MIN_PROBE_SEQ 0xefffffff -#define RTC_HEADER_SIZE 12 -#define FEC_HEADER_MAX_SIZE 36 -#define HIPERF_MTU 1500 - -using namespace transport::interface; -using namespace transport::auth; -using namespace transport::core; +static constexpr int ERROR_SETUP = -5; +static constexpr uint32_t MIN_PROBE_SEQ = 0xefffffff; +static constexpr uint32_t RTC_HEADER_SIZE = 12; +static constexpr uint32_t FEC_HEADER_MAX_SIZE = 36; +static constexpr uint32_t HIPERF_MTU = 1500; namespace hiperf { +using transport::core::Packet; +using transport::core::Prefix; + /** * Logger */ template <typename D, typename ConfType, typename ParentType> -class Base : protected std::stringbuf, protected std::ostream { +class Base : public std::stringbuf, public std::ostream { protected: static inline const char separator[] = "| "; @@ -88,7 +87,7 @@ class Base : protected std::stringbuf, protected std::ostream { end_ = end.str(); } - Base(Base &&other) + Base(Base &&other) noexcept : parent_(other.parent_), configuration_(other.configuration_), io_service_(other.io_service_), @@ -96,6 +95,8 @@ class Base : protected std::stringbuf, protected std::ostream { name_id_(std::move(other.name_id_)), flow_name_(other.flow_name_) {} + ~Base() {} + /*************************************************************** * std::stringbuf sync override ***************************************************************/ @@ -142,7 +143,7 @@ static inline int ensureFlows(const Prefix &prefix, std::size_t flows) { } else { LoggerErr() << "Error: unknown address family."; ret = ERROR_SETUP; - goto end; + goto END; } log2_n_flow = max_ip_addr_len_bits - prefix.getPrefixLength(); @@ -155,7 +156,7 @@ static inline int ensureFlows(const Prefix &prefix, std::size_t flows) { ret = ERROR_SETUP; } -end: +END: return ret; } @@ -184,18 +185,10 @@ class PayloadSize { */ class Rate { public: - Rate() : rate_kbps_(0) {} + Rate() {} ~Rate() {} - Rate &operator=(const Rate &other) { - if (this != &other) { - rate_kbps_ = other.rate_kbps_; - } - - return *this; - } - - Rate(const std::string &rate) { + explicit Rate(const std::string &rate) { std::size_t found = rate.find("kbps"); if (found != std::string::npos) { rate_kbps_ = std::stof(rate.substr(0, found)); @@ -223,7 +216,7 @@ class Rate { } private: - float rate_kbps_; + float rate_kbps_ = 0.0; }; struct packet_t { @@ -238,7 +231,8 @@ struct Configuration { bool rtc_{false}; uint16_t port_{0}; bool aggregated_data_{false}; - Packet::Format packet_format_{default_values::packet_format}; + Packet::Format packet_format_{ + transport::interface::default_values::packet_format}; uint32_t parallel_flows_{1}; bool colored_{true}; }; @@ -246,15 +240,15 @@ struct Configuration { /** * Container for command line configuration for hiperf client. */ -struct ClientConfiguration : public Configuration { +struct ClientConfiguration : Configuration { double beta_{-1.f}; double drop_factor_{-1.f}; double window_{-1.f}; std::string producer_certificate_; - std::string passphrase_; std::size_t receive_buffer_size_{128 * 1024}; std::uint32_t report_interval_milliseconds_{1000}; - TransportProtocolAlgorithms transport_protocol_{CBR}; + transport::interface::TransportProtocolAlgorithms transport_protocol_{ + transport::interface::CBR}; bool test_mode_{false}; bool relay_{false}; Prefix producer_prefix_; @@ -274,14 +268,15 @@ struct ClientConfiguration : public Configuration { /** * Container for command line configuration for hiperf server. */ -struct ServerConfiguration : public Configuration { +struct ServerConfiguration : Configuration { bool virtual_producer_{true}; std::uint32_t manifest_max_capacity_{0}; bool live_production_{false}; std::uint32_t content_lifetime_{ transport::interface::default_values::content_object_expiry_time}; std::uint32_t download_size_{20 * 1024 * 1024}; - CryptoHashType hash_algorithm_{CryptoHashType::SHA256}; + transport::auth::CryptoHashType hash_algorithm_{ + transport::auth::CryptoHashType::SHA256}; std::string keystore_name_; std::string keystore_password_{"cisco"}; bool multiphase_produce_{false}; diff --git a/apps/hiperf/src/main.cc b/apps/hiperf/src/main.cc index d655b1fe3..25c1a288c 100644 --- a/apps/hiperf/src/main.cc +++ b/apps/hiperf/src/main.cc @@ -19,14 +19,18 @@ namespace hiperf { +using transport::auth::CryptoHashType; + static std::unordered_map<std::string, hicn_packet_format_t> const packet_format_map = {{"ipv4_tcp", HICN_PACKET_FORMAT_IPV4_TCP}, {"ipv6_tcp", HICN_PACKET_FORMAT_IPV6_TCP}, {"new", HICN_PACKET_FORMAT_NEW}}; -#define TO_LOWER(s) \ - std::transform(s.begin(), s.end(), s.begin(), \ +std::string str_tolower(std::string s) { + std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); }); + return s; +} void usage() { LoggerInfo() << "HIPERF - Instrumentation tool for performing active network" @@ -187,7 +191,7 @@ void usage() { "defaults to IPV6_TCP)"; } -int main(int argc, char *argv[]) { +int hiperf_main(int argc, char *argv[]) { #ifndef _WIN32 // Common bool daemon = false; @@ -202,7 +206,7 @@ int main(int argc, char *argv[]) { int role = 0; int options = 0; - char *log_file = nullptr; + const char *log_file = nullptr; transport::interface::global_config::IoModuleConfiguration config; std::string conf_file; config.name = "hicnlight_module"; @@ -282,7 +286,7 @@ int main(int argc, char *argv[]) { } case 'w': { std::string packet_format_s = std::string(optarg); - TO_LOWER(packet_format_s); + packet_format_s = str_tolower(packet_format_s); auto it = packet_format_map.find(std::string(optarg)); if (it == packet_format_map.end()) throw std::runtime_error("Bad packet format"); @@ -476,7 +480,6 @@ int main(int argc, char *argv[]) { options = -1; break; } - case 'h': default: usage(); return EXIT_FAILURE; @@ -565,4 +568,4 @@ int main(int argc, char *argv[]) { } // namespace hiperf -int main(int argc, char *argv[]) { return hiperf::main(argc, argv); } +int main(int argc, char *argv[]) { return hiperf::hiperf_main(argc, argv); } diff --git a/apps/hiperf/src/server.cc b/apps/hiperf/src/server.cc index b338c69df..3f6c335f9 100644 --- a/apps/hiperf/src/server.cc +++ b/apps/hiperf/src/server.cc @@ -17,18 +17,25 @@ namespace hiperf { +using transport::core::ContentObject; +using transport::core::Interest; +using transport::core::Name; +using transport::interface::GeneralTransportOptions; +using transport::interface::ProducerCallbacksOptions; +using transport::interface::ProducerInterestCallback; +using transport::interface::ProducerSocket; +using transport::interface::ProductionProtocolAlgorithms; + /** * Hiperf server class: configure and setup an hicn producer following the * ServerConfiguration. */ class HIperfServer::Impl { - static inline constexpr std::size_t klog2_content_object_buffer_size() { - return 8; - } - static inline constexpr std::size_t kcontent_object_buffer_size() { + static constexpr std::size_t klog2_content_object_buffer_size() { return 8; } + static constexpr std::size_t kcontent_object_buffer_size() { return (1 << klog2_content_object_buffer_size()); } - static inline constexpr std::size_t kmask() { + static constexpr std::size_t kmask() { return (kcontent_object_buffer_size() - 1); } @@ -58,7 +65,8 @@ class HIperfServer::Impl { content_objects_.emplace_back(std::make_shared<ContentObject>( configuration_.name_.makeName(), configuration_.packet_format_, 0, (const uint8_t *)buffer.data(), buffer.size())); - element->setLifetime(default_values::content_object_expiry_time); + element->setLifetime( + transport::interface::default_values::content_object_expiry_time); } } @@ -92,7 +100,8 @@ class HIperfServer::Impl { int setup() { int ret; int production_protocol; - std::shared_ptr<Signer> signer = std::make_shared<VoidSigner>(); + std::shared_ptr<transport::auth::Signer> signer = + std::make_shared<transport::auth::VoidSigner>(); if (!configuration_.rtc_) { production_protocol = ProductionProtocolAlgorithms::BYTE_STREAM; @@ -121,7 +130,7 @@ class HIperfServer::Impl { return ERROR_SETUP; } - if (producer_socket_->setSocketOption(PACKET_FORMAT, + if (producer_socket_->setSocketOption(transport::interface::PACKET_FORMAT, configuration_.packet_format_) == SOCKET_OPTION_NOT_SET) { getOutputStream() << "ERROR -- Impossible to set the packet format." @@ -130,12 +139,13 @@ class HIperfServer::Impl { } if (!configuration_.passphrase_.empty()) { - signer = std::make_shared<SymmetricSigner>(CryptoSuite::HMAC_SHA256, - configuration_.passphrase_); + signer = std::make_shared<transport::auth::SymmetricSigner>( + transport::auth::CryptoSuite::HMAC_SHA256, + configuration_.passphrase_); } if (!configuration_.keystore_name_.empty()) { - signer = std::make_shared<AsymmetricSigner>( + signer = std::make_shared<transport::auth::AsymmetricSigner>( configuration_.keystore_name_, configuration_.keystore_password_); } @@ -161,9 +171,10 @@ class HIperfServer::Impl { } // Verifier for aggregated interests - std::shared_ptr<Verifier> verifier = std::make_shared<VoidVerifier>(); + std::shared_ptr<transport::auth::Verifier> verifier = + std::make_shared<transport::auth::VoidVerifier>(); if (!configuration_.aggr_interest_passphrase_.empty()) { - verifier = std::make_unique<SymmetricVerifier>( + verifier = std::make_unique<transport::auth::SymmetricVerifier>( configuration_.aggr_interest_passphrase_); } ret = producer_socket_->setSocketOption(GeneralTransportOptions::VERIFIER, @@ -172,7 +183,7 @@ class HIperfServer::Impl { if (configuration_.rtc_) { ret = producer_socket_->setSocketOption( - RtcTransportOptions::AGGREGATED_DATA, + transport::interface::RtcTransportOptions::AGGREGATED_DATA, configuration_.aggregated_data_); if (ret == SOCKET_OPTION_NOT_SET) { @@ -249,7 +260,7 @@ class HIperfServer::Impl { ret = producer_socket_->setSocketOption( ProducerCallbacksOptions::CONTENT_PRODUCED, - (ProducerContentCallback)bind( + (transport::interface::ProducerContentCallback)bind( &ProducerContext::onContentProduced, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); if (ret == SOCKET_OPTION_NOT_SET) { @@ -308,8 +319,9 @@ class HIperfServer::Impl { * @brief Synchronously produce content upon reception of one interest */ void processInterest(ProducerSocket &p, const Interest &interest) const { - p.setSocketOption(ProducerCallbacksOptions::CACHE_MISS, - (ProducerInterestCallback)VOID_HANDLER); + p.setSocketOption( + ProducerCallbacksOptions::CACHE_MISS, + (ProducerInterestCallback)transport::interface::VOID_HANDLER); p.setSocketOption(GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME, configuration_.content_lifetime_); |