diff options
Diffstat (limited to 'apps/ping/src')
-rw-r--r-- | apps/ping/src/ping_client.cc | 109 | ||||
-rw-r--r-- | apps/ping/src/ping_server.cc | 61 |
2 files changed, 73 insertions, 97 deletions
diff --git a/apps/ping/src/ping_client.cc b/apps/ping/src/ping_client.cc index 539e84ada..116d228d4 100644 --- a/apps/ping/src/ping_client.cc +++ b/apps/ping/src/ping_client.cc @@ -55,12 +55,10 @@ class Configuration { std::string certificate_; std::string passphrase_; std::string traffic_generator_type_; - uint16_t srcPort_ = 9695; - uint16_t dstPort_ = 8080; bool jump_ = false; uint32_t jump_freq_ = 0; uint32_t jump_size_ = 0; - uint8_t ttl_ = 64; + hicn_packet_format_t packet_format_ = HICN_PACKET_FORMAT_IPV6_TCP; Configuration() = default; }; @@ -111,7 +109,7 @@ class Client : private interface::Portal::TransportCallback { } void onInterest(Interest &interest) override { - throw errors::RuntimeException("Unexpected interest received."); + LoggerInfo() << "Unexpected interest received."; } void onContentObject(Interest &interest, ContentObject &object) override { @@ -141,15 +139,10 @@ class Client : private interface::Portal::TransportCallback { 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 " + << ")"; + LoggerInfo() << "<<< object name: " << object.getName() << " path label " << object.getPathLabel() << " (" - << (object.getPathLabel() >> 24) << ")" - << " TTL: " << (int)object.getTTL(); + << (object.getPathLabel() >> 24) << ")"; } else if (LoggerIsOn(1)) { LoggerInfo() << "<<< received object. "; LoggerInfo() << "<<< round trip: " << rtt << " [us]"; @@ -179,9 +172,7 @@ class Client : private interface::Portal::TransportCallback { void onTimeout(Interest::Ptr &interest, const Name &name) override { if (LoggerIsOn(2)) { - LoggerInfo() << "### timeout for " << name - << " src port: " << interest->getSrcPort() - << " dst port: " << interest->getDstPort(); + LoggerInfo() << "### timeout for " << name; } else if (LoggerIsOn(1)) { LoggerInfo() << "### timeout for " << name; } @@ -203,36 +194,54 @@ class Client : private interface::Portal::TransportCallback { afterSignal(); } + void checkFamily(hicn_packet_format_t format, int family) { + switch (HICN_PACKET_FORMAT_GET(format, 0)) { + case IPPROTO_IP: + if (family != AF_INET) throw std::runtime_error("Bad packet format"); + break; + case IPPROTO_IPV6: + if (family != AF_INET6) throw std::runtime_error("Bad packet format"); + break; + default: + throw std::runtime_error("Bad packet format"); + } + } + void doPing() { 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 - : HICN_PACKET_FORMAT_IPV4_TCP; + hicn_packet_format_t format = config_->packet_format_; + + switch (format) { + case HICN_PACKET_FORMAT_NEW: + /* Nothing to do */ + break; + case HICN_PACKET_FORMAT_IPV4_TCP: + case HICN_PACKET_FORMAT_IPV6_TCP: + checkFamily(format, interest_name.getAddressFamily()); + break; + } + + /* + * Eventually add the AH header if a signer is defined. Raise an error + * if format include the AH header but no signer is defined. + */ + if (HICN_PACKET_FORMAT_IS_AH(format)) { + if (!signer_) throw std::runtime_error("Bad packet format"); } else { - format = signer_ ? HICN_PACKET_FORMAT_IPV6_TCP_AH - : HICN_PACKET_FORMAT_IPV6_TCP; + if (signer_) format = Packet::toAHFormat(format); } - size_t additional_header_size = 0; - if (signer_) additional_header_size = signer_->getSignatureFieldSize(); - auto interest = std::make_shared<Interest>(interest_name, format, - additional_header_size); + auto interest = core::PacketManager<>::getInstance().getPacket<Interest>( + format, signer_ ? signer_->getSignatureFieldSize() : 0); + interest->setName(interest_name); interest->setLifetime(uint32_t(config_->interestLifetime_)); - interest->setSrcPort(config_->srcPort_); - interest->setDstPort(config_->dstPort_); - interest->setTTL(config_->ttl_); - 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)) { @@ -305,6 +314,15 @@ class Client : private interface::Portal::TransportCallback { std::unique_ptr<TrafficGenerator> traffic_generator_; }; +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(), \ + [](unsigned char c) { return std::tolower(c); }); + void help() { LoggerInfo() << "usage: hicn-consumer-ping [options]"; LoggerInfo() << "PING options"; @@ -312,9 +330,6 @@ void help() { "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() @@ -337,6 +352,9 @@ void help() { "libtransport"; LoggerInfo() << "-b <type> Traffic generator type. Use 'RANDOM' for " "random prefixes and suffixes. Default: sequential suffixes."; + LoggerInfo() + << "-w <packet_format> Packet format (without signature, defaults " + "to IPV6_TCP)"; LoggerInfo() << "-H prints this message"; } @@ -356,8 +374,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:SAOHz:F:")) != - -1) { + while ((opt = getopt(argc, argv, "a:b:i:m:f:n:l:c:z:F:w:H")) != -1) { switch (opt) { case 'a': c->num_int_manifest_suffixes_ = std::stoi(optarg); @@ -366,9 +383,6 @@ int start(int argc, char *argv[]) { case 'b': c->traffic_generator_type_ = optarg; break; - case 't': - c->ttl_ = uint8_t(std::stoi(optarg)); - break; case 'i': c->pingInterval_ = std::stoi(optarg); break; @@ -378,12 +392,6 @@ int start(int argc, char *argv[]) { case 'f': c->first_suffix_ = uint32_t(std::stoul(optarg)); break; - case 's': - c->srcPort_ = uint16_t(std::stoi(optarg)); - break; - case 'd': - c->dstPort_ = uint16_t(std::stoi(optarg)); - break; case 'n': c->name_ = optarg; break; @@ -399,6 +407,15 @@ int start(int argc, char *argv[]) { case 'F': conf_file = optarg; break; + case 'w': { + std::string packet_format_s = std::string(optarg); + TO_LOWER(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"); + c->packet_format_ = it->second; + break; + } case 'H':; default: help(); diff --git a/apps/ping/src/ping_server.cc b/apps/ping/src/ping_server.cc index b2806ba64..8156866dd 100644 --- a/apps/ping/src/ping_server.cc +++ b/apps/ping/src/ping_server.cc @@ -25,6 +25,7 @@ #include <hicn/transport/auth/signer.h> #include <hicn/transport/auth/verifier.h> #include <hicn/transport/core/content_object.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/utils/string_tokenizer.h> @@ -39,26 +40,21 @@ using HashAlgorithm = core::HashAlgorithm; 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_]; + auto content_object = + core::PacketManager<>::getInstance().getPacket<ContentObject>( + interest.getFormat(), + (sign_ && signer_) ? signer_->getSignatureFieldSize() : 0); 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 (LoggerIsOn(2)) { - LoggerInfo() << ">>> send object " << content_object->getName() - << " src port: " << content_object->getSrcPort() - << " dst port: " << content_object->getDstPort() - << " TTL: " << (int)content_object->getTTL(); + LoggerInfo() << ">>> send object " << content_object->getName(); } else if (LoggerIsOn(1)) { LoggerInfo() << ">>> send object " << content_object->getName(); } @@ -74,38 +70,13 @@ class CallbackContainer { } public: - CallbackContainer(const Name &prefix, uint32_t object_size, uint8_t ttl, + CallbackContainer(const Name &prefix, uint32_t object_size, 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), - ttl_(ttl), - signer_(signer), - sign_(sign) { + : buffer_(object_size, 'X'), signer_(signer), sign_(sign) { // Verifier for interest manifests if (!passphrase.empty()) verifier_ = std::make_unique<auth::SymmetricVerifier>(passphrase); - - core::Packet::Format format; - if (prefix.getAddressFamily() == AF_INET) { - format = HICN_PACKET_FORMAT_IPV4_TCP; - if (sign_) { - format = HICN_PACKET_FORMAT_IPV4_TCP_AH; - } - } else { - format = HICN_PACKET_FORMAT_IPV6_TCP; - if (sign_) { - format = HICN_PACKET_FORMAT_IPV6_TCP_AH; - } - } - - for (int i = 0; i < (1 << log2_content_object_buffer_size); i++) { - content_objects_[i] = std::make_shared<ContentObject>( - prefix, format, 0, (const uint8_t *)buffer_.data(), buffer_.size()); - content_objects_[i]->setLifetime(lifetime); - } } void processInterest(ProducerSocket &p, Interest &interest, @@ -124,9 +95,6 @@ class CallbackContainer { 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(); @@ -162,10 +130,6 @@ class CallbackContainer { private: std::string buffer_; - std::vector<std::shared_ptr<ContentObject>> content_objects_; - std::uint16_t mask_; - std::uint16_t content_objects_index_; - uint8_t ttl_; auth::Signer *signer_; bool sign_; std::unique_ptr<auth::Verifier> verifier_; @@ -177,7 +141,6 @@ void help() { 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 " @@ -206,7 +169,6 @@ int main(int argc, char **argv) { std::string name_prefix = "b001::0/64"; std::string delimiter = "/"; uint32_t object_size = 1250; - uint8_t ttl = 64; std::string keystore_path = "./rsa_crypto_material.p12"; std::string keystore_password = "cisco"; std::string passphrase = ""; @@ -233,9 +195,6 @@ int main(int argc, char **argv) { case 'n': name_prefix = optarg; break; - case 't': - ttl = (uint8_t)std::stoi(optarg); - break; case 'l': data_lifetime = std::stoi(optarg); break; @@ -294,11 +253,11 @@ int main(int argc, char **argv) { if (sign) { signer = std::make_unique<auth::AsymmetricSigner>(keystore_path, keystore_password); - stubs = new CallbackContainer(n, object_size, ttl, signer.get(), sign, + stubs = new CallbackContainer(n, object_size, signer.get(), sign, passphrase, data_lifetime); } else { auth::Signer *signer = nullptr; - stubs = new CallbackContainer(n, object_size, ttl, signer, sign, passphrase, + stubs = new CallbackContainer(n, object_size, signer, sign, passphrase, data_lifetime); } |