From 3476dd9ddecc87d9212c3bf56a5be52079e27def Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Wed, 21 Sep 2022 17:11:22 +0200 Subject: feat: support for new packet format in hicn-light MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref: HICN-792 Change-Id: I3204006bd2dd2be6504c33035c6578ec0292455a Signed-off-by: Jordan Augé --- Dockerfile | 34 ++- apps/ping/src/ping_client.cc | 109 +++++---- apps/ping/src/ping_server.cc | 61 +----- .../facemgr/src/interfaces/hicn_light/hicn_light.c | 1 - hicn-light/src/hicn/core/fib.c | 126 +++++------ hicn-light/src/hicn/io/CMakeLists.txt | 8 - hicn-light/src/hicn/io/udp.c | 14 +- hicn-light/src/hicn/test/test-fib.cc | 60 ++++- hicn-plugin/src/hicn.h | 6 +- hicn-plugin/src/mapme_eventmgr.c | 5 +- hicn-plugin/src/parser.h | 9 - lib/includes/hicn/base.h | 192 +++++++--------- lib/includes/hicn/packet.h | 55 +---- lib/src/base.c | 29 ++- lib/src/ops.c | 6 - lib/src/ops.h | 119 +--------- lib/src/packet.c | 72 ++---- lib/src/protocol/ah.c | 6 - lib/src/protocol/icmp.c | 6 - lib/src/protocol/ipv4.c | 46 +--- lib/src/protocol/ipv6.c | 47 +--- lib/src/protocol/new.c | 14 +- lib/src/protocol/tcp.c | 37 +--- lib/src/protocol/udp.c | 38 ---- lib/src/test/test_name.cc | 3 + lib/src/test/test_udp_header.cc | 4 +- .../includes/hicn/transport/core/io_module.h | 2 +- libtransport/includes/hicn/transport/core/packet.h | 7 +- .../hicn/transport/interfaces/socket_consumer.h | 6 - .../hicn/transport/interfaces/socket_producer.h | 6 - libtransport/src/core/packet.cc | 65 +----- libtransport/src/implementation/socket.cc | 21 +- libtransport/src/implementation/socket.h | 1 - libtransport/src/implementation/socket_consumer.h | 11 +- libtransport/src/implementation/socket_producer.h | 10 + libtransport/src/interfaces/socket_consumer.cc | 10 - libtransport/src/interfaces/socket_producer.cc | 10 - libtransport/src/protocols/prod_protocol_rtc.cc | 2 +- libtransport/src/protocols/rtc/rtc_verifier.cc | 2 +- libtransport/src/protocols/transport_protocol.cc | 2 +- libtransport/src/test/test_auth.cc | 8 +- libtransport/src/test/test_packet.cc | 243 ++++++++------------- tests/config.sh | 2 + tests/functional-tests/2-nodes-hicn-light.robot | 4 + tests/resources/libraries/robot/runtest.robot | 14 ++ 45 files changed, 507 insertions(+), 1026 deletions(-) mode change 120000 => 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 120000 index 91fb519b8..000000000 --- a/Dockerfile +++ /dev/null @@ -1 +0,0 @@ -Dockerfile.dev \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..ad7f99785 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM ubuntu:focal +ENV DEBIAN_FRONTEND=noninteractive +WORKDIR /hicn-build + +ARG USERNAME=ubuntu +ARG USER_UID=1000 +ARG USER_GID=${USER_UID} + +COPY Makefile versions.cmake ./ +COPY scripts scripts/ + +USER root + +RUN apt update && apt-get install -y \ + make \ + sudo \ + curl \ + valgrind \ + git \ + zsh + +RUN make deps debug-tools + +# Add non-root user +RUN groupadd --gid ${USER_GID} ${USERNAME} && \ + useradd -s /bin/bash --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} && \ + echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL >/etc/sudoers.d/${USERNAME} && \ + chmod 0440 /etc/sudoers.d/${USERNAME} + +USER ${USERNAME} +WORKDIR /home/${USERNAME} + +ENV DEBIAN_FRONTEND= 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_name, format, - additional_header_size); + auto interest = core::PacketManager<>::getInstance().getPacket( + 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 traffic_generator_; }; +static std::unordered_map 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 maximum number of pings to send (default 10)"; - LoggerInfo() << "-s sorce port (default 9695)"; - LoggerInfo() << "-d destination port (default 8080)"; - LoggerInfo() << "-t set packet ttl (default 64)"; LoggerInfo() << "-a set the passphrase and the number of " "suffixes in interest manifest (default 0);"; LoggerInfo() @@ -337,6 +352,9 @@ void help() { "libtransport"; LoggerInfo() << "-b Traffic generator type. Use 'RANDOM' for " "random prefixes and suffixes. Default: sequential suffixes."; + LoggerInfo() + << "-w 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 #include #include +#include #include #include #include @@ -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 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( + 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(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( - 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> content_objects_; - std::uint16_t mask_; - std::uint16_t content_objects_index_; - uint8_t ttl_; auth::Signer *signer_; bool sign_; std::unique_ptr verifier_; @@ -177,7 +141,6 @@ void help() { LoggerInfo() << "-s object content size (default 1350B)"; LoggerInfo() << "-n 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(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); } diff --git a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c index 2275d1cff..25cc44caf 100644 --- a/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c +++ b/ctrl/facemgr/src/interfaces/hicn_light/hicn_light.c @@ -218,7 +218,6 @@ int hl_connect_timeout(interface_t *interface, int fd, void *unused) { * connected to succeed. */ int _hl_connect(interface_t *interface) { - ERROR("[MACCHA] CONNECT"); hl_data_t *data = interface->data; assert(!data->s); assert(!data->sp); diff --git a/hicn-light/src/hicn/core/fib.c b/hicn-light/src/hicn/core/fib.c index 66e6ae339..b3b5d4036 100644 --- a/hicn-light/src/hicn/core/fib.c +++ b/hicn-light/src/hicn/core/fib.c @@ -124,11 +124,13 @@ fib_node_t *fib_search(const fib_t *fib, const hicn_prefix_t *prefix, uint32_t curr_len; uint32_t match_len; - char buf[MAXSZ_HICN_PREFIX]; - int rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix); - if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) - snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); - INFO("FIB SEARCH: %s prefix len %d", buf, prefix_len); + WITH_DEBUG({ + char buf[MAXSZ_HICN_PREFIX]; + int rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix); + if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) + snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); + DEBUG("[fib_search] prefix=%s prefix_len=%d\n", buf, prefix_len); + }); fib_node_t *parent = NULL; fib_node_t *gparent = NULL; @@ -136,23 +138,13 @@ fib_node_t *fib_search(const fib_t *fib, const hicn_prefix_t *prefix, while (curr) { const hicn_prefix_t *curr_prefix = fib_entry_get_prefix(curr->entry); - rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, curr_prefix); - if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) - snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); - INFO(" >> current %s", buf); - curr_len = hicn_prefix_get_len(curr_prefix); match_len = hicn_prefix_lpm(prefix, curr_prefix); - INFO("curr len %d match len %d", curr_len, match_len); - - // XXX >= vs == for the second stop condition // curr_len >= prefix_len l >= L // L is a prefix of l // > means we did not find // = means we could have found - // leverage this info for contains! - // XXX remove this comment when done if (match_len < curr_len || curr_len >= prefix_len) break; gparent = parent; @@ -191,30 +183,14 @@ fib_node_t *_fib_insert(fib_t *fib, fib_entry_t *entry, fib_node_t *parent, const hicn_prefix_t *parent_prefix = fib_entry_get_prefix(parent->entry); uint32_t parent_prefix_len = hicn_prefix_get_len(parent_prefix); uint8_t next_bit = hicn_prefix_get_bit(prefix, parent_prefix_len); - INFO("parent prefix len %d next bit %d", parent_prefix_len, next_bit); parent->child[next_bit] = new_node; } if (child) { - char buf[MAXSZ_HICN_PREFIX]; - int rc; - const hicn_prefix_t *child_prefix = fib_entry_get_prefix(child->entry); - INFO("prefix lengths %d==127 %d==128", hicn_prefix_get_len(prefix), - hicn_prefix_get_len(child_prefix)); - INFO("LPM BETWEEN"); - rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix); - if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) - snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); - INFO("prefix %s", buf); - rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, child_prefix); - if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) - snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); - INFO("child prefix %s", buf); uint32_t match_len = hicn_prefix_lpm(prefix, child_prefix); uint8_t next_bit = hicn_prefix_get_bit(child_prefix, match_len); new_node->child[next_bit] = child; - INFO("child match len %d next bit %d", match_len, next_bit); } if (is_used) fib->size++; @@ -319,16 +295,34 @@ void fib_add(fib_t *fib, fib_entry_t *entry) { fib_search_t search; fib_node_t *curr = fib_search(fib, prefix, &search); + char buf[MAXSZ_HICN_PREFIX]; + char buf2[MAXSZ_HICN_PREFIX]; + int rc; + + rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix); + if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) + snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); + if (curr) { + rc = hicn_prefix_snprintf(buf2, MAXSZ_HICN_PREFIX, + fib_entry_get_prefix(curr->entry)); + if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) + snprintf(buf2, MAXSZ_HICN_PREFIX, "%s", "(error)"); + } else { + snprintf(buf2, MAXSZ_HICN_PREFIX, "%s", "(null)"); + search.prefix_len = 0; + search.match_len = 0; + } + DEBUG("fib_search(%s) result: curr=%s, prefix_len=%d; match_len=%d\n", buf, + buf2, search.prefix_len, search.match_len); + /* Case 1 */ if (!curr) { - INFO("Case 1"); _fib_insert(fib, entry, search.parent, NULL, true); goto END; } /* Case 2 */ if (search.prefix_len == search.match_len && prefix_len == search.match_len) { - INFO("Case 2"); if (!curr->is_used) { curr->is_used = true; if (curr->entry) fib_entry_free(curr->entry); @@ -345,51 +339,28 @@ void fib_add(fib_t *fib, fib_entry_t *entry) { /* Case 3 */ if (prefix_len == search.match_len) { - INFO("Case 3"); _fib_insert(fib, entry, search.parent, curr, true); goto END; } /* Case 4 */ - char buf[MAXSZ_HICN_PREFIX]; - int rc; - - INFO("Case 4 : match len = %d", search.match_len); hicn_prefix_t inner_prefix; /* dup'ed in fib_entry_create */ hicn_prefix_copy(&inner_prefix, prefix); - rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, &inner_prefix); - if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) - snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); - INFO("inner prefix before truncate %s", buf); - INFO("last bit should be 1: %d", hicn_prefix_get_bit(&inner_prefix, 127)); - - INFO("truncate to length = %d", search.match_len); hicn_prefix_truncate(&inner_prefix, search.match_len); - INFO("last bit should be 0: %d", hicn_prefix_get_bit(&inner_prefix, 127)); - - rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, &inner_prefix); - if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) - snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); - INFO("inner prefix after truncate %s", buf); fib_entry_t *inner_entry = fib_entry_create( &inner_prefix, STRATEGY_TYPE_UNDEFINED, NULL, fib->forwarder); - INFO("inner prefix len=%d", hicn_prefix_get_len(&inner_prefix)); - // debug - const hicn_prefix_t *parent_prefix = fib_entry_get_prefix(inner_entry); - INFO("inner prefix len=%d", hicn_prefix_get_len(parent_prefix)); - - INFO("insert inner"); fib_node_t *new_node = _fib_insert(fib, inner_entry, search.parent, curr, false); - INFO("insert new node"); - fib_dump(fib); _fib_insert(fib, entry, new_node, NULL, true); END: +#if 0 fib_dump(fib); +#endif + ; /* required for clang */ } /* @@ -695,18 +666,16 @@ bool __fib_check_preorder(const fib_node_t *node, if (!hicn_prefix_equals(prefix, prefix_array[*pos])) { char buf[MAXSZ_HICN_PREFIX]; + char buf2[MAXSZ_HICN_PREFIX]; int rc; - ERROR("Prefix mismatch in position %d %s != %s", pos); rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix); if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); - ERROR("Expected: %s", buf); - - rc = hicn_prefix_snprintf(buf, MAXSZ_HICN_PREFIX, prefix_array[*pos]); + rc = hicn_prefix_snprintf(buf2, MAXSZ_HICN_PREFIX, prefix_array[*pos]); if (rc < 0 || rc >= MAXSZ_HICN_PREFIX) - snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(error)"); - ERROR("Expected: %s", buf); + snprintf(buf2, MAXSZ_HICN_PREFIX, "%s", "(error)"); + ERROR("Prefix mismatch in position %ld %s != %s", *pos, buf, buf2); return false; } @@ -736,7 +705,7 @@ bool _fib_check_preorder(const fib_t *fib, const hicn_prefix_t **prefix_array, } // XXX print empty node but not recurse -void _fib_dump(const fib_node_t *node, int start, int indent) { +void _fib_dump(const fib_node_t *node, int start, int indent, int location) { char buf[MAXSZ_HICN_PREFIX]; if (node) { @@ -748,20 +717,25 @@ void _fib_dump(const fib_node_t *node, int start, int indent) { snprintf(buf, MAXSZ_HICN_PREFIX, "%s", "(null)"); } - // Left if (indent > 0) { - for (int i = 0; i < start - 1; i++) printf(" "); - for (int i = start + 1; i < indent; i++) printf("| "); - printf("|"); - printf("_ %s\n", buf); - } else { - printf("%s\n", buf); + for (int i = 0; i < start; i++) printf(" "); + for (int i = 0; i < indent - start - 1; i++) printf("| "); + printf("|_ "); } + printf("%s", buf); + if (node && !node->is_used) printf(" [inner]"); + printf("\n"); if (!node) return; - _fib_dump(node->child[ZERO], start, indent + 1); - _fib_dump(node->child[ONE], start + 1, indent + 1); + if (location == 2) { + start++; + location = 0; + } + _fib_dump(node->child[ZERO], start, indent + 1, + (location == 0) ? 1 : location); + _fib_dump(node->child[ONE], start, indent + 1, + (location == 0) ? 2 : location); } -void fib_dump(const fib_t *fib) { _fib_dump(fib->root, 0, 0); } +void fib_dump(const fib_t *fib) { _fib_dump(fib->root, 0, 0, 0); } diff --git a/hicn-light/src/hicn/io/CMakeLists.txt b/hicn-light/src/hicn/io/CMakeLists.txt index 68a5baec5..1a04aad75 100644 --- a/hicn-light/src/hicn/io/CMakeLists.txt +++ b/hicn-light/src/hicn/io/CMakeLists.txt @@ -21,13 +21,5 @@ list(APPEND SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/udp.c ) -#if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") -# list(APPEND SOURCE_FILES -# io/hicnTunnel.c -# io/hicnConnection.c -# io/hicnListener.c -# ) -#endif() - set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE) set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) diff --git a/hicn-light/src/hicn/io/udp.c b/hicn-light/src/hicn/io/udp.c index b06ee7bce..d704a64f1 100644 --- a/hicn-light/src/hicn/io/udp.c +++ b/hicn-light/src/hicn/io/udp.c @@ -15,10 +15,8 @@ /** * @file udp.c - * #brief Implementation of the UDP face - * - * Old comment: - * - The Send() function may overflow the output buffer + * #brief Implementation of the native UDP face leveraging the new packet format + * to avoid encapsulation. * */ @@ -59,14 +57,6 @@ #include "../core/listener.h" #include "../core/listener_vft.h" #include "../core/msgbuf.h" -//#include "../hicn-light/config.h" - -// Batching based on recvmmsg is also generic -// the difference is the handling of packet as in tcp we need to go through the -// ring buffer first to do the framing, while in UDP this is already done -// -// each module should have a function to process a packet, then call a callback -// in the forwarder again #define BATCH_SOCKET_BUFFER 512 * 1024 /* 256k */ diff --git a/hicn-light/src/hicn/test/test-fib.cc b/hicn-light/src/hicn/test/test-fib.cc index 125515e41..d2c5d1e1c 100644 --- a/hicn-light/src/hicn/test/test-fib.cc +++ b/hicn-light/src/hicn/test/test-fib.cc @@ -55,20 +55,30 @@ void _fib_add_prefix(fib_t *fib, const hicn_prefix_t *prefix) { fib_add(fib, entry); } +#if 0 static const hicn_prefix_t p0010 = (hicn_prefix_t){ .name = {.v6 = {.as_u64 = {0x1122334455667788, 0x9900aabbccddeeff}}}, .len = 4}; +#endif + +#define HICN_PREFIX(P, STR) \ + hicn_prefix_t P; \ + hicn_ip_prefix_t _##P; \ + EXPECT_EQ(hicn_ip_prefix_pton(STR, &_##P), 0); \ + EXPECT_EQ(hicn_prefix_create_from_ip_prefix(&_##P, &P), 0); /* TEST: Fib allocation and initialization */ TEST_F(FibTest, FibAddOne) { /* Empty fib should be valid */ + HICN_PREFIX(pfx, "1122:3344:5566:7788:9900:aabb:ccdd:eeff/4"); + const hicn_prefix_t *empty_prefix_array[] = {}; bool empty_used_array[] = {}; EXPECT_TRUE(fib_is_valid(fib)); EXPECT_TRUE(fib_check_preorder(fib, empty_prefix_array, empty_used_array)); - const hicn_prefix_t *prefix_array[] = {&p0010}; + const hicn_prefix_t *prefix_array[] = {&pfx}; bool used_array[] = {true}; for (unsigned i = 0; i < ARRAY_SIZE(prefix_array); i++) { @@ -84,10 +94,44 @@ TEST_F(FibTest, FibAddOne) { /* Check that free indices and bitmaps are correctly updated */ } -#if 0 -22-09-2022 13:07:57 fib_entry_on_event: b002::/64 -22-09-2022 13:08:01 fib_entry_on_event: b002::abcd:0:0:0/128 -22-09-2022 13:08:01 fib_entry_on_event: b002::2/128 -22-09-2022 13:08:01 fib_entry_on_event: b002::abcd:0:0:1/128 -22-09-2022 13:08:01 fib_entry_on_event: b002::3/128 -#endif +TEST_F(FibTest, FibAddTwo) { + HICN_PREFIX(b001, "b001::/64"); + HICN_PREFIX(c001, "c001::/64"); + HICN_PREFIX(inner_8000_1, "8000::/1"); + + const hicn_prefix_t *prefix_array[] = {&b001, &inner_8000_1, &c001}; + bool used_array[] = {true, false, true}; + + _fib_add_prefix(fib, &b001); + _fib_add_prefix(fib, &c001); + + fib_dump(fib); + + EXPECT_TRUE(fib_is_valid(fib)); + EXPECT_TRUE(fib_check_preorder(fib, prefix_array, used_array)); +} + +TEST_F(FibTest, FibAddFive) { + HICN_PREFIX(b002, "b002::/64"); + HICN_PREFIX(b002_abcd_0, "b002::abcd:0:0:0/128"); + HICN_PREFIX(b002_2, "b002::2/128"); + HICN_PREFIX(b002_abcd_1, "b002::abcd:0:0:1/128"); + HICN_PREFIX(b002_3, "b002::3/128"); + HICN_PREFIX(inner_b002_2, "b002::2/127"); + HICN_PREFIX(inner_b002_abcd_0, "b002::abcd:0:0:0/127"); + const hicn_prefix_t *prefix_array[] = { + &b002_2, &inner_b002_2, &b002_3, &b002, + &b002_abcd_0, &inner_b002_abcd_0, &b002_abcd_1}; + bool used_array[] = {true, false, true, true, true, false, true}; + + _fib_add_prefix(fib, &b002); + _fib_add_prefix(fib, &b002_abcd_0); + _fib_add_prefix(fib, &b002_2); + _fib_add_prefix(fib, &b002_abcd_1); + _fib_add_prefix(fib, &b002_3); + + fib_dump(fib); + + EXPECT_TRUE(fib_is_valid(fib)); + EXPECT_TRUE(fib_check_preorder(fib, prefix_array, used_array)); +} diff --git a/hicn-plugin/src/hicn.h b/hicn-plugin/src/hicn.h index af23f3dde..7231773d7 100644 --- a/hicn-plugin/src/hicn.h +++ b/hicn-plugin/src/hicn.h @@ -72,7 +72,6 @@ typedef struct /** * Cached packet info */ - u16 port; u16 payload_type; hicn_lifetime_t lifetime; @@ -90,8 +89,7 @@ typedef struct STATIC_ASSERT (offsetof (hicn_buffer_t, pcs_entry_id) == 24, ""); STATIC_ASSERT (offsetof (hicn_buffer_t, vft_id) == 28, ""); STATIC_ASSERT (offsetof (hicn_buffer_t, dpo_ctx_id) == 32, ""); -STATIC_ASSERT (offsetof (hicn_buffer_t, port) == 36, ""); -STATIC_ASSERT (offsetof (hicn_buffer_t, payload_type) == 38, ""); +STATIC_ASSERT (offsetof (hicn_buffer_t, payload_type) == 36, ""); STATIC_ASSERT (offsetof (hicn_buffer_t, lifetime) == 40, ""); STATIC_ASSERT (offsetof (hicn_buffer_t, face_id) == 44, ""); STATIC_ASSERT (offsetof (hicn_buffer_t, flags) == 48, ""); @@ -126,7 +124,7 @@ hicn_buffer_is_v6 (vlib_buffer_t *b0) { hicn_packet_format_t format = hicn_packet_get_format (&hicn_get_buffer (b0)->pkbuf); - return format.l1 == IPPROTO_IPV6; + return HICN_PACKET_FORMAT_IS_IPV6 (format); } always_inline void diff --git a/hicn-plugin/src/mapme_eventmgr.c b/hicn-plugin/src/mapme_eventmgr.c index bbfe77819..866ac9a85 100644 --- a/hicn-plugin/src/mapme_eventmgr.c +++ b/hicn-plugin/src/mapme_eventmgr.c @@ -232,8 +232,9 @@ get_packet_buffer (vlib_main_t *vm, u32 node_index, u32 dpoi_index, // pointer to IP layer ? do we need to prepare for ethernet ??? buffer = vlib_buffer_get_current (b); - b->current_length = (format.l1 == IPPROTO_IPV6) ? EXPECTED_MAPME_V6_HDRLEN : - EXPECTED_MAPME_V4_HDRLEN; + b->current_length = HICN_PACKET_FORMAT_IS_IPV6 (format) ? + EXPECTED_MAPME_V6_HDRLEN : + EXPECTED_MAPME_V4_HDRLEN; return buffer; } diff --git a/hicn-plugin/src/parser.h b/hicn-plugin/src/parser.h index e69a97755..e9f709481 100644 --- a/hicn-plugin/src/parser.h +++ b/hicn-plugin/src/parser.h @@ -34,7 +34,6 @@ parse (vlib_buffer_t *pkt, uword size) int ret = HICN_ERROR_NONE; - u16 *port; hicn_lifetime_t *lifetime; hicn_payload_type_t payload_type; @@ -43,14 +42,6 @@ parse (vlib_buffer_t *pkt, uword size) hicn_packet_set_buffer (pkbuf, vlib_buffer_get_current (pkt), size, size); hicn_packet_analyze (&hicn_get_buffer (pkt)->pkbuf); - /* get source port*/ - port = &hicn_get_buffer (pkt)->port; - hicn_packet_get_src_port (pkbuf, port); - if (PREDICT_FALSE (ret)) - { - return HICN_ERROR_PARSER_PKT_INVAL; - } - /* get lifetime*/ lifetime = &hicn_get_buffer (pkt)->lifetime; hicn_packet_get_lifetime (pkbuf, lifetime); diff --git a/lib/includes/hicn/base.h b/lib/includes/hicn/base.h index 50961354b..2c80d42e6 100644 --- a/lib/includes/hicn/base.h +++ b/lib/includes/hicn/base.h @@ -65,59 +65,33 @@ typedef u32 hicn_lifetime_t; * [IPPROTO_ICMPRD, IPPROTO_AH, IPPROTO_ICMP, IPPROTO_IPV6] */ -#define HICN_FORMAT_LEN 4 +typedef uint32_t hicn_packet_format_t; -typedef union -{ - /** protocol layers representation */ - struct - { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - u8 l1; /**< First layer */ - u8 l2; /**< Second layer */ - u8 l3; /**< Third layer */ - u8 l4; /**< Fourth layer */ -#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - u8 l4; /**< Fourth layer */ - u8 l3; /**< Third layer */ - u8 l2; /**< Second layer */ - u8 l1; /**< First layer */ -#elif _WIN32 /* Windows is assumed little-endian */ - u8 l1; - u8 l2; - u8 l3; - u8 l4; -#else -#error "Unsupported endianness" -#endif - }; - /** u32 representation */ - u32 as_u32; - u8 as_u8[HICN_FORMAT_LEN]; -} hicn_packet_format_t; - -/* Common protocol layers */ /* Common protocol layers */ -#ifndef _WIN32 #define HICN_PACKET_FORMAT(x, y, z, t) \ - (hicn_packet_format_t) \ - { \ + (uint32_t) (((x) << 24) + ((y) << 16) + ((z) << 8) + (t)) + +#define HICN_PACKET_FORMAT_SIZE 4 + +// i = 0..3 +#define HICN_PACKET_FORMAT_GET(format, i) \ + (i < 0 || i > 3) ? IPPROTO_NONE : ((format >> ((3 - (i)) << 3)) & 0xFF) + +#define HICN_PACKET_FORMAT_SET(format, i, val) \ + format = ((val << ((3 - i) << 3)) | \ + (format & (0xFFFFFFFF ^ (0xFF << ((3 - i) << 3))))) + +#define HICN_PACKET_FORMAT_ENUMERATE(FORMAT, POS, PROTOCOL, BODY) \ + for (unsigned POS = 0; POS <= HICN_PACKET_FORMAT_SIZE - 1; POS++) \ { \ - .l1 = x, .l2 = y, .l3 = z, .l4 = t \ - } \ - } -#else -inline const hicn_packet_format_t -HICN_PACKET_FORMAT (int x, int y, int z, int t) -{ - hicn_packet_format_t format; - format.l1 = x; - format.l2 = y; - format.l3 = z; - format.l4 = t; - return format; -} -#endif + uint8_t PROTOCOL = HICN_PACKET_FORMAT_GET (FORMAT, POS); \ + BODY; \ + } + +#define HICN_PACKET_FORMAT_L1(format) HICN_PACKET_FORMAT_L ((format), 0) +#define HICN_PACKET_FORMAT_L2(format) HICN_PACKET_FORMAT_L ((format), 1) +#define HICN_PACKET_FORMAT_L3(format) HICN_PACKET_FORMAT_L ((format), 2) +#define HICN_PACKET_FORMAT_L4(format) HICN_PACKET_FORMAT_L ((format), 3) extern const char *const _protocol_str[]; @@ -132,37 +106,36 @@ int hicn_packet_format_snprintf (char *s, size_t size, #define constexpr const #endif -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV4_TCP = - HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV4_ICMP = - HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV6_TCP = - HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV6_ICMP = - HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_NONE, - IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_NEW = - HICN_PACKET_FORMAT (IPPROTO_ENCAP, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV4_UDP = - HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV6_UDP = - HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV4_TCP_AH = - HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV4_ICMP_AH = - HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_ICMP, IPPROTO_AH, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV6_TCP_AH = - HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV6_ICMP_AH = - HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_AH, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_NEW_AH = - HICN_PACKET_FORMAT (IPPROTO_ENCAP, IPPROTO_AH, IPPROTO_NONE, IPPROTO_NONE); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV6_UDP_AH = - HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_AH); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_IPV4_UDP_AH = - HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_AH); -static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_NONE = - HICN_PACKET_FORMAT (IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE); +#define HICN_PACKET_FORMAT_IPV4_TCP \ + HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV4_ICMP \ + HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_ICMP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV6_TCP \ + HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV6_ICMP \ + HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_NEW \ + HICN_PACKET_FORMAT (IPPROTO_ENCAP, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV4_UDP \ + HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV6_UDP \ + HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV4_TCP_AH \ + HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV4_ICMP_AH \ + HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_ICMP, IPPROTO_AH, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV6_TCP_AH \ + HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_AH, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV6_ICMP_AH \ + HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_ICMPV6, IPPROTO_AH, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_NEW_AH \ + HICN_PACKET_FORMAT (IPPROTO_ENCAP, IPPROTO_AH, IPPROTO_NONE, IPPROTO_NONE) +#define HICN_PACKET_FORMAT_IPV6_UDP_AH \ + HICN_PACKET_FORMAT (IPPROTO_IPV6, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_AH) +#define HICN_PACKET_FORMAT_IPV4_UDP_AH \ + HICN_PACKET_FORMAT (IPPROTO_IP, IPPROTO_UDP, IPPROTO_ENCAP, IPPROTO_AH) +#define HICN_PACKET_FORMAT_NONE \ + HICN_PACKET_FORMAT (IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE, IPPROTO_NONE) /** * @brief Return the hICN format with an additional AH header @@ -172,21 +145,21 @@ static constexpr hicn_packet_format_t HICN_PACKET_FORMAT_NONE = static inline hicn_packet_format_t hicn_get_ah_format (hicn_packet_format_t format) { - hicn_packet_format_t ret = format; - for (unsigned i = 0; i < HICN_FORMAT_LEN; i++) - { - switch (ret.as_u8[i]) + HICN_PACKET_FORMAT_ENUMERATE (format, i, protocol, { + switch (protocol) + { { case IPPROTO_AH: - return ret; + return format; case IPPROTO_NONE: - ret.as_u8[i] = IPPROTO_AH; - return ret; + HICN_PACKET_FORMAT_SET (format, i, IPPROTO_AH); + return format; default: break; } - } - return ret; + } + }); + return format; } /* @@ -196,27 +169,22 @@ hicn_get_ah_format (hicn_packet_format_t format) */ #define HICN_HDRLEN_MAX 72 -/** - * @brief Check if type is none. - * @return 1 if none, 0 otherwise - */ -static inline int -hicn_type_is_none (hicn_packet_format_t format) -{ - return (format.l1 == IPPROTO_NONE) && (format.l2 == IPPROTO_NONE) && - (format.l3 == IPPROTO_NONE) && (format.l4 == IPPROTO_NONE); -} +#define HICN_PACKET_FORMAT_IS_NONE(format) \ + ((HICN_PACKET_FORMAT_GET (format, 0) == IPPROTO_NONE) && \ + (HICN_PACKET_FORMAT_GET (format, 1) == IPPROTO_NONE) && \ + (HICN_PACKET_FORMAT_GET (format, 2) == IPPROTO_NONE) && \ + (HICN_PACKET_FORMAT_GET (format, 3) == IPPROTO_NONE)) + +#define HICN_PACKET_FORMAT_IS_AH(format) \ + ((HICN_PACKET_FORMAT_GET (format, 0) == IPPROTO_AH) || \ + (HICN_PACKET_FORMAT_GET (format, 1) == IPPROTO_AH) || \ + (HICN_PACKET_FORMAT_GET (format, 2) == IPPROTO_AH) || \ + (HICN_PACKET_FORMAT_GET (format, 3) == IPPROTO_AH)) -#define _is_ipv4(format) (format.l1 == IPPROTO_IP) -#define _is_ipv6(format) (format.l1 == IPPROTO_IPV6) -#define _is_tcp(format) (format.l2 == IPPROTO_TCP) -#define _is_udp(format) (format.l2 == IPPROTO_UDP) -#define _is_icmp(format) \ - ((format.l2 == IPPROTO_ICMP) || (format.l2 == IPPROTO_ICMPV6)) -#define _is_cmpr(format) ((format & HFO_CMPR) >> 5) -#define _is_ah(format) \ - ((format.l1 == IPPROTO_AH) || (format.l2 == IPPROTO_AH) || \ - (format.l3 == IPPROTO_AH)) +#define HICN_PACKET_FORMAT_IS_IPV4(format) \ + (HICN_PACKET_FORMAT_GET (format, 0) == IPPROTO_IP) +#define HICN_PACKET_FORMAT_IS_IPV6(format) \ + (HICN_PACKET_FORMAT_GET (format, 0) == IPPROTO_IPV6) /* * @brief hICN packet types @@ -276,9 +244,9 @@ typedef u8 hicn_path_label_t; /** * @brief Path label computations * - * Path label is computed by accumulating the identifiers of successive output - * faces as a Data packet is traveling from its producer back to the consumer - * originating the Interest. + * Path label is computed by accumulating the identifiers of successive + * output faces as a Data packet is traveling from its producer back to the + * consumer originating the Interest. * * NOTE: this computation is not (yet) part of the hICN specification. */ diff --git a/lib/includes/hicn/packet.h b/lib/includes/hicn/packet.h index 85f76d21b..c4a0dd80e 100644 --- a/lib/includes/hicn/packet.h +++ b/lib/includes/hicn/packet.h @@ -233,6 +233,10 @@ void hicn_packet_set_format (hicn_packet_buffer_t *pkbuf, hicn_packet_format_t format); hicn_packet_type_t hicn_packet_get_type (const hicn_packet_buffer_t *pkbuf); + +void hicn_packet_initialize_type (hicn_packet_buffer_t *pkbuf, + hicn_packet_type_t type); + void hicn_packet_set_type (hicn_packet_buffer_t *pkbuf, hicn_packet_type_t type); @@ -644,57 +648,6 @@ int hicn_packet_compute_header_checksum (const hicn_packet_buffer_t *pkbuf, int hicn_packet_check_integrity_no_payload (const hicn_packet_buffer_t *pkbuf, u16 init_sum); -/** - * @brief Returns the packet TTL - * @param [in] pkbuf - hICN packet buffer - * @param [out] hops - Pointer to the variable receiving the TTL value - * @return hICN error code - */ -int hicn_packet_get_ttl (const hicn_packet_buffer_t *pkbuf, u8 *hops); - -/** - * @brief Returns the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [in, out] pos - Current position in the sequence of headers while - * @param [out] hops - The TTL value to set - * @return hICN error code - */ -int hicn_packet_set_ttl (const hicn_packet_buffer_t *pkbuf, u8 hops); - -/** - * @brief Returns the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [out] port - Pointer to the variable that will receive the port - * number - * @return hICN error code - */ -int hicn_packet_get_src_port (const hicn_packet_buffer_t *pkbuf, u16 *port); - -/** - * @brief Sets the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [out] port - The port number to set - * @return hICN error code - */ -int hicn_packet_set_src_port (const hicn_packet_buffer_t *pkbuf, u16 port); - -/** - * @brief Returns the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [out] port - Pointer to the variable that will receive the port - * number - * @return hICN error code - */ -int hicn_packet_get_dst_port (const hicn_packet_buffer_t *pkbuf, u16 *port); - -/** - * @brief Sets the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [out] port - The port number to set - * @return hICN error code - */ -int hicn_packet_set_dst_port (const hicn_packet_buffer_t *pkbuf, u16 port); - int hicn_interest_rewrite (const hicn_packet_buffer_t *pkbuf, const hicn_ip_address_t *addr_new, hicn_ip_address_t *addr_old); diff --git a/lib/src/base.c b/lib/src/base.c index a15d55938..8c689da50 100644 --- a/lib/src/base.c +++ b/lib/src/base.c @@ -32,21 +32,20 @@ hicn_packet_format_snprintf (char *s, size_t size, hicn_packet_format_t format) { char *cur = s; int rc; - for (unsigned i = 0; i < 4; i++) - { - if (i > 0) - { - rc = snprintf (cur, size - (cur - s), " %s ", "/"); - if (rc < 0 || rc >= size - (cur - s)) - return rc; - cur += rc; - } - rc = snprintf (cur, size - (cur - s), "%s", - hicn_ops_vft[format.as_u8[i]]->name); - if (rc < 0 || rc >= size - (cur - s)) - return rc; - cur += rc; - } + HICN_PACKET_FORMAT_ENUMERATE (format, i, protocol, { + if (i > 1) + { + rc = snprintf (cur, size - (cur - s), " %s ", "/"); + if (rc < 0 || rc >= size - (cur - s)) + return rc; + cur += rc; + } + + rc = snprintf (cur, size - (cur - s), "%s", hicn_ops_vft[protocol]->name); + if (rc < 0 || rc >= size - (cur - s)) + return rc; + cur += rc; + }); return (int) (cur - s); } diff --git a/lib/src/ops.c b/lib/src/ops.c index 0174a3902..2c38b5374 100644 --- a/lib/src/ops.c +++ b/lib/src/ops.c @@ -86,12 +86,6 @@ DECLARE_get_signature_padding (none, NONE); DECLARE_set_signature_padding (none, NONE); DECLARE_is_last_data (none, NONE); DECLARE_set_last_data (none, NONE); -DECLARE_get_ttl (none, NONE); -DECLARE_set_ttl (none, NONE); -DECLARE_get_src_port (none, NONE); -DECLARE_set_src_port (none, NONE); -DECLARE_get_dst_port (none, NONE); -DECLARE_set_dst_port (none, NONE); DECLARE_HICN_OPS (none, 0); /** diff --git a/lib/src/ops.h b/lib/src/ops.h index 886d75cd5..843945690 100644 --- a/lib/src/ops.h +++ b/lib/src/ops.h @@ -554,65 +554,6 @@ typedef struct hicn_ops_s */ int (*set_last_data) (const hicn_packet_buffer_t *pkbuf, size_t pos); - /** - * @brief Returns the packet TTL - * @param [in] pkbuf - hICN packet buffer - * @param [in, out] pos - Current position in the sequence of headers while - * @param [out] hops - Pointer to the variable receiving the TTL value - * @return hICN error code - */ - int (*get_ttl) (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 *hops); - - /** - * @brief Returns the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [in, out] pos - Current position in the sequence of headers while - * @param [out] hops - The TTL value to set - * @return hICN error code - */ - int (*set_ttl) (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 hops); - - /** - * @brief Returns the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [in, out] pos - Current position in the sequence of headers while - * @param [out] port - Pointer to the variable that will receive the port - * number - * @return hICN error code - */ - int (*get_src_port) (const hicn_packet_buffer_t *pkbuf, size_t pos, - u16 *port); - - /** - * @brief Sets the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [in, out] pos - Current position in the sequence of headers while - * @param [out] port - The port number to set - * @return hICN error code - */ - int (*set_src_port) (const hicn_packet_buffer_t *pkbuf, size_t pos, - u16 port); - - /** - * @brief Returns the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [in, out] pos - Current position in the sequence of headers while - * @param [out] port - Pointer to the variable that will receive the port - * number - * @return hICN error code - */ - int (*get_dst_port) (const hicn_packet_buffer_t *pkbuf, size_t pos, - u16 *port); - - /** - * @brief Sets the packet source port - * @param [in] pkbuf - hICN packet buffer - * @param [in, out] pos - Current position in the sequence of headers while - * @param [out] port - The port number to set - * @return hICN error code - */ - int (*set_dst_port) (const hicn_packet_buffer_t *pkbuf, size_t pos, - u16 port); } hicn_ops_t; #define DECLARE_HICN_OPS(protocol, len) \ @@ -667,12 +608,6 @@ typedef struct hicn_ops_s ATTR_INIT (set_signature_size, protocol##_set_signature_size), \ ATTR_INIT (get_signature_padding, protocol##_get_signature_padding), \ ATTR_INIT (is_last_data, protocol##_is_last_data), \ - ATTR_INIT (get_ttl, protocol##_get_ttl), \ - ATTR_INIT (set_ttl, protocol##_set_ttl), \ - ATTR_INIT (get_src_port, protocol##_get_src_port), \ - ATTR_INIT (set_src_port, protocol##_set_src_port), \ - ATTR_INIT (get_dst_port, protocol##_get_dst_port), \ - ATTR_INIT (set_dst_port, protocol##_set_dst_port), \ } /** @@ -681,10 +616,14 @@ typedef struct hicn_ops_s */ extern const hicn_ops_t *const hicn_ops_vft[]; -#define PROT(pkbuf, pos) \ - ((pos < (HICN_FORMAT_LEN - 1)) ? \ - hicn_packet_get_format (pkbuf).as_u8[(pos) + 1] : \ - IPPROTO_NONE) +static inline uint8_t +PROT (const hicn_packet_buffer_t *pkbuf, int pos) +{ + if (pos < -1 || pos >= HICN_PACKET_FORMAT_SIZE - 1) + return IPPROTO_NONE; + hicn_packet_format_t format = hicn_packet_get_format (pkbuf); + return HICN_PACKET_FORMAT_GET (format, pos + 1); +} #define CALL_CHILD(method, pkbuf, pos, ...) \ hicn_ops_vft[PROT (pkbuf, (pos))]->method (pkbuf, (pos) + 1, ##__VA_ARGS__); @@ -1029,48 +968,6 @@ extern const hicn_ops_t *const hicn_ops_vft[]; return HICN_LIB_ERROR_##error; \ } -#define DECLARE_get_ttl(protocol, error) \ - int protocol##_get_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, \ - u8 *hops) \ - { \ - return HICN_LIB_ERROR_##error; \ - } - -#define DECLARE_set_ttl(protocol, error) \ - int protocol##_set_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, \ - u8 hops) \ - { \ - return HICN_LIB_ERROR_##error; \ - } - -#define DECLARE_get_src_port(protocol, error) \ - int protocol##_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, \ - u16 *port) \ - { \ - return HICN_LIB_ERROR_##error; \ - } - -#define DECLARE_set_src_port(protocol, error) \ - int protocol##_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, \ - u16 port) \ - { \ - return HICN_LIB_ERROR_##error; \ - } - -#define DECLARE_get_dst_port(protocol, error) \ - int protocol##_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, \ - u16 *port) \ - { \ - return HICN_LIB_ERROR_##error; \ - } - -#define DECLARE_set_dst_port(protocol, error) \ - int protocol##_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, \ - u16 port) \ - { \ - return HICN_LIB_ERROR_##error; \ - } - #endif /* HICN_OPS_H */ /* diff --git a/lib/src/packet.c b/lib/src/packet.c index f020e099c..bebfad23e 100644 --- a/lib/src/packet.c +++ b/lib/src/packet.c @@ -54,6 +54,15 @@ hicn_packet_get_type (const hicn_packet_buffer_t *pkbuf) return pkbuf->type; } +void +hicn_packet_initialize_type (hicn_packet_buffer_t *pkbuf, + hicn_packet_type_t type) +{ + assert (pkbuf->format != HICN_PACKET_FORMAT_NONE); + pkbuf->type = type; + CALL (set_type, pkbuf, type); +} + void hicn_packet_set_type (hicn_packet_buffer_t *pkbuf, hicn_packet_type_t type) { @@ -84,7 +93,7 @@ hicn_packet_init_header (hicn_packet_buffer_t *pkbuf, { if (hicn_packet_is_undefined (pkbuf)) return HICN_LIB_ERROR_UNEXPECTED; - if (hicn_packet_get_format (pkbuf).as_u32 == HICN_PACKET_FORMAT_NONE.as_u32) + if (hicn_packet_get_format (pkbuf) == HICN_PACKET_FORMAT_NONE) return HICN_LIB_ERROR_UNEXPECTED; if (!pkbuf_get_header (pkbuf)) return HICN_LIB_ERROR_UNEXPECTED; @@ -124,8 +133,6 @@ hicn_packet_analyze (hicn_packet_buffer_t *pkbuf) size_t signature_size; int rc; - hicn_packet_format_t *format = &pkbuf->format; - /* Bootstrap: assume IP packet, and get version from header */ switch (HICN_IP_VERSION (pkbuf_get_header (pkbuf))) { @@ -135,14 +142,17 @@ hicn_packet_analyze (hicn_packet_buffer_t *pkbuf) case 6: protocol = IPPROTO_IPV6; break; + case 9: + protocol = IPPROTO_ENCAP; // new + break; default: goto ERR; } - format->as_u32 = 0; - for (unsigned i = 0; i < HICN_FORMAT_LEN; i++) + hicn_packet_format_t *format = &pkbuf->format; + for (unsigned i = 0; i < HICN_PACKET_FORMAT_SIZE; i++) { - format->as_u8[i] = protocol; + HICN_PACKET_FORMAT_SET (*format, i, protocol); /* Next protocol + increment offset */ switch (protocol) @@ -257,7 +267,7 @@ hicn_packet_analyze (hicn_packet_buffer_t *pkbuf) return HICN_LIB_ERROR_NONE; ERR: - *format = HICN_PACKET_FORMAT_NONE; + pkbuf->format = HICN_PACKET_FORMAT_NONE; pkbuf->type = HICN_PACKET_TYPE_UNDEFINED; return HICN_LIB_ERROR_UNEXPECTED; } @@ -346,10 +356,9 @@ hicn_packet_get_header_length_from_format (hicn_packet_format_t format, size_t *header_length) { *header_length = 0; - for (unsigned i = 0; i < HICN_FORMAT_LEN; i++) - { - *header_length += hicn_ops_vft[format.as_u8[i]]->header_len; - } + HICN_PACKET_FORMAT_ENUMERATE (format, i, protocol, { + *header_length += hicn_ops_vft[protocol]->header_len; + }); return HICN_LIB_ERROR_NONE; } @@ -385,11 +394,10 @@ int hicn_packet_compare (const hicn_packet_buffer_t *pkbuf1, const hicn_packet_buffer_t *pkbuf2) { - hicn_packet_format_t format1 = hicn_packet_get_format (pkbuf1); hicn_packet_format_t format2 = hicn_packet_get_format (pkbuf2); - if (format1.as_u32 != format2.as_u32) + if (format1 != format2) return HICN_LIB_ERROR_UNEXPECTED; size_t len1 = hicn_packet_get_len (pkbuf1); @@ -563,7 +571,7 @@ hicn_packet_save_header (const hicn_packet_buffer_t *pkbuf, u8 *header, size_t *header_len, bool copy_ah) { hicn_packet_format_t format = hicn_packet_get_format (pkbuf); - if (copy_ah || !_is_ah (format)) + if (copy_ah || !HICN_PACKET_FORMAT_IS_AH (format)) { int rc = hicn_packet_get_header_len (pkbuf, header_len); if (HICN_LIB_IS_ERROR (rc)) @@ -772,42 +780,6 @@ hicn_packet_get_signature (const hicn_packet_buffer_t *pkbuf, return CALL (get_signature, pkbuf, sign_buf); } -int -hicn_packet_get_ttl (const hicn_packet_buffer_t *pkbuf, u8 *hops) -{ - return CALL (get_ttl, pkbuf, hops); -} - -int -hicn_packet_set_ttl (const hicn_packet_buffer_t *pkbuf, u8 hops) -{ - return CALL (set_ttl, pkbuf, hops); -} - -int -hicn_packet_get_src_port (const hicn_packet_buffer_t *pkbuf, u16 *port) -{ - return CALL (get_src_port, pkbuf, port); -} - -int -hicn_packet_set_src_port (const hicn_packet_buffer_t *pkbuf, u16 port) -{ - return CALL (set_src_port, pkbuf, port); -} - -int -hicn_packet_get_dst_port (const hicn_packet_buffer_t *pkbuf, u16 *port) -{ - return CALL (get_dst_port, pkbuf, port); -} - -int -hicn_packet_set_dst_port (const hicn_packet_buffer_t *pkbuf, u16 port) -{ - return CALL (set_dst_port, pkbuf, port); -} - int hicn_interest_rewrite (const hicn_packet_buffer_t *pkbuf, const hicn_ip_address_t *addr_new, diff --git a/lib/src/protocol/ah.c b/lib/src/protocol/ah.c index 645b0482b..ea028d559 100644 --- a/lib/src/protocol/ah.c +++ b/lib/src/protocol/ah.c @@ -50,12 +50,6 @@ DECLARE_get_payload_type (ah, UNEXPECTED); DECLARE_set_payload_type (ah, UNEXPECTED); DECLARE_is_last_data (ah, UNEXPECTED); DECLARE_set_last_data (ah, UNEXPECTED); -DECLARE_get_ttl (ah, UNEXPECTED); -DECLARE_set_ttl (ah, UNEXPECTED); -DECLARE_get_src_port (ah, UNEXPECTED); -DECLARE_set_src_port (ah, UNEXPECTED); -DECLARE_get_dst_port (ah, UNEXPECTED); -DECLARE_set_dst_port (ah, UNEXPECTED); int ah_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos) diff --git a/lib/src/protocol/icmp.c b/lib/src/protocol/icmp.c index 71417a4e0..5ee70f088 100644 --- a/lib/src/protocol/icmp.c +++ b/lib/src/protocol/icmp.c @@ -44,12 +44,6 @@ DECLARE_get_signature (icmp, UNEXPECTED); DECLARE_has_signature (icmp, UNEXPECTED); DECLARE_is_last_data (icmp, UNEXPECTED); DECLARE_set_last_data (icmp, UNEXPECTED); -DECLARE_get_ttl (icmp, UNEXPECTED); -DECLARE_set_ttl (icmp, UNEXPECTED); -DECLARE_get_src_port (icmp, UNEXPECTED); -DECLARE_set_src_port (icmp, UNEXPECTED); -DECLARE_get_dst_port (icmp, UNEXPECTED); -DECLARE_set_dst_port (icmp, UNEXPECTED); int icmp_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos) diff --git a/lib/src/protocol/ipv4.c b/lib/src/protocol/ipv4.c index a13728d04..daa5a706a 100644 --- a/lib/src/protocol/ipv4.c +++ b/lib/src/protocol/ipv4.c @@ -60,7 +60,7 @@ ipv4_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos) .id = htons (IPV4_DEFAULT_ID), .frag_off = htons (IPV4_DEFAULT_FRAG_OFF), .ttl = HICN_DEFAULT_TTL, - .protocol = format.as_u8[pos + 1], + .protocol = HICN_PACKET_FORMAT_GET (format, pos + 1), .csum = 0, .saddr.as_u32 = 0, .daddr.as_u32 = 0, @@ -530,50 +530,6 @@ ipv4_set_last_data (const hicn_packet_buffer_t *pkbuf, size_t pos) return CALL_CHILD (set_last_data, pkbuf, pos); } -int -ipv4_get_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 *hops) -{ - _ipv4_header_t *ipv4 = pkbuf_get_ipv4 (pkbuf); - - *hops = ipv4->ttl; - - return HICN_LIB_ERROR_NONE; -} - -int -ipv4_set_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 hops) -{ - _ipv4_header_t *ipv4 = pkbuf_get_ipv4 (pkbuf); - - ipv4->ttl = hops; - - return HICN_LIB_ERROR_NONE; -} - -int -ipv4_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port) -{ - return CALL_CHILD (get_src_port, pkbuf, pos, port); -} - -int -ipv4_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port) -{ - return CALL_CHILD (set_src_port, pkbuf, pos, port); -} - -int -ipv4_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port) -{ - return CALL_CHILD (get_dst_port, pkbuf, pos, port); -} - -int -ipv4_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port) -{ - return CALL_CHILD (set_dst_port, pkbuf, pos, port); -} - DECLARE_HICN_OPS (ipv4, IPV4_HDRLEN); /* diff --git a/lib/src/protocol/ipv6.c b/lib/src/protocol/ipv6.c index aec521afc..c5fa643aa 100644 --- a/lib/src/protocol/ipv6.c +++ b/lib/src/protocol/ipv6.c @@ -53,7 +53,7 @@ ipv6_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos) (IPV6_DEFAULT_TRAFFIC_CLASS << 20) | (IPV6_DEFAULT_FLOW_LABEL & 0xfffff)), .len = htons(header_len - IPV6_HDRLEN), - .nxt = format.as_u8[pos + 1], + .nxt = HICN_PACKET_FORMAT_GET(format, pos+1), .hlim = HICN_DEFAULT_TTL, }; /* clang-format on */ @@ -468,51 +468,6 @@ ipv6_set_last_data (const hicn_packet_buffer_t *pkbuf, size_t pos) return CALL_CHILD (set_last_data, pkbuf, pos); } -int -ipv6_get_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 *hops) -{ - _ipv6_header_t *ipv6 = pkbuf_get_ipv6 (pkbuf); - - *hops = ipv6->hlim; - - return HICN_LIB_ERROR_NONE; -} - -int -ipv6_set_ttl (const hicn_packet_buffer_t *pkbuf, size_t pos, u8 hops) -{ - - _ipv6_header_t *ipv6 = pkbuf_get_ipv6 (pkbuf); - - ipv6->hlim = hops; - - return HICN_LIB_ERROR_NONE; -} - -int -ipv6_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port) -{ - return CALL_CHILD (get_src_port, pkbuf, pos, port); -} - -int -ipv6_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port) -{ - return CALL_CHILD (set_src_port, pkbuf, pos, port); -} - -int -ipv6_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port) -{ - return CALL_CHILD (get_dst_port, pkbuf, pos, port); -} - -int -ipv6_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port) -{ - return CALL_CHILD (set_dst_port, pkbuf, pos, port); -} - DECLARE_HICN_OPS (ipv6, IPV6_HDRLEN); /* diff --git a/lib/src/protocol/new.c b/lib/src/protocol/new.c index 5308e8c0a..e86ce4753 100644 --- a/lib/src/protocol/new.c +++ b/lib/src/protocol/new.c @@ -24,13 +24,6 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" -DECLARE_get_ttl (new, UNEXPECTED); -DECLARE_set_ttl (new, UNEXPECTED); -DECLARE_get_src_port (new, UNEXPECTED); -DECLARE_set_src_port (new, UNEXPECTED); -DECLARE_get_dst_port (new, UNEXPECTED); -DECLARE_set_dst_port (new, UNEXPECTED); - int new_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos) { @@ -45,8 +38,9 @@ new_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos) memset (new, 0, sizeof (_new_header_t)); _set_new_header_version (new); - uint8_t ah_flag = - format.as_u8[pos + 1] == IPPROTO_AH ? HICN_NEW_FLAG_SIG : 0; + uint8_t ah_flag = (HICN_PACKET_FORMAT_GET (format, pos + 1) == IPPROTO_AH) ? + HICN_NEW_FLAG_SIG : + 0; new->flags |= ah_flag; return CALL_CHILD (init_packet_header, pkbuf, pos); @@ -128,6 +122,8 @@ new_get_interest_name (const hicn_packet_buffer_t *pkbuf, size_t pos, return HICN_LIB_ERROR_NONE; } +// XXX never called and thus packet is never initialized as interest +// DECLARE_set_interest_name (udp, UNEXPECTED); int new_set_interest_name (const hicn_packet_buffer_t *pkbuf, size_t pos, const hicn_name_t *name) diff --git a/lib/src/protocol/tcp.c b/lib/src/protocol/tcp.c index 822bd3e0c..e09495ecd 100644 --- a/lib/src/protocol/tcp.c +++ b/lib/src/protocol/tcp.c @@ -46,8 +46,6 @@ DECLARE_set_data_locator (tcp, UNEXPECTED); DECLARE_get_data_name (tcp, UNEXPECTED); DECLARE_set_data_name (tcp, UNEXPECTED); DECLARE_set_payload_len (tcp, UNEXPECTED); -DECLARE_get_ttl (tcp, UNEXPECTED); -DECLARE_set_ttl (tcp, UNEXPECTED); int tcp_update_checksums_incremental (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *old_val, u16 *new_val, @@ -115,7 +113,8 @@ tcp_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos) .urg_ptr = 65000, }; - uint8_t ah_flag = ((format.as_u8[pos + 1] == IPPROTO_AH) ? AH_FLAG : 0); + uint8_t ah_flag = + (HICN_PACKET_FORMAT_GET (format, pos + 1) == IPPROTO_AH) ? AH_FLAG : 0; tcp->flags |= ah_flag; @@ -590,38 +589,6 @@ tcp_set_last_data (const hicn_packet_buffer_t *pkbuf, size_t pos) return HICN_LIB_ERROR_NONE; } -int -tcp_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port) -{ - _tcp_header_t *tcp = pkbuf_get_tcp (pkbuf); - *port = ntohs (tcp->sport); - return HICN_LIB_ERROR_NONE; -} - -int -tcp_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port) -{ - _tcp_header_t *tcp = pkbuf_get_tcp (pkbuf); - tcp->sport = htons (port); - return HICN_LIB_ERROR_NONE; -} - -int -tcp_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port) -{ - _tcp_header_t *tcp = pkbuf_get_tcp (pkbuf); - *port = ntohs (tcp->dport); - return HICN_LIB_ERROR_NONE; -} - -int -tcp_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port) -{ - _tcp_header_t *tcp = pkbuf_get_tcp (pkbuf); - tcp->dport = htons (port); - return HICN_LIB_ERROR_NONE; -} - DECLARE_HICN_OPS (tcp, TCP_HDRLEN); /* diff --git a/lib/src/protocol/udp.c b/lib/src/protocol/udp.c index ff2355b0c..56de0065f 100644 --- a/lib/src/protocol/udp.c +++ b/lib/src/protocol/udp.c @@ -30,8 +30,6 @@ DECLARE_set_data_locator (udp, UNEXPECTED); DECLARE_get_data_name (udp, UNEXPECTED); DECLARE_set_data_name (udp, UNEXPECTED); DECLARE_set_payload_len (udp, UNEXPECTED); -DECLARE_get_ttl (udp, UNEXPECTED); -DECLARE_set_ttl (udp, UNEXPECTED); int udp_init_packet_header (hicn_packet_buffer_t *pkbuf, size_t pos) @@ -299,42 +297,6 @@ udp_set_last_data (const hicn_packet_buffer_t *pkbuf, size_t pos) return CALL_CHILD (set_last_data, pkbuf, pos); } -int -udp_get_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port) -{ - _udp_header_t *udp = pkbuf_get_udp (pkbuf); - - *port = udp->src_port; - return HICN_LIB_ERROR_NONE; -} - -int -udp_set_src_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port) -{ - _udp_header_t *udp = pkbuf_get_udp (pkbuf); - - udp->src_port = port; - return HICN_LIB_ERROR_NONE; -} - -int -udp_get_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 *port) -{ - _udp_header_t *udp = pkbuf_get_udp (pkbuf); - - *port = udp->dst_port; - return HICN_LIB_ERROR_NONE; -} - -int -udp_set_dst_port (const hicn_packet_buffer_t *pkbuf, size_t pos, u16 port) -{ - _udp_header_t *udp = pkbuf_get_udp (pkbuf); - - udp->dst_port = port; - return HICN_LIB_ERROR_NONE; -} - DECLARE_HICN_OPS (udp, UDP_HDRLEN); /* diff --git a/lib/src/test/test_name.cc b/lib/src/test/test_name.cc index cd9ff2d4d..0cf160f70 100644 --- a/lib/src/test/test_name.cc +++ b/lib/src/test/test_name.cc @@ -395,4 +395,7 @@ TEST_F (PrefixTest, PrefixLPM) HICN_PREFIX (b009, "b009::/64"); EXPECT_EQ (hicn_prefix_lpm (&b007, &b009), (uint32_t) 12); + + HICN_PREFIX (pfx, "1122:3344:5566:7788:9900:aabb:ccdd:eeff/128"); + EXPECT_EQ (hicn_prefix_lpm (&pfx, &pfx), (uint32_t) 128); } diff --git a/lib/src/test/test_udp_header.cc b/lib/src/test/test_udp_header.cc index 2853ee31b..2856c8ebf 100644 --- a/lib/src/test/test_udp_header.cc +++ b/lib/src/test/test_udp_header.cc @@ -125,7 +125,7 @@ protected: TEST_F (UdpHeaderTest, GetFormat) { hicn_packet_format_t format = hicn_packet_get_format (&pkbuf_); - EXPECT_EQ (format.as_u32, HICN_PACKET_FORMAT_IPV6_UDP.as_u32); + EXPECT_EQ (format, HICN_PACKET_FORMAT_IPV6_UDP); } TEST_F (UdpHeaderAHTest, GetFormat) @@ -134,7 +134,7 @@ TEST_F (UdpHeaderAHTest, GetFormat) hicn_packet_format_t format = hicn_packet_get_format (&pkbuf_); // Check it corresponds to the new header format - EXPECT_EQ (format.as_u32, HICN_PACKET_FORMAT_IPV6_UDP_AH.as_u32); + EXPECT_EQ (format, HICN_PACKET_FORMAT_IPV6_UDP_AH); } #if 0 diff --git a/libtransport/includes/hicn/transport/core/io_module.h b/libtransport/includes/hicn/transport/core/io_module.h index ce6f3a629..cfaa61975 100644 --- a/libtransport/includes/hicn/transport/core/io_module.h +++ b/libtransport/includes/hicn/transport/core/io_module.h @@ -88,7 +88,7 @@ class IoModule : utils::NonCopyable { counters_.tx_packets++; counters_.tx_bytes += packet.payloadSize() + packet.headerSize(); - if (_is_ipv4(packet.getFormat())) { + if (HICN_PACKET_FORMAT_IS_IPV4(packet.getFormat())) { packet.setLocator(inet_address_); } else { packet.setLocator(inet6_address_); diff --git a/libtransport/includes/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h index 9277a52c2..31d856cd5 100644 --- a/libtransport/includes/hicn/transport/core/packet.h +++ b/libtransport/includes/hicn/transport/core/packet.h @@ -100,6 +100,7 @@ class Packet : public utils::MemBuf, void initialize(std::size_t additional_header_size = 0); void analyze(); + void initializeType(Packet::Type type); hicn_packet_type_t getType() const; void setType(Packet::Type type); @@ -146,12 +147,6 @@ class Packet : public utils::MemBuf, // TCP methods void setChecksum(); bool checkIntegrity() const; - Packet &setSrcPort(uint16_t srcPort); - Packet &setDstPort(uint16_t dstPort); - uint16_t getSrcPort() const; - uint16_t getDstPort() const; - Packet &setTTL(uint8_t hops); - uint8_t getTTL() const; // Authentication Header methods bool hasAH() const; diff --git a/libtransport/includes/hicn/transport/interfaces/socket_consumer.h b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h index d997634da..1c709eb72 100644 --- a/libtransport/includes/hicn/transport/interfaces/socket_consumer.h +++ b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h @@ -266,9 +266,6 @@ class ConsumerSocket : private utils::NonCopyable { int setSocketOption(int socket_option_key, StrategyCallback socket_option_value); - int setSocketOption(int socket_option_key, - Packet::Format socket_option_value); - int getSocketOption(int socket_option_key, double &socket_option_value); int getSocketOption(int socket_option_key, uint32_t &socket_option_value); @@ -302,9 +299,6 @@ class ConsumerSocket : private utils::NonCopyable { int getSocketOption(int socket_option_key, interface::TransportStatistics **socket_option_value); - int getSocketOption(int socket_option_key, - Packet::Format &socket_option_value); - protected: ConsumerSocket(); std::unique_ptr socket_; diff --git a/libtransport/includes/hicn/transport/interfaces/socket_producer.h b/libtransport/includes/hicn/transport/interfaces/socket_producer.h index be08c9a0b..2627b3138 100644 --- a/libtransport/includes/hicn/transport/interfaces/socket_producer.h +++ b/libtransport/includes/hicn/transport/interfaces/socket_producer.h @@ -130,9 +130,6 @@ class ProducerSocket : private utils::NonCopyable { int setSocketOption(int socket_option_key, const std::string &socket_option_value); - int setSocketOption(int socket_option_key, - Packet::Format socket_option_value); - int getSocketOption(int socket_option_key, uint32_t &socket_option_value); int getSocketOption(int socket_option_key, bool &socket_option_value); @@ -163,9 +160,6 @@ class ProducerSocket : private utils::NonCopyable { int getSocketOption(int socket_option_key, std::string &socket_option_value); - int getSocketOption(int socket_option_key, - Packet::Format &socket_option_value); - protected: ProducerSocket(bool); std::unique_ptr socket_; diff --git a/libtransport/src/core/packet.cc b/libtransport/src/core/packet.cc index e670ecb54..bcd0b8498 100644 --- a/libtransport/src/core/packet.cc +++ b/libtransport/src/core/packet.cc @@ -41,9 +41,9 @@ Packet::Packet(Type type, Format format, std::size_t additional_header_size) * We define the format and the storage area of the packet buffer we * manipulate */ - setType(type); setFormat(format); setBuffer(); + initializeType(type); // type requires packet format initialize(additional_header_size); } @@ -142,6 +142,10 @@ void Packet::analyze() { Packet::Type Packet::getType() const { return hicn_packet_get_type(&pkbuf_); } +void Packet::initializeType(Packet::Type type) { + hicn_packet_initialize_type(&pkbuf_, type); +} + void Packet::setType(Packet::Type type) { hicn_packet_set_type(&pkbuf_, type); } void Packet::setBuffer() { @@ -313,62 +317,7 @@ bool Packet::checkIntegrity() const { return true; } -Packet &Packet::setSrcPort(uint16_t srcPort) { - if (hicn_packet_set_src_port(&pkbuf_, srcPort) < 0) { - throw errors::RuntimeException("Error setting source port in the packet."); - } - - return *this; -} - -Packet &Packet::setDstPort(uint16_t dstPort) { - if (hicn_packet_set_dst_port(&pkbuf_, dstPort) < 0) { - throw errors::RuntimeException( - "Error setting destination port in the packet."); - } - - return *this; -} - -uint16_t Packet::getSrcPort() const { - uint16_t port = 0; - - if (hicn_packet_get_src_port(&pkbuf_, &port) < 0) { - throw errors::RuntimeException("Error reading source port in the packet."); - } - - return port; -} - -uint16_t Packet::getDstPort() const { - uint16_t port = 0; - - if (hicn_packet_get_dst_port(&pkbuf_, &port) < 0) { - throw errors::RuntimeException( - "Error reading destination port in the packet."); - } - - return port; -} - -Packet &Packet::setTTL(uint8_t hops) { - if (hicn_packet_set_ttl(&pkbuf_, hops) < 0) { - throw errors::RuntimeException("Error setting TTL."); - } - - return *this; -} - -uint8_t Packet::getTTL() const { - uint8_t hops = 0; - if (hicn_packet_get_ttl(&pkbuf_, &hops) < 0) { - throw errors::RuntimeException("Error reading TTL."); - } - - return hops; -} - -bool Packet::hasAH() const { return _is_ah(getFormat()); } +bool Packet::hasAH() const { return HICN_PACKET_FORMAT_IS_AH(getFormat()); } utils::MemBuf::Ptr Packet::getSignature() const { if (!hasAH()) { @@ -553,7 +502,7 @@ std::size_t Packet::getHeaderSizeFromFormat(Format format, std::size_t signature_size) { std::size_t header_length; hicn_packet_get_header_length_from_format(format, &header_length); - int is_ah = _is_ah(format); + int is_ah = HICN_PACKET_FORMAT_IS_AH(format); return is_ah * (header_length + signature_size) + (!is_ah) * header_length; } diff --git a/libtransport/src/implementation/socket.cc b/libtransport/src/implementation/socket.cc index 8e9760a5d..c554d09d3 100644 --- a/libtransport/src/implementation/socket.cc +++ b/libtransport/src/implementation/socket.cc @@ -23,34 +23,17 @@ namespace implementation { Socket::Socket(std::shared_ptr &&portal) : portal_(std::move(portal)), is_async_(false), - packet_format_(interface::default_values::packet_format), signer_(std::make_shared()), verifier_(std::make_shared()) {} int Socket::setSocketOption(int socket_option_key, hicn_packet_format_t packet_format) { - switch (socket_option_key) { - case interface::GeneralTransportOptions::PACKET_FORMAT: - packet_format_ = packet_format; - break; - default: - return SOCKET_OPTION_NOT_SET; - } - - return SOCKET_OPTION_SET; + return SOCKET_OPTION_NOT_SET; } int Socket::getSocketOption(int socket_option_key, hicn_packet_format_t &packet_format) { - switch (socket_option_key) { - case interface::GeneralTransportOptions::PACKET_FORMAT: - packet_format = packet_format_; - break; - default: - return SOCKET_OPTION_NOT_GET; - } - - return SOCKET_OPTION_GET; + return SOCKET_OPTION_NOT_GET; } } // namespace implementation diff --git a/libtransport/src/implementation/socket.h b/libtransport/src/implementation/socket.h index 55132eb75..d0d2ba2ac 100644 --- a/libtransport/src/implementation/socket.h +++ b/libtransport/src/implementation/socket.h @@ -71,7 +71,6 @@ class Socket { protected: std::shared_ptr portal_; bool is_async_; - hicn_packet_format_t packet_format_; std::shared_ptr signer_; std::shared_ptr verifier_; }; diff --git a/libtransport/src/implementation/socket_consumer.h b/libtransport/src/implementation/socket_consumer.h index 4721f426c..3117e21e7 100644 --- a/libtransport/src/implementation/socket_consumer.h +++ b/libtransport/src/implementation/socket_consumer.h @@ -39,6 +39,7 @@ class ConsumerSocket : public Socket { std::shared_ptr &&portal) : Socket(std::move(portal)), consumer_interface_(consumer), + packet_format_(default_values::packet_format), interest_lifetime_(default_values::interest_lifetime), min_window_size_(default_values::min_window_size), max_window_size_(default_values::max_window_size), @@ -273,6 +274,10 @@ class ConsumerSocket : public Socket { manifest_factor_alert_ = socket_option_value; break; + case GeneralTransportOptions::PACKET_FORMAT: + packet_format_ = socket_option_value; + break; + default: return SOCKET_OPTION_NOT_SET; } @@ -318,7 +323,6 @@ class ConsumerSocket : public Socket { on_content_object_input_ = VOID_HANDLER; break; } - default: return SOCKET_OPTION_NOT_SET; } @@ -602,6 +606,10 @@ class ConsumerSocket : public Socket { socket_option_value = manifest_factor_alert_; break; + case GeneralTransportOptions::PACKET_FORMAT: + socket_option_value = packet_format_; + break; + default: return SOCKET_OPTION_NOT_GET; } @@ -854,6 +862,7 @@ class ConsumerSocket : public Socket { // set from the consume Name network_name_; + hicn_packet_format_t packet_format_; int interest_lifetime_; double min_window_size_; diff --git a/libtransport/src/implementation/socket_producer.h b/libtransport/src/implementation/socket_producer.h index 53ce28766..c5e0929b2 100644 --- a/libtransport/src/implementation/socket_producer.h +++ b/libtransport/src/implementation/socket_producer.h @@ -48,6 +48,7 @@ class ProducerSocket : public Socket { std::shared_ptr &&portal) : Socket(std::move(portal)), producer_interface_(producer_socket), + packet_format_(default_values::packet_format), data_packet_size_(default_values::content_object_packet_size), max_segment_size_(default_values::content_object_packet_size), content_object_expiry_time_(default_values::content_object_expiry_time), @@ -199,6 +200,10 @@ class ProducerSocket : public Socket { content_object_expiry_time_ = socket_option_value; break; + case GeneralTransportOptions::PACKET_FORMAT: + packet_format_ = socket_option_value; + break; + default: return SOCKET_OPTION_NOT_SET; } @@ -490,6 +495,10 @@ class ProducerSocket : public Socket { socket_option_value = content_object_expiry_time_; break; + case GeneralTransportOptions::PACKET_FORMAT: + socket_option_value = packet_format_; + break; + default: return SOCKET_OPTION_NOT_SET; } @@ -758,6 +767,7 @@ class ProducerSocket : public Socket { // Threads protected: interface::ProducerSocket *producer_interface_; + std::atomic packet_format_; std::atomic data_packet_size_; std::atomic max_segment_size_; std::atomic content_object_expiry_time_; diff --git a/libtransport/src/interfaces/socket_consumer.cc b/libtransport/src/interfaces/socket_consumer.cc index cc496c8a5..afb672c95 100644 --- a/libtransport/src/interfaces/socket_consumer.cc +++ b/libtransport/src/interfaces/socket_consumer.cc @@ -127,11 +127,6 @@ int ConsumerSocket::setSocketOption(int socket_option_key, return socket_->setSocketOption(socket_option_key, socket_option_value); } -int ConsumerSocket::setSocketOption(int socket_option_key, - Packet::Format socket_option_value) { - return socket_->setSocketOption(socket_option_key, socket_option_value); -} - int ConsumerSocket::getSocketOption(int socket_option_key, double &socket_option_value) { return socket_->getSocketOption(socket_option_key, socket_option_value); @@ -200,11 +195,6 @@ int ConsumerSocket::getSocketOption(int socket_option_key, return socket_->getSocketOption(socket_option_key, socket_option_value); } -int ConsumerSocket::getSocketOption(int socket_option_key, - Packet::Format &socket_option_value) { - return socket_->getSocketOption(socket_option_key, socket_option_value); -} - } // namespace interface } // namespace transport diff --git a/libtransport/src/interfaces/socket_producer.cc b/libtransport/src/interfaces/socket_producer.cc index 2155ebd78..77e3bf633 100644 --- a/libtransport/src/interfaces/socket_producer.cc +++ b/libtransport/src/interfaces/socket_producer.cc @@ -154,11 +154,6 @@ int ProducerSocket::setSocketOption( return socket_->setSocketOption(socket_option_key, socket_option_value); } -int ProducerSocket::setSocketOption(int socket_option_key, - Packet::Format socket_option_value) { - return socket_->setSocketOption(socket_option_key, socket_option_value); -} - int ProducerSocket::getSocketOption(int socket_option_key, uint32_t &socket_option_value) { return socket_->getSocketOption(socket_option_key, socket_option_value); @@ -206,11 +201,6 @@ int ProducerSocket::getSocketOption( return socket_->getSocketOption(socket_option_key, socket_option_value); } -int ProducerSocket::getSocketOption(int socket_option_key, - Packet::Format &socket_option_value) { - return socket_->getSocketOption(socket_option_key, socket_option_value); -} - } // namespace interface } // namespace transport diff --git a/libtransport/src/protocols/prod_protocol_rtc.cc b/libtransport/src/protocols/prod_protocol_rtc.cc index aebad23d6..83cd23ac6 100644 --- a/libtransport/src/protocols/prod_protocol_rtc.cc +++ b/libtransport/src/protocols/prod_protocol_rtc.cc @@ -692,7 +692,7 @@ void RTCProductionProtocol::sendNack(uint32_t sequence) { void RTCProductionProtocol::sendContentObject( std::shared_ptr content_object, bool nack, bool fec) { - bool is_ah = _is_ah(content_object->getFormat()); + bool is_ah = HICN_PACKET_FORMAT_IS_AH(content_object->getFormat()); // Compute signature if (is_ah) { diff --git a/libtransport/src/protocols/rtc/rtc_verifier.cc b/libtransport/src/protocols/rtc/rtc_verifier.cc index 861ceee89..60fce92a5 100644 --- a/libtransport/src/protocols/rtc/rtc_verifier.cc +++ b/libtransport/src/protocols/rtc/rtc_verifier.cc @@ -106,7 +106,7 @@ auth::VerificationPolicy RTCVerifier::verifyFec( auth::VerificationPolicy RTCVerifier::verifyData( core::ContentObject &content_object) { - if (_is_ah(content_object.getFormat())) { + if (HICN_PACKET_FORMAT_IS_AH(content_object.getFormat())) { return verifier_->verifyPackets(&content_object); } diff --git a/libtransport/src/protocols/transport_protocol.cc b/libtransport/src/protocols/transport_protocol.cc index 5b262e4e7..29d140454 100644 --- a/libtransport/src/protocols/transport_protocol.cc +++ b/libtransport/src/protocols/transport_protocol.cc @@ -179,7 +179,7 @@ void TransportProtocol::sendInterest( if (content_sharing_mode) lifetime = ceil((double)lifetime * 0.9); // Compute signature - bool is_ah = _is_ah(interest->getFormat()); + bool is_ah = HICN_PACKET_FORMAT_IS_AH(interest->getFormat()); if (is_ah) signer_->signPacket(interest.get()); portal_->sendInterest(interest, lifetime); diff --git a/libtransport/src/test/test_auth.cc b/libtransport/src/test/test_auth.cc index 5b9b04c5c..2ee3c0776 100644 --- a/libtransport/src/test/test_auth.cc +++ b/libtransport/src/test/test_auth.cc @@ -88,7 +88,7 @@ TEST_F(AuthTest, AsymmetricRSA) { std::shared_ptr verifier = std::make_shared(pubKey); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP_AH); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::RSA_SHA256); EXPECT_EQ(signer->getSignatureSize(), 256u); @@ -202,7 +202,7 @@ TEST_F(AuthTest, AsymmetricVerifierDSA) { std::shared_ptr verifier = std::make_shared(cert); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP_AH); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::DSA_SHA256); EXPECT_EQ(verifier->verifyPackets(&packet), VerificationPolicy::ACCEPT); @@ -269,7 +269,7 @@ TEST_F(AuthTest, AsymmetricVerifierECDSA) { packet.appendPayload(buffer, 256); signer->signPacket(&packet); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP_AH); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::ECDSA_SHA256); EXPECT_EQ(verifier->verifyPackets(&packet), VerificationPolicy::ACCEPT); @@ -314,7 +314,7 @@ TEST_F(AuthTest, HMACVerifier) { std::shared_ptr verifier = std::make_shared(PASSPHRASE); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP_AH); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::HMAC_SHA256); EXPECT_EQ(signer->getSignatureSize(), 32u); diff --git a/libtransport/src/test/test_packet.cc b/libtransport/src/test/test_packet.cc index 3dfca8f9a..f2f658932 100644 --- a/libtransport/src/test/test_packet.cc +++ b/libtransport/src/test/test_packet.cc @@ -76,8 +76,8 @@ class PacketTest : public ::testing::Test { PacketTest() : name_("b001::123|321"), packet(Packet::COPY_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()) { + &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()) { // You can do set-up work for each test here. } @@ -119,7 +119,7 @@ class PacketTest : public ::testing::Test { }; std::map> PacketTest::raw_packets_ = { - {HICN_PACKET_FORMAT_IPV6_TCP.as_u32, + {HICN_PACKET_FORMAT_IPV6_TCP, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(TCP_PROTO, 20 + PAYLOAD_SIZE), @@ -128,7 +128,7 @@ std::map> PacketTest::raw_packets_ = { // Payload PAYLOAD}}, - {HICN_PACKET_FORMAT_IPV4_TCP.as_u32, + {HICN_PACKET_FORMAT_IPV4_TCP, {// IPv4 src=3.13.127.8, dst=192.168.1.92 IPV4_HEADER(TCP_PROTO, 20 + PAYLOAD_SIZE), // TCP src=0x1234 dst=0x4321, seq=0x0001 @@ -136,19 +136,19 @@ std::map> PacketTest::raw_packets_ = { // Other PAYLOAD}}, - {HICN_PACKET_FORMAT_IPV4_ICMP.as_u32, + {HICN_PACKET_FORMAT_IPV4_ICMP, {// IPv4 src=3.13.127.8, dst=192.168.1.92 IPV4_HEADER(ICMP_PROTO, 64), // ICMP echo request ICMP_ECHO_REQUEST}}, - {HICN_PACKET_FORMAT_IPV6_ICMP.as_u32, + {HICN_PACKET_FORMAT_IPV6_ICMP, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(ICMP6_PROTO, 60), // ICMP6 echo request ICMP6_ECHO_REQUEST}}, - {HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32, + {HICN_PACKET_FORMAT_IPV6_TCP_AH, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(TCP_PROTO, 20 + 44 + 128), // ICMP6 echo request @@ -156,7 +156,7 @@ std::map> PacketTest::raw_packets_ = { // hICN AH header AH_HEADER, SIGNATURE}}, - {HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32, + {HICN_PACKET_FORMAT_IPV4_TCP_AH, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV4_HEADER(TCP_PROTO, 20 + 44 + 128), // ICMP6 echo request @@ -165,7 +165,7 @@ std::map> PacketTest::raw_packets_ = { AH_HEADER, SIGNATURE}}, // XXX No flag defined in ICMP header to signal AH header. - {HICN_PACKET_FORMAT_IPV4_ICMP_AH.as_u32, + {HICN_PACKET_FORMAT_IPV4_ICMP_AH, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV4_HEADER(ICMP_PROTO, 64 + 44), // ICMP6 echo request @@ -173,7 +173,7 @@ std::map> PacketTest::raw_packets_ = { // hICN AH header AH_HEADER, SIGNATURE}}, - {HICN_PACKET_FORMAT_IPV6_ICMP_AH.as_u32, + {HICN_PACKET_FORMAT_IPV6_ICMP_AH, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(ICMP6_PROTO, 60 + 44), // ICMP6 echo request @@ -213,7 +213,7 @@ void testRawBufferConstructor(std::vector packet, packet.size()); // Check format is expected one. - EXPECT_EQ(p.getFormat().as_u32, format.as_u32); + EXPECT_EQ(p.getFormat(), format); // // Try the same using a MemBuf // auto buf = utils::MemBuf::wrapBuffer(&packet[0], packet.size()); @@ -237,7 +237,7 @@ void testRawBufferConstructor(std::vector packet, packet.size()); // Format should fallback to HICN_PACKET_FORMAT_NONE - EXPECT_EQ(p.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); + EXPECT_EQ(p.getFormat(), HICN_PACKET_FORMAT_NONE); } catch (errors::MalformedPacketException &exc) { // Ok right exception } catch (...) { @@ -267,7 +267,7 @@ void getPayloadSizeFromBuffer(std::vector &packet, void getFormatFromBuffer(Packet::Format expected, std::vector &packet) { auto format = PacketForTest::getFormatFromBuffer(&packet[0], packet.size()); - EXPECT_EQ(format.as_u32, expected.as_u32); + EXPECT_EQ(format, expected); } void getHeaderSize(std::size_t expected, const PacketForTest &packet) { @@ -277,7 +277,7 @@ void getHeaderSize(std::size_t expected, const PacketForTest &packet) { void testGetFormat(Packet::Format expected, const Packet &packet) { auto format = packet.getFormat(); - EXPECT_EQ(format.as_u32, expected.as_u32); + EXPECT_EQ(format, expected); } } // namespace @@ -306,7 +306,7 @@ TEST_F(PacketTest, ConstructorWithFormatAndAdditionalHeader) { } TEST_F(PacketTest, ConstructorWithNew) { - auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP]; auto packet_ptr = new PacketForTest(Packet::WRAP_BUFFER, &_packet[0], _packet.size(), _packet.size()); delete packet_ptr; @@ -314,53 +314,53 @@ TEST_F(PacketTest, ConstructorWithNew) { TEST_F(PacketTest, ConstructorWithRawBufferInet6Tcp) { auto format = HICN_PACKET_FORMAT_IPV6_TCP; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetTcp) { auto format = HICN_PACKET_FORMAT_IPV4_TCP; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetIcmp) { auto format = HICN_PACKET_FORMAT_IPV4_ICMP; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInet6Icmp) { auto format = HICN_PACKET_FORMAT_IPV6_ICMP; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInet6TcpAh) { auto format = HICN_PACKET_FORMAT_IPV6_TCP_AH; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetTcpAh) { auto format = HICN_PACKET_FORMAT_IPV4_TCP_AH; - testRawBufferConstructor(raw_packets_[format.as_u32], format); + testRawBufferConstructor(raw_packets_[format], format); } TEST_F(PacketTest, MoveConstructor) { PacketForTest p0(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP); PacketForTest p1(std::move(p0)); - EXPECT_EQ(p0.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); - EXPECT_EQ(p1.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP.as_u32); + EXPECT_EQ(p0.getFormat(), HICN_PACKET_FORMAT_NONE); + EXPECT_EQ(p1.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP); } TEST_F(PacketTest, TestGetHeaderSizeFromBuffer) { - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP], IPV6_HDRLEN + TCP_HDRLEN); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP], IPV4_HDRLEN + TCP_HDRLEN); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP], IPV6_HDRLEN + 4); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP], IPV4_HDRLEN + 4); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH], IPV6_HDRLEN + TCP_HDRLEN + AH_HDRLEN + 128); - getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH], IPV4_HDRLEN + TCP_HDRLEN + AH_HDRLEN + 128); } @@ -378,23 +378,17 @@ TEST_F(PacketTest, TestGetHeaderSizeFromFormat) { } TEST_F(PacketTest, TestGetPayloadSizeFromBuffer) { - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32], - 12); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32], - 12); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32], - 56); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32], - 60); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32], - 0); - getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32], - 0); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP], 12); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP], 12); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP], 56); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP], 60); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH], 0); + getPayloadSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH], 0); } #if 0 TEST_F(PacketTest, TestIsInterest) { - auto ret = PacketForTest::isInterest(&raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0]); + auto ret = PacketForTest::isInterest(&raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0]); EXPECT_TRUE(ret); } @@ -402,27 +396,27 @@ TEST_F(PacketTest, TestIsInterest) { TEST_F(PacketTest, TestGetFormatFromBuffer) { getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_TCP, - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_TCP, - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_ICMP, - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_ICMP, - raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_TCP_AH, - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH]); getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_TCP_AH, - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32]); + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH]); } // TEST_F(PacketTest, TestReplace) { // PacketForTest packet(Packet::WRAP_BUFFER, -// &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], -// raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); +// &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0], +// raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); // // Replace current packet with another one -// packet.replace(&raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32][0], -// raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32].size()); +// packet.replace(&raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP][0], +// raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP].size()); // // Check new format // ASSERT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV4_TCP); @@ -430,7 +424,7 @@ TEST_F(PacketTest, TestGetFormatFromBuffer) { TEST_F(PacketTest, TestPayloadSize) { // Check payload size of existing packet - auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP]; PacketForTest packet(Packet::WRAP_BUFFER, &_packet[0], _packet.size(), _packet.size()); @@ -489,7 +483,7 @@ TEST_F(PacketTest, TestHeaderSize) { TEST_F(PacketTest, TestMemBufReference) { // Create packet - auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP]; // Packet was not created as a shared_ptr. If we try to get a membuf shared // ptr we should get an exception. @@ -530,9 +524,8 @@ TEST_F(PacketTest, TestMemBufReference) { TEST_F(PacketTest, TestReset) { // Check everything is ok - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP.as_u32); - EXPECT_EQ(packet.length(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV6_TCP); + EXPECT_EQ(packet.length(), raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); EXPECT_EQ(packet.headerSize(), IPV6_HDRLEN + TCP_HDRLEN); EXPECT_EQ(packet.payloadSize(), packet.length() - packet.headerSize()); @@ -540,7 +533,7 @@ TEST_F(PacketTest, TestReset) { packet.reset(); // Rerun test - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_NONE); EXPECT_EQ(packet.length(), std::size_t(0)); EXPECT_EQ(packet.headerSize(), std::size_t(0)); EXPECT_EQ(packet.payloadSize(), std::size_t(0)); @@ -581,7 +574,7 @@ TEST_F(PacketTest, TestAppendPayload) { // There should be no more bufferls left in the chain EXPECT_EQ(&packet, packet.next()); - EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); + EXPECT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_NONE); EXPECT_EQ(packet.length(), std::size_t(0)); EXPECT_EQ(packet.headerSize(), std::size_t(0)); EXPECT_EQ(packet.payloadSize(), std::size_t(0)); @@ -655,41 +648,39 @@ TEST_F(PacketTest, SetGetPayloadType) { TEST_F(PacketTest, GetFormat) { { PacketForTest p0(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32].size()); + &raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP].size()); testGetFormat(HICN_PACKET_FORMAT_IPV4_TCP, p0); PacketForTest p1(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); testGetFormat(HICN_PACKET_FORMAT_IPV6_TCP, p1); PacketForTest p2(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32].size()); + &raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP].size()); testGetFormat(HICN_PACKET_FORMAT_IPV4_ICMP, p2); PacketForTest p3(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size()); + &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP].size()); testGetFormat(HICN_PACKET_FORMAT_IPV6_ICMP, p3); - PacketForTest p4( - Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32].size()); + PacketForTest p4(Packet::WRAP_BUFFER, + &raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH][0], + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH].size()); testGetFormat(HICN_PACKET_FORMAT_IPV4_TCP_AH, p4); - PacketForTest p5( - Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32].size()); + PacketForTest p5(Packet::WRAP_BUFFER, + &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH].size()); testGetFormat(HICN_PACKET_FORMAT_IPV6_TCP_AH, p5); } @@ -848,83 +839,39 @@ TEST_F(PacketTest, DISABLED_TestChecksum) { EXPECT_TRUE(integrity); } -TEST_F(PacketTest, TestSetGetSrcPort) { - try { - auto p = - PacketForTest(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size()); - // Let's make compiler happy - p.setSrcPort(12345); - FAIL() << "We should not reach this point."; - } catch (const errors::RuntimeException &exc) { - /* ok right exception*/ - } catch (...) { - FAIL() << "Unexpected exception"; - } - - packet.setSrcPort(12345); - EXPECT_EQ(packet.getSrcPort(), 12345); -} - -TEST_F(PacketTest, TestSetGetDstPort) { - try { - auto p = - PacketForTest(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size()); - // Let's make compiler happy - p.setDstPort(12345); - FAIL() << "We should not reach this point."; - } catch (const errors::RuntimeException &exc) { - /* ok right exception*/ - } catch (...) { - FAIL() << "Unexpected exception"; - } - - packet.setDstPort(12345); - EXPECT_EQ(packet.getDstPort(), 12345); -} - TEST_F(PacketTest, TestEnsureCapacity) { PacketForTest &p = packet; // This shoul be false - auto ret = p.ensureCapacity( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() + 10); + auto ret = + p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() + 10); EXPECT_FALSE(ret); // This should be true - ret = - p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + ret = p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); EXPECT_TRUE(ret); // This should be true - ret = p.ensureCapacity( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - 10); + ret = p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - 10); EXPECT_TRUE(ret); // Try to trim the packet start p.trimStart(10); // Now this should be false - ret = - p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + ret = p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); EXPECT_FALSE(ret); // Create a new packet - auto p2 = - PacketForTest(Packet::WRAP_BUFFER, - &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size(), - raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32].size()); + auto p2 = PacketForTest(Packet::WRAP_BUFFER, + &raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP].size(), + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP].size()); p2.appendPayload(utils::MemBuf::createCombined(2000)); // This should be false, since the buffer is chained - ret = p2.ensureCapacity( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - 10); + ret = + p2.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - 10); EXPECT_FALSE(ret); } @@ -936,21 +883,20 @@ TEST_F(PacketTest, DISABLED_TestEnsureCapacityAndFillUnused) { // Create packet by excluding the payload (So only L3 + L4 headers). The // payload will be trated as unused tailroom PacketForTest p = PacketForTest( - Packet::WRAP_BUFFER, &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - PAYLOAD_SIZE, - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); + Packet::WRAP_BUFFER, &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - PAYLOAD_SIZE, + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size()); // Copy original packet payload, which is here trated as a unused tailroom uint8_t original_payload[PAYLOAD_SIZE]; - uint8_t *payload = &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0] + - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - + uint8_t *payload = &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP][0] + + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - PAYLOAD_SIZE; std::memcpy(original_payload, payload, PAYLOAD_SIZE); // This should be true and the unused tailroom should be unmodified auto ret = p.ensureCapacityAndFillUnused( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - - (PAYLOAD_SIZE + 10), + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() - (PAYLOAD_SIZE + 10), 0); EXPECT_TRUE(ret); ret = std::memcmp(original_payload, payload, PAYLOAD_SIZE); @@ -958,7 +904,7 @@ TEST_F(PacketTest, DISABLED_TestEnsureCapacityAndFillUnused) { // This should fill the payload with zeros ret = p.ensureCapacityAndFillUnused( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size(), 0); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size(), 0); EXPECT_TRUE(ret); uint8_t zeros[PAYLOAD_SIZE]; std::memset(zeros, 0, PAYLOAD_SIZE); @@ -967,7 +913,7 @@ TEST_F(PacketTest, DISABLED_TestEnsureCapacityAndFillUnused) { // This should fill the payload with ones ret = p.ensureCapacityAndFillUnused( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size(), 1); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size(), 1); EXPECT_TRUE(ret); uint8_t ones[PAYLOAD_SIZE]; std::memset(ones, 1, PAYLOAD_SIZE); @@ -976,16 +922,11 @@ TEST_F(PacketTest, DISABLED_TestEnsureCapacityAndFillUnused) { // This should return false and the payload should be unmodified ret = p.ensureCapacityAndFillUnused( - raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() + 1, 1); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP].size() + 1, 1); EXPECT_FALSE(ret); ret = std::memcmp(payload, ones, PAYLOAD_SIZE); EXPECT_EQ(ret, 0); } -TEST_F(PacketTest, TestSetGetTTL) { - packet.setTTL(128); - EXPECT_EQ(packet.getTTL(), 128); -} - } // namespace core } // namespace transport diff --git a/tests/config.sh b/tests/config.sh index b10d11204..8d36382d9 100755 --- a/tests/config.sh +++ b/tests/config.sh @@ -39,6 +39,7 @@ HIPERF_CMD_MEMIF_RAAQM="${HIPERF_CMD_RAAQM} -z memif_module" HIPERF_CMD_MEMIF_CBR="${HIPERF_CMD_CBR} -z memif_module" PING_CMD="ENABLE_LOG_PREFIX=OFF LOG_LEVEL=1 hicn-ping-client -m 50 -i 200000 -n ${PING_PRODUCER}" +PING_CMD_NEW="ENABLE_LOG_PREFIX=OFF LOG_LEVEL=1 hicn-ping-client -m 50 -i 200000 -n ${PING_PRODUCER} -w new" PING_CMD_MEMIF="${PING_CMD} -z memif_module" POSTPROCESS_COMMAND_PING='grep trip | \ cut -f 4 -d " " | \ @@ -88,6 +89,7 @@ declare -A tests=( ["vpp-bridge-latency"]="${PING_CMD_MEMIF} 2>&1 | tee >(>&2 cat) | ${POSTPROCESS_COMMAND_PING}" ["vpp-memif-latency"]="${PING_CMD_MEMIF} 2>&1 | tee >(>&2 cat) | ${POSTPROCESS_COMMAND_PING}" ["vpp-memif-replication-latency"]="${PING_CMD_MEMIF} 2>&1 | tee >(>&2 cat) | ${POSTPROCESS_COMMAND_PING}" + ["hicn-light-latency-new"]="${PING_CMD_NEW} 2>&1 | tee >(>&2 cat) | ${POSTPROCESS_COMMAND_PING}" ) declare -A link_model=( diff --git a/tests/functional-tests/2-nodes-hicn-light.robot b/tests/functional-tests/2-nodes-hicn-light.robot index 9aa5923a0..e23c35e6a 100644 --- a/tests/functional-tests/2-nodes-hicn-light.robot +++ b/tests/functional-tests/2-nodes-hicn-light.robot @@ -22,3 +22,7 @@ RTC Testing Mobile Latency Testing Mobile Set Link hicn-light 500 1 0 0 Run Latency Test hicn-light 3000 3000 3000 + +Latency Testing Mobile New + Set Link hicn-light 500 1 0 0 + Run Latency Test New hicn-light 3000 3000 3000 diff --git a/tests/resources/libraries/robot/runtest.robot b/tests/resources/libraries/robot/runtest.robot index d5201d765..379b4d307 100644 --- a/tests/resources/libraries/robot/runtest.robot +++ b/tests/resources/libraries/robot/runtest.robot @@ -32,6 +32,10 @@ Run Test Should Be True ${min_max_avg}[0] >= ${EXPECTED_MIN} msg="Min does not match (${min_max_avg}[0] < ${EXPECTED_MIN})" Should Be True ${min_max_avg}[1] >= ${EXPECTED_MAX} msg="Max does not match (${min_max_avg}[1] < ${EXPECTED_MAX})" Should Be True ${min_max_avg}[2] >= ${EXPECTED_AVG} msg="Avg does not match (${min_max_avg}[2] < ${EXPECTED_AVG})" + ELSE IF '${TESTID}' == 'latency-new' + Should Be True ${min_max_avg}[0] <= ${EXPECTED_MIN} msg="Min does not match (${min_max_avg}[0] > ${EXPECTED_MIN})" + Should Be True ${min_max_avg}[1] <= ${EXPECTED_MAX} msg="Max does not match (${min_max_avg}[1] > ${EXPECTED_MAX})" + Should Be True ${min_max_avg}[2] <= ${EXPECTED_AVG} msg="Avg does not match (${min_max_avg}[2] > ${EXPECTED_AVG})" ELSE Fail "Provided Test ID does not exist" END @@ -90,3 +94,13 @@ Run RTC Test ... ${EXPECTED_AVG} The expected avg bitrate [Arguments] ${TEST_SETUP}=${NONE} ${EXPECTED_MIN}=${NONE} ${EXPECTED_MAX}=${NONE} ${EXPECTED_AVG}=${NONE} Run Test ${TEST_SETUP} rtc ${EXPECTED_MIN} ${EXPECTED_MAX} ${EXPECTED_AVG} + +Run Latency Test New + [Documentation] Run hicn-ping on the ${TEST_SETUP} topology with the new packet format and measure latency. + ... Arguments: + ... ${TEST_SETUP} The setup of the test. + ... ${EXPECTED_MIN} The expected min latency + ... ${EXPECTED_MAX} The expected max latency + ... ${EXPECTED_AVG} The expected avg latency + [Arguments] ${TEST_SETUP}=${NONE} ${EXPECTED_MIN}=${NONE} ${EXPECTED_MAX}=${NONE} ${EXPECTED_AVG}=${NONE} + Run Test ${TEST_SETUP} latency-new ${EXPECTED_MIN} ${EXPECTED_MAX} ${EXPECTED_AVG} -- cgit 1.2.3-korg