diff options
Diffstat (limited to 'libtransport/src')
35 files changed, 783 insertions, 912 deletions
diff --git a/libtransport/src/auth/signer.cc b/libtransport/src/auth/signer.cc index f13df53eb..500732ba1 100644 --- a/libtransport/src/auth/signer.cc +++ b/libtransport/src/auth/signer.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -36,8 +36,6 @@ Signer::~Signer() {} void Signer::signPacket(PacketPtr packet) { DCHECK(key_ != nullptr); - core::Packet::Format format = packet->getFormat(); - if (!packet->hasAH()) { throw errors::MalformedAHPacketException(); } @@ -48,8 +46,9 @@ void Signer::signPacket(PacketPtr packet) { packet->updateLength(); // update IP payload length // Copy IP+TCP / ICMP header before zeroing them - hicn_header_t header_copy; - hicn_packet_copy_header(format, packet->packet_start_, &header_copy, false); + u8 header_copy[HICN_HDRLEN_MAX]; + size_t header_len; + packet->saveHeader(header_copy, &header_len); // Copy bitmap from interest manifest uint32_t request_bitmap[BITMAP_SIZE] = {0}; @@ -78,7 +77,7 @@ void Signer::signPacket(PacketPtr packet) { packet->setSignatureSize(signature_len_); // Restore header - hicn_packet_copy_header(format, &header_copy, packet->packet_start_, false); + packet->loadHeader(header_copy, header_len); // Restore bitmap in interest manifest if (packet->isInterest()) { diff --git a/libtransport/src/auth/verifier.cc b/libtransport/src/auth/verifier.cc index e257582f6..f930383e6 100644 --- a/libtransport/src/auth/verifier.cc +++ b/libtransport/src/auth/verifier.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -38,8 +38,6 @@ Verifier::Verifier() Verifier::~Verifier() {} bool Verifier::verifyPacket(PacketPtr packet) { - core::Packet::Format format = packet->getFormat(); - if (!packet->hasAH()) { throw errors::MalformedAHPacketException(); } @@ -49,8 +47,9 @@ bool Verifier::verifyPacket(PacketPtr packet) { CryptoHashType hash_type = getHashType(suite); // Copy IP+TCP / ICMP header before zeroing them - hicn_header_t header_copy; - hicn_packet_copy_header(format, packet->packet_start_, &header_copy, false); + u8 header_copy[HICN_HDRLEN_MAX]; + size_t header_len; + packet->saveHeader(header_copy, &header_len); // Copy bitmap from interest manifest uint32_t request_bitmap[BITMAP_SIZE] = {0}; @@ -74,7 +73,7 @@ bool Verifier::verifyPacket(PacketPtr packet) { signature_raw, hash_type); // Restore header - hicn_packet_copy_header(format, &header_copy, packet->packet_start_, false); + packet->loadHeader(header_copy, header_len); packet->setSignature(signature_raw); packet->setSignatureSize(signature_raw->length()); diff --git a/libtransport/src/core/content_object.cc b/libtransport/src/core/content_object.cc index e66b2a6cd..7ed6c57ab 100644 --- a/libtransport/src/core/content_object.cc +++ b/libtransport/src/core/content_object.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -35,25 +35,18 @@ namespace core { ContentObject::ContentObject(const Name &name, Packet::Format format, std::size_t additional_header_size) - : Packet(format, additional_header_size) { - if (TRANSPORT_EXPECT_FALSE(hicn_packet_set_data(format_, packet_start_) < - 0)) { - throw errors::MalformedPacketException(); - } - - if (TRANSPORT_EXPECT_FALSE( - hicn_data_set_name(format, packet_start_, &name.name_) < 0)) { + : Packet(HICN_PACKET_TYPE_DATA, format, additional_header_size) { + if (TRANSPORT_EXPECT_FALSE(hicn_data_set_name(&pkbuf_, &name.name_) < 0)) { throw errors::RuntimeException("Error filling the packet name."); } - if (TRANSPORT_EXPECT_FALSE(hicn_data_get_name(format_, packet_start_, - &name_.getStructReference()) < - 0)) { + if (TRANSPORT_EXPECT_FALSE( + hicn_data_get_name(&pkbuf_, &name_.getStructReference()) < 0)) { throw errors::MalformedPacketException(); } } -ContentObject::ContentObject(hicn_format_t format, +ContentObject::ContentObject(hicn_packet_format_t format, std::size_t additional_header_size) : ContentObject( #ifdef __ANDROID__ @@ -62,13 +55,9 @@ ContentObject::ContentObject(hicn_format_t format, Packet::base_name, #endif format, additional_header_size) { - if (TRANSPORT_EXPECT_FALSE(hicn_packet_set_data(format_, packet_start_) < - 0)) { - throw errors::MalformedPacketException(); - } } -ContentObject::ContentObject(const Name &name, hicn_format_t format, +ContentObject::ContentObject(const Name &name, hicn_packet_format_t format, std::size_t additional_header_size, const uint8_t *payload, std::size_t size) : ContentObject(name, format, additional_header_size) { @@ -91,9 +80,8 @@ ContentObject::~ContentObject() {} const Name &ContentObject::getName() const { if (!name_) { - if (hicn_data_get_name(format_, packet_start_, - (hicn_name_t *)&name_.getConstStructReference()) < - 0) { + if (hicn_data_get_name( + &pkbuf_, (hicn_name_t *)&name_.getConstStructReference()) < 0) { throw errors::MalformedPacketException(); } } @@ -104,31 +92,27 @@ const Name &ContentObject::getName() const { Name &ContentObject::getWritableName() { return const_cast<Name &>(getName()); } void ContentObject::setName(const Name &name) { - if (hicn_data_set_name(format_, packet_start_, - &name.getConstStructReference()) < 0) { + if (hicn_data_set_name(&pkbuf_, &name.getConstStructReference()) < 0) { throw errors::RuntimeException("Error setting content object name."); } - if (hicn_data_get_name(format_, packet_start_, &name_.getStructReference()) < - 0) { + if (hicn_data_get_name(&pkbuf_, &name_.getStructReference()) < 0) { throw errors::MalformedPacketException(); } } -uint32_t ContentObject::getPathLabel() const { - uint32_t path_label; - if (hicn_data_get_path_label(packet_start_, &path_label) < 0) { +hicn_path_label_t ContentObject::getPathLabel() const { + hicn_path_label_t path_label; + if (hicn_data_get_path_label(&pkbuf_, &path_label) < 0) { throw errors::RuntimeException( "Error retrieving the path label from content object"); } - return portability::net_to_host(path_label); + return path_label; } -ContentObject &ContentObject::setPathLabel(uint32_t path_label) { - path_label = portability::host_to_net(path_label); - if (hicn_data_set_path_label((hicn_header_t *)packet_start_, path_label) < - 0) { +ContentObject &ContentObject::setPathLabel(hicn_path_label_t path_label) { + if (hicn_data_set_path_label(&pkbuf_, path_label) < 0) { throw errors::RuntimeException( "Error setting the path label from content object"); } @@ -136,18 +120,18 @@ ContentObject &ContentObject::setPathLabel(uint32_t path_label) { return *this; } -void ContentObject::setLocator(const ip_address_t &ip_address) { - if (hicn_data_set_locator(format_, packet_start_, &ip_address) < 0) { +void ContentObject::setLocator(const hicn_ip_address_t &ip_address) { + if (hicn_data_set_locator(&pkbuf_, &ip_address) < 0) { throw errors::RuntimeException("Error setting content object locator"); } return; } -ip_address_t ContentObject::getLocator() const { - ip_address_t ip; +hicn_ip_address_t ContentObject::getLocator() const { + hicn_ip_address_t ip; - if (hicn_data_get_locator(format_, packet_start_, &ip) < 0) { + if (hicn_data_get_locator(&pkbuf_, &ip) < 0) { throw errors::RuntimeException("Error getting content object locator."); } @@ -155,7 +139,7 @@ ip_address_t ContentObject::getLocator() const { } void ContentObject::setLifetime(uint32_t lifetime) { - if (hicn_data_set_expiry_time(packet_start_, lifetime) < 0) { + if (hicn_data_set_expiry_time(&pkbuf_, lifetime) < 0) { throw errors::MalformedPacketException(); } } @@ -163,7 +147,7 @@ void ContentObject::setLifetime(uint32_t lifetime) { uint32_t ContentObject::getLifetime() const { uint32_t lifetime = 0; - if (hicn_data_get_expiry_time(packet_start_, &lifetime) < 0) { + if (hicn_data_get_expiry_time(&pkbuf_, &lifetime) < 0) { throw errors::MalformedPacketException(); } @@ -171,8 +155,7 @@ uint32_t ContentObject::getLifetime() const { } void ContentObject::resetForHash() { - if (hicn_data_reset_for_hash( - format_, reinterpret_cast<hicn_header_t *>(packet_start_)) < 0) { + if (hicn_data_reset_for_hash(&pkbuf_) < 0) { throw errors::RuntimeException( "Error resetting content object fields for hash computation."); } @@ -180,7 +163,7 @@ void ContentObject::resetForHash() { bool ContentObject::isLast() const { int is_last = 0; - if (hicn_data_is_last(format_, packet_start_, &is_last) < 0) { + if (hicn_data_is_last(&pkbuf_, &is_last) < 0) { throw errors::RuntimeException( "Impossible to get last data flag from packet header."); } @@ -189,7 +172,7 @@ bool ContentObject::isLast() const { } void ContentObject::setLast() { - if (hicn_data_set_last(format_, packet_start_) < 0) { + if (hicn_data_set_last(&pkbuf_) < 0) { throw errors::RuntimeException( "Impossible to set last data flag to packet header."); } diff --git a/libtransport/src/core/interest.cc b/libtransport/src/core/interest.cc index 8b9dcf256..0851bfef6 100644 --- a/libtransport/src/core/interest.cc +++ b/libtransport/src/core/interest.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -23,6 +23,7 @@ TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat") #endif #include <hicn/base.h> #include <hicn/hicn.h> +#include <hicn/interest_manifest.h> } #include <cstring> @@ -34,23 +35,19 @@ namespace core { Interest::Interest(const Name &interest_name, Packet::Format format, std::size_t additional_header_size) - : Packet(format, additional_header_size) { - if (hicn_packet_set_interest(format_, packet_start_) < 0) { - throw errors::MalformedPacketException(); - } - - if (hicn_interest_set_name(format_, packet_start_, + : Packet(HICN_PACKET_TYPE_INTEREST, format, additional_header_size) { + if (hicn_interest_set_name(&pkbuf_, &interest_name.getConstStructReference()) < 0) { throw errors::MalformedPacketException(); } - if (hicn_interest_get_name(format_, packet_start_, - &name_.getStructReference()) < 0) { + if (hicn_interest_get_name(&pkbuf_, &name_.getStructReference()) < 0) { throw errors::MalformedPacketException(); } } -Interest::Interest(hicn_format_t format, std::size_t additional_header_size) +Interest::Interest(hicn_packet_format_t format, + std::size_t additional_header_size) : Interest( #ifdef __ANDROID__ Name("0::0|0"), @@ -58,14 +55,10 @@ Interest::Interest(hicn_format_t format, std::size_t additional_header_size) base_name, #endif format, additional_header_size) { - if (hicn_packet_set_interest(format_, packet_start_) < 0) { - throw errors::MalformedPacketException(); - } } Interest::Interest(MemBuf &&buffer) : Packet(std::move(buffer)) { - if (hicn_interest_get_name(format_, packet_start_, - &name_.getStructReference()) < 0) { + if (hicn_interest_get_name(&pkbuf_, &name_.getStructReference()) < 0) { throw errors::MalformedPacketException(); } } @@ -88,8 +81,7 @@ Interest::~Interest() {} const Name &Interest::getName() const { if (!name_) { if (hicn_interest_get_name( - format_, packet_start_, - (hicn_name_t *)&name_.getConstStructReference()) < 0) { + &pkbuf_, (hicn_name_t *)&name_.getConstStructReference()) < 0) { throw errors::MalformedPacketException(); } } @@ -100,29 +92,27 @@ const Name &Interest::getName() const { Name &Interest::getWritableName() { return const_cast<Name &>(getName()); } void Interest::setName(const Name &name) { - if (hicn_interest_set_name(format_, packet_start_, - &name.getConstStructReference()) < 0) { + if (hicn_interest_set_name(&pkbuf_, &name.getConstStructReference()) < 0) { throw errors::RuntimeException("Error setting interest name."); } - if (hicn_interest_get_name(format_, packet_start_, - &name_.getStructReference()) < 0) { + if (hicn_interest_get_name(&pkbuf_, &name_.getStructReference()) < 0) { throw errors::MalformedPacketException(); } } -void Interest::setLocator(const ip_address_t &ip_address) { - if (hicn_interest_set_locator(format_, packet_start_, &ip_address) < 0) { +void Interest::setLocator(const hicn_ip_address_t &ip_address) { + if (hicn_interest_set_locator(&pkbuf_, &ip_address) < 0) { throw errors::RuntimeException("Error setting interest locator."); } return; } -ip_address_t Interest::getLocator() const { - ip_address_t ip; +hicn_ip_address_t Interest::getLocator() const { + hicn_ip_address_t ip; - if (hicn_interest_get_locator(format_, packet_start_, &ip) < 0) { + if (hicn_interest_get_locator(&pkbuf_, &ip) < 0) { throw errors::RuntimeException("Error getting interest locator."); } @@ -130,7 +120,7 @@ ip_address_t Interest::getLocator() const { } void Interest::setLifetime(uint32_t lifetime) { - if (hicn_interest_set_lifetime(packet_start_, lifetime) < 0) { + if (hicn_interest_set_lifetime(&pkbuf_, lifetime) < 0) { throw errors::MalformedPacketException(); } } @@ -138,7 +128,7 @@ void Interest::setLifetime(uint32_t lifetime) { uint32_t Interest::getLifetime() const { uint32_t lifetime = 0; - if (hicn_interest_get_lifetime(packet_start_, &lifetime) < 0) { + if (hicn_interest_get_lifetime(&pkbuf_, &lifetime) < 0) { throw errors::MalformedPacketException(); } @@ -146,8 +136,7 @@ uint32_t Interest::getLifetime() const { } void Interest::resetForHash() { - if (hicn_interest_reset_for_hash( - format_, reinterpret_cast<hicn_header_t *>(packet_start_)) < 0) { + if (hicn_interest_reset_for_hash(&pkbuf_) < 0) { throw errors::RuntimeException( "Error resetting interest fields for hash computation."); } @@ -217,7 +206,7 @@ uint32_t Interest::numberOfSuffixes() { return header->n_suffixes; } -uint32_t *Interest::getRequestBitmap() { +hicn_uword *Interest::getRequestBitmap() { if (!hasManifest()) return nullptr; auto header = (interest_manifest_header_t *)(writableData() + headerSize()); diff --git a/libtransport/src/core/io_module.cc b/libtransport/src/core/io_module.cc index 0f92cc47c..0fdb735c4 100644 --- a/libtransport/src/core/io_module.cc +++ b/libtransport/src/core/io_module.cc @@ -23,7 +23,7 @@ #include <iostream> #ifdef ANDROID -#include <io_modules/hicn-light-ng/hicn_forwarder_module.h> +#include <io_modules/hicn-light/hicn_forwarder_module.h> #elif _WIN32 #include <hicn/util/windows/windows_utils.h> #endif @@ -49,7 +49,7 @@ IoModule *IoModule::load(const char *module_name) { creator = (IoModule * (*)(void)) dlsym(handle, "create_module"); if (!creator) { if ((error = dlerror()) != nullptr) { - LOG(ERROR) << error; + LOG(ERROR) << error << ": " << module_name; } return nullptr; diff --git a/libtransport/src/core/manifest_format_fixed.cc b/libtransport/src/core/manifest_format_fixed.cc index 668169642..bda666c0c 100644 --- a/libtransport/src/core/manifest_format_fixed.cc +++ b/libtransport/src/core/manifest_format_fixed.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -75,6 +75,7 @@ FixedManifestEncoder &FixedManifestEncoder::encodeImpl() { manifest_entry_meta_->nb_entries = manifest_entries_.size(); packet_->append(manifestHeaderSizeImpl()); + packet_->updateLength(); auto params = reinterpret_cast<uint8_t *>(manifest_entry_meta_ + 1); @@ -97,6 +98,7 @@ FixedManifestEncoder &FixedManifestEncoder::encodeImpl() { auto payload = reinterpret_cast<const uint8_t *>(manifest_entries_.data()); packet_->appendPayload(payload, manifestPayloadSizeImpl()); + packet_->updateLength(); if (TRANSPORT_EXPECT_FALSE(packet_->payloadSize() < manifestSizeImpl())) { throw errors::RuntimeException("Error encoding the manifest"); } diff --git a/libtransport/src/core/name.cc b/libtransport/src/core/name.cc index 960947cb9..02cc79be6 100644 --- a/libtransport/src/core/name.cc +++ b/libtransport/src/core/name.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -14,6 +14,7 @@ */ #include <core/manifest_format.h> +#include <hicn/name.h> #include <hicn/transport/core/name.h> #include <hicn/transport/errors/errors.h> #include <hicn/transport/errors/tokenizer_exception.h> @@ -124,8 +125,8 @@ std::string Name::toString() const { } uint32_t Name::getHash32(bool consider_suffix) const { - uint32_t hash; - if (hicn_name_hash(&name_, &hash, consider_suffix) < 0) { + uint32_t hash = _hicn_name_get_hash(&name_, consider_suffix); + if (hash < 0) { throw errors::RuntimeException("Error computing the hash of the name!"); } return hash; @@ -148,20 +149,19 @@ uint32_t Name::getSuffix() const { return ret; } -Name &Name::setSuffix(uint32_t seq_number) { - if (hicn_name_set_seq_number(&name_, seq_number) < 0) { - throw errors::RuntimeException( - "Impossible to set the sequence number to the name."); +Name &Name::setSuffix(hicn_name_suffix_t suffix) { + if (hicn_name_set_suffix(&name_, suffix) < 0) { + throw errors::RuntimeException("Impossible to set name suffix."); } return *this; } -ip_prefix_t Name::toIpAddress() const { - ip_prefix_t ret; +hicn_ip_prefix_t Name::toIpAddress() const { + hicn_ip_prefix_t ret; std::memset(&ret, 0, sizeof(ret)); - if (hicn_name_to_ip_prefix(&name_, &ret) < 0) { + if (hicn_name_to_hicn_ip_prefix(&name_, &ret) < 0) { throw errors::InvalidIpAddressException(); } diff --git a/libtransport/src/core/packet.cc b/libtransport/src/core/packet.cc index 0c08246af..73134ce3d 100644 --- a/libtransport/src/core/packet.cc +++ b/libtransport/src/core/packet.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -24,6 +24,7 @@ extern "C" { #ifndef _WIN32 TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat") #endif +#include <hicn/base.h> #include <hicn/error.h> } @@ -33,72 +34,78 @@ namespace core { const core::Name Packet::base_name("0::0|0"); -Packet::Packet(Format format, std::size_t additional_header_size) +Packet::Packet(Type type, Format format, std::size_t additional_header_size) : utils::MemBuf(utils::MemBuf(CREATE, 2048)), - packet_start_(reinterpret_cast<hicn_header_t *>(writableData())), - header_offset_(0), - format_(format), payload_type_(PayloadType::UNSPECIFIED) { - setFormat(format_, additional_header_size); + /* + * We define the format and the storage area of the packet buffer we + * manipulate + */ + setType(type); + setFormat(format); + setBuffer(); + initialize(additional_header_size); } Packet::Packet(CopyBufferOp, const uint8_t *buffer, std::size_t size) : utils::MemBuf(COPY_BUFFER, buffer, size), - packet_start_(reinterpret_cast<hicn_header_t *>(writableData())), - header_offset_(0), - format_(getFormatFromBuffer(data(), length())), - payload_type_(PayloadType::UNSPECIFIED) {} + payload_type_(PayloadType::UNSPECIFIED) { + setBuffer(); + analyze(); +} Packet::Packet(WrapBufferOp, uint8_t *buffer, std::size_t length, std::size_t size) : utils::MemBuf(WRAP_BUFFER, buffer, length, size), - packet_start_(reinterpret_cast<hicn_header_t *>(writableData())), - header_offset_(0), - format_(getFormatFromBuffer(this->data(), this->length())), - payload_type_(PayloadType::UNSPECIFIED) {} + payload_type_(PayloadType::UNSPECIFIED) { + setBuffer(); + analyze(); +} -Packet::Packet(CreateOp, uint8_t *buffer, std::size_t length, std::size_t size, - Format format, std::size_t additional_header_size) +Packet::Packet(CreateOp, Type type, uint8_t *buffer, std::size_t length, + std::size_t size, Format format, + std::size_t additional_header_size) : utils::MemBuf(WRAP_BUFFER, buffer, length, size), - packet_start_(reinterpret_cast<hicn_header_t *>(writableData())), - header_offset_(0), - format_(format), payload_type_(PayloadType::UNSPECIFIED) { clear(); - setFormat(format_, additional_header_size); + setType(type); + setFormat(format); + setBuffer(); + initialize(additional_header_size); } Packet::Packet(MemBuf &&buffer) : utils::MemBuf(std::move(buffer)), - packet_start_(reinterpret_cast<hicn_header_t *>(writableData())), - header_offset_(0), - format_(getFormatFromBuffer(data(), length())), - payload_type_(PayloadType::UNSPECIFIED) {} + payload_type_(PayloadType::UNSPECIFIED) { + setBuffer(); + analyze(); +} + +/* + * In the two following constructors, we inherit the pkbuf and only need to + * recompute the pointer fields, aka the buffer. + */ Packet::Packet(Packet &&other) : utils::MemBuf(std::move(other)), - packet_start_(other.packet_start_), - header_offset_(other.header_offset_), - format_(other.format_), + pkbuf_(other.pkbuf_), payload_type_(PayloadType::UNSPECIFIED) { - other.packet_start_ = nullptr; - other.format_ = HF_UNSPEC; - other.header_offset_ = 0; + hicn_packet_reset(&other.pkbuf_); } Packet::Packet(const Packet &other) : utils::MemBuf(other), - packet_start_(reinterpret_cast<hicn_header_t *>(writableData())), - header_offset_(other.header_offset_), - format_(other.format_), - payload_type_(PayloadType::UNSPECIFIED) {} + pkbuf_(other.pkbuf_), + payload_type_(PayloadType::UNSPECIFIED) { + setBuffer(); +} Packet::~Packet() {} Packet &Packet::operator=(const Packet &other) { if (this != &other) { *this = other; - packet_start_ = reinterpret_cast<hicn_header_t *>(writableData()); + setBuffer(); } return *this; @@ -109,38 +116,44 @@ std::shared_ptr<utils::MemBuf> Packet::acquireMemBufReference() { } Packet::Format Packet::getFormat() const { - // We check packet start because after a movement it will result in a nullptr - if (format_ == HF_UNSPEC && length()) { - if (hicn_packet_get_format(packet_start_, &format_) < 0) { - LOG(ERROR) << "Unexpected packet format HF_UNSPEC."; - } - } + return hicn_packet_get_format(&pkbuf_); +} - return format_; +void Packet::setFormat(Packet::Format format) { + hicn_packet_set_format(&pkbuf_, format); } -void Packet::setFormat(Packet::Format format, - std::size_t additional_header_size) { - format_ = format; - if (hicn_packet_init_header(format_, packet_start_) < 0) { +void Packet::initialize(std::size_t additional_header_size) { + if (hicn_packet_init_header(&pkbuf_, additional_header_size) < 0) { throw errors::RuntimeException("Unexpected error initializing the packet."); } - auto header_size = getHeaderSizeFromFormat(format_); + auto header_size = getHeaderSizeFromFormat(getFormat()); DCHECK(header_size <= tailroom()); append(header_size); - DCHECK(additional_header_size <= tailroom()); append(additional_header_size); +} - header_offset_ = length(); +void Packet::analyze() { + if (hicn_packet_analyze(&pkbuf_) < 0) + throw errors::MalformedPacketException(); +} + +Packet::Type Packet::getType() const { return hicn_packet_get_type(&pkbuf_); } + +void Packet::setType(Packet::Type type) { hicn_packet_set_type(&pkbuf_, type); } + +void Packet::setBuffer() { + hicn_packet_set_buffer(&pkbuf_, writableData(), + this->capacity() - this->headroom(), this->length()); } PayloadType Packet::getPayloadType() const { if (payload_type_ == PayloadType::UNSPECIFIED) { hicn_payload_type_t ret; - if (hicn_packet_get_payload_type(format_, packet_start_, &ret) < 0) { + if (hicn_packet_get_payload_type(&pkbuf_, &ret) < 0) { throw errors::RuntimeException("Impossible to retrieve payload type."); } @@ -151,8 +164,8 @@ PayloadType Packet::getPayloadType() const { } Packet &Packet::setPayloadType(PayloadType payload_type) { - if (hicn_packet_set_payload_type(format_, packet_start_, - hicn_payload_type_t(payload_type)) < 0) { + if (hicn_packet_set_payload_type(&pkbuf_, hicn_payload_type_t(payload_type)) < + 0) { throw errors::RuntimeException("Error setting payload type of the packet."); } @@ -184,23 +197,15 @@ Packet &Packet::appendPayload(const uint8_t *buffer, std::size_t length) { } std::size_t Packet::headerSize() const { - if (header_offset_ == 0 && length()) { - const_cast<Packet *>(this)->header_offset_ = getHeaderSizeFromBuffer( - format_, reinterpret_cast<uint8_t *>(packet_start_)); - } - - return header_offset_; + std::size_t len; + hicn_packet_get_header_len(&pkbuf_, &len); + return len; } std::size_t Packet::payloadSize() const { - std::size_t ret = 0; - - if (length()) { - ret = getPayloadSizeFromBuffer(format_, - reinterpret_cast<uint8_t *>(packet_start_)); - } - - return ret; + std::size_t len; + hicn_packet_get_payload_len(&pkbuf_, &len); + return len; } auth::CryptoHash Packet::computeDigest(auth::CryptoHashType algorithm) const { @@ -208,21 +213,22 @@ auth::CryptoHash Packet::computeDigest(auth::CryptoHashType algorithm) const { hash.setType(algorithm); // Copy IP+TCP/ICMP header before zeroing them - hicn_header_t header_copy; - hicn_packet_copy_header(format_, packet_start_, &header_copy, false); + u8 header_copy[HICN_HDRLEN_MAX]; + size_t header_len; + hicn_packet_save_header(&pkbuf_, header_copy, &header_len, + /* copy_ah */ false); const_cast<Packet *>(this)->resetForHash(); hash.computeDigest(this); - hicn_packet_copy_header(format_, &header_copy, packet_start_, false); + hicn_packet_load_header(&pkbuf_, header_copy, header_len); return hash; } void Packet::reset() { clear(); - packet_start_ = reinterpret_cast<hicn_header_t *>(writableData()); - header_offset_ = 0; - format_ = HF_UNSPEC; + hicn_packet_reset(&pkbuf_); + setBuffer(); payload_type_ = PayloadType::UNSPECIFIED; name_.clear(); @@ -231,7 +237,9 @@ void Packet::reset() { } } -bool Packet::isInterest() { return Packet::isInterest(data(), format_); } +bool Packet::isInterest() { + return hicn_packet_get_type(&pkbuf_) == HICN_PACKET_TYPE_INTEREST; +} Packet &Packet::updateLength(std::size_t length) { std::size_t total_length = length; @@ -242,11 +250,14 @@ Packet &Packet::updateLength(std::size_t length) { current = current->next(); } while (current != this); + if (hicn_packet_set_len(&pkbuf_, total_length) < 0) { + throw errors::RuntimeException("Error setting the packet length."); + } + total_length -= headerSize(); - if (hicn_packet_set_payload_length(format_, packet_start_, total_length) < - 0) { - throw errors::RuntimeException("Error setting the packet payload."); + if (hicn_packet_set_payload_length(&pkbuf_, total_length) < 0) { + throw errors::RuntimeException("Error setting the packet payload length."); } return *this; @@ -265,168 +276,45 @@ void Packet::dump() const { } void Packet::setChecksum() { - if (_is_tcp(format_)) { - uint16_t partial_csum = - csum(data() + HICN_V6_TCP_HDRLEN, length() - HICN_V6_TCP_HDRLEN, 0); - - for (utils::MemBuf *current = next(); current != this; - current = current->next()) { - partial_csum = csum(current->data(), current->length(), ~partial_csum); - } - - if (hicn_packet_compute_header_checksum(format_, packet_start_, - partial_csum) < 0) { - throw errors::MalformedPacketException(); - } - } -} - -bool Packet::checkIntegrity() const { - if (_is_tcp(format_)) { - uint16_t partial_csum = - csum(data() + HICN_V6_TCP_HDRLEN, length() - HICN_V6_TCP_HDRLEN, 0); - - for (const utils::MemBuf *current = next(); current != this; - current = current->next()) { - partial_csum = csum(current->data(), current->length(), ~partial_csum); - } - - if (hicn_packet_check_integrity_no_payload(format_, packet_start_, - partial_csum) < 0) { - return false; - } - } - - return true; -} - -Packet &Packet::setSyn() { - if (hicn_packet_set_syn(format_, packet_start_) < 0) { - throw errors::RuntimeException("Error setting syn bit in the packet."); - } - - return *this; -} - -Packet &Packet::resetSyn() { - if (hicn_packet_reset_syn(format_, packet_start_) < 0) { - throw errors::RuntimeException("Error resetting syn bit in the packet."); - } - - return *this; -} - -bool Packet::testSyn() const { - bool res = false; - if (hicn_packet_test_syn(format_, packet_start_, &res) < 0) { - throw errors::RuntimeException("Error testing syn bit in the packet."); - } - - return res; -} - -Packet &Packet::setAck() { - if (hicn_packet_set_ack(format_, packet_start_) < 0) { - throw errors::RuntimeException("Error setting ack bit in the packet."); - } - - return *this; -} - -Packet &Packet::resetAck() { - if (hicn_packet_reset_ack(format_, packet_start_) < 0) { - throw errors::RuntimeException("Error resetting ack bit in the packet."); - } - - return *this; -} - -bool Packet::testAck() const { - bool res = false; - if (hicn_packet_test_ack(format_, packet_start_, &res) < 0) { - throw errors::RuntimeException("Error testing ack bit in the packet."); - } - - return res; -} - -Packet &Packet::setRst() { - if (hicn_packet_set_rst(format_, packet_start_) < 0) { - throw errors::RuntimeException("Error setting rst bit in the packet."); - } + size_t header_len = 0; + if (hicn_packet_get_header_len(&pkbuf_, &header_len) < 0) + throw errors::RuntimeException( + "Error setting getting packet header length."); - return *this; -} + uint16_t partial_csum = csum(data() + header_len, length() - header_len, 0); -Packet &Packet::resetRst() { - if (hicn_packet_reset_rst(format_, packet_start_) < 0) { - throw errors::RuntimeException("Error resetting rst bit in the packet."); + for (utils::MemBuf *current = next(); current != this; + current = current->next()) { + partial_csum = csum(current->data(), current->length(), ~partial_csum); } - return *this; -} - -bool Packet::testRst() const { - bool res = false; - if (hicn_packet_test_rst(format_, packet_start_, &res) < 0) { - throw errors::RuntimeException("Error testing rst bit in the packet."); + if (hicn_packet_compute_header_checksum(&pkbuf_, partial_csum) < 0) { + throw errors::MalformedPacketException(); } - - return res; } -Packet &Packet::setFin() { - if (hicn_packet_set_fin(format_, packet_start_) < 0) { - throw errors::RuntimeException("Error setting fin bit in the packet."); - } +bool Packet::checkIntegrity() const { + size_t header_len = 0; + if (hicn_packet_get_header_len(&pkbuf_, &header_len) < 0) + throw errors::RuntimeException( + "Error setting getting packet header length."); - return *this; -} + uint16_t partial_csum = csum(data() + header_len, length() - header_len, 0); -Packet &Packet::resetFin() { - if (hicn_packet_reset_fin(format_, packet_start_) < 0) { - throw errors::RuntimeException("Error resetting fin bit in the packet."); + for (const utils::MemBuf *current = next(); current != this; + current = current->next()) { + partial_csum = csum(current->data(), current->length(), ~partial_csum); } - return *this; -} - -bool Packet::testFin() const { - bool res = false; - if (hicn_packet_test_fin(format_, packet_start_, &res) < 0) { - throw errors::RuntimeException("Error testing fin bit in the packet."); + if (hicn_packet_check_integrity_no_payload(&pkbuf_, partial_csum) < 0) { + return false; } - return res; -} - -Packet &Packet::resetFlags() { - resetSyn(); - resetAck(); - resetRst(); - resetFin(); - return *this; -} - -std::string Packet::printFlags() const { - std::string flags; - if (testSyn()) { - flags += "S"; - } - if (testAck()) { - flags += "A"; - } - if (testRst()) { - flags += "R"; - } - if (testFin()) { - flags += "F"; - } - return flags; + return true; } Packet &Packet::setSrcPort(uint16_t srcPort) { - if (hicn_packet_set_src_port(format_, packet_start_, srcPort) < 0) { + if (hicn_packet_set_src_port(&pkbuf_, srcPort) < 0) { throw errors::RuntimeException("Error setting source port in the packet."); } @@ -434,7 +322,7 @@ Packet &Packet::setSrcPort(uint16_t srcPort) { } Packet &Packet::setDstPort(uint16_t dstPort) { - if (hicn_packet_set_dst_port(format_, packet_start_, dstPort) < 0) { + if (hicn_packet_set_dst_port(&pkbuf_, dstPort) < 0) { throw errors::RuntimeException( "Error setting destination port in the packet."); } @@ -445,7 +333,7 @@ Packet &Packet::setDstPort(uint16_t dstPort) { uint16_t Packet::getSrcPort() const { uint16_t port = 0; - if (hicn_packet_get_src_port(format_, packet_start_, &port) < 0) { + if (hicn_packet_get_src_port(&pkbuf_, &port) < 0) { throw errors::RuntimeException("Error reading source port in the packet."); } @@ -455,7 +343,7 @@ uint16_t Packet::getSrcPort() const { uint16_t Packet::getDstPort() const { uint16_t port = 0; - if (hicn_packet_get_dst_port(format_, packet_start_, &port) < 0) { + if (hicn_packet_get_dst_port(&pkbuf_, &port) < 0) { throw errors::RuntimeException( "Error reading destination port in the packet."); } @@ -464,7 +352,7 @@ uint16_t Packet::getDstPort() const { } Packet &Packet::setTTL(uint8_t hops) { - if (hicn_packet_set_hoplimit(packet_start_, hops) < 0) { + if (hicn_packet_set_ttl(&pkbuf_, hops) < 0) { throw errors::RuntimeException("Error setting TTL."); } @@ -473,14 +361,14 @@ Packet &Packet::setTTL(uint8_t hops) { uint8_t Packet::getTTL() const { uint8_t hops = 0; - if (hicn_packet_get_hoplimit(packet_start_, &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(format_); } +bool Packet::hasAH() const { return _is_ah(hicn_packet_get_format(&pkbuf_)); } utils::MemBuf::Ptr Packet::getSignature() const { if (!hasAH()) { @@ -488,7 +376,7 @@ utils::MemBuf::Ptr Packet::getSignature() const { } uint8_t *signature; - int ret = hicn_packet_get_signature(format_, packet_start_, &signature); + int ret = hicn_packet_get_signature(&pkbuf_, &signature); if (ret < 0) { throw errors::RuntimeException("Error getting signature."); @@ -507,7 +395,7 @@ std::size_t Packet::getSignatureFieldSize() const { } size_t field_size; - int ret = hicn_packet_get_signature_size(format_, packet_start_, &field_size); + int ret = hicn_packet_get_signature_size(&pkbuf_, &field_size); if (ret < 0) { throw errors::RuntimeException("Error reading signature field size"); } @@ -520,7 +408,7 @@ std::size_t Packet::getSignatureSize() const { } size_t padding; - int ret = hicn_packet_get_signature_padding(format_, packet_start_, &padding); + int ret = hicn_packet_get_signature_padding(&pkbuf_, &padding); if (ret < 0) { throw errors::RuntimeException("Error reading signature padding"); } @@ -539,8 +427,7 @@ uint64_t Packet::getSignatureTimestamp() const { } uint64_t timestamp; - int ret = - hicn_packet_get_signature_timestamp(format_, packet_start_, ×tamp); + int ret = hicn_packet_get_signature_timestamp(&pkbuf_, ×tamp); if (ret < 0) { throw errors::RuntimeException("Error getting the signature timestamp."); } @@ -553,8 +440,7 @@ auth::KeyId Packet::getKeyId() const { } auth::KeyId key_id; - int ret = hicn_packet_get_key_id(format_, packet_start_, &key_id.first, - &key_id.second); + int ret = hicn_packet_get_key_id(&pkbuf_, &key_id.first, &key_id.second); if (ret < 0) { throw errors::RuntimeException("Error getting the validation algorithm."); } @@ -567,8 +453,7 @@ auth::CryptoSuite Packet::getValidationAlgorithm() const { } uint8_t return_value; - int ret = hicn_packet_get_validation_algorithm(format_, packet_start_, - &return_value); + int ret = hicn_packet_get_validation_algorithm(&pkbuf_, &return_value); if (ret < 0) { throw errors::RuntimeException("Error getting the validation algorithm."); } @@ -581,7 +466,7 @@ void Packet::setSignature(const utils::MemBuf::Ptr &signature) { } uint8_t *signature_field; - int ret = hicn_packet_get_signature(format_, packet_start_, &signature_field); + int ret = hicn_packet_get_signature(&pkbuf_, &signature_field); if (ret < 0) { throw errors::RuntimeException("Error getting signature."); } @@ -593,7 +478,7 @@ void Packet::setSignatureFieldSize(std::size_t size) { throw errors::RuntimeException("Packet without Authentication Header."); } - int ret = hicn_packet_set_signature_size(format_, packet_start_, size); + int ret = hicn_packet_set_signature_size(&pkbuf_, size); if (ret < 0) { throw errors::RuntimeException("Error setting signature size."); } @@ -609,7 +494,7 @@ void Packet::setSignatureSize(std::size_t size) { throw errors::RuntimeException("Error setting signature padding."); } - int ret = hicn_packet_set_signature_padding(format_, packet_start_, padding); + int ret = hicn_packet_set_signature_padding(&pkbuf_, padding); if (ret < 0) { throw errors::RuntimeException("Error setting signature padding."); } @@ -620,8 +505,7 @@ void Packet::setSignatureTimestamp(const uint64_t ×tamp) { throw errors::RuntimeException("Packet without Authentication Header."); } - int ret = - hicn_packet_set_signature_timestamp(format_, packet_start_, timestamp); + int ret = hicn_packet_set_signature_timestamp(&pkbuf_, timestamp); if (ret < 0) { throw errors::RuntimeException("Error setting the signature timestamp."); } @@ -632,7 +516,7 @@ void Packet::setKeyId(const auth::KeyId &key_id) { throw errors::RuntimeException("Packet without Authentication Header."); } - int ret = hicn_packet_set_key_id(format_, packet_start_, key_id.first); + int ret = hicn_packet_set_key_id(&pkbuf_, key_id.first, key_id.second); if (ret < 0) { throw errors::RuntimeException("Error setting the key id."); } @@ -644,7 +528,7 @@ void Packet::setValidationAlgorithm( throw errors::RuntimeException("Packet without Authentication Header."); } - int ret = hicn_packet_set_validation_algorithm(format_, packet_start_, + int ret = hicn_packet_set_validation_algorithm(&pkbuf_, uint8_t(validation_algorithm)); if (ret < 0) { throw errors::RuntimeException("Error setting the validation algorithm."); @@ -656,10 +540,13 @@ Packet::Format Packet::toAHFormat(const Format &format) { } Packet::Format Packet::getFormatFromBuffer(const uint8_t *buffer, - std::size_t /* length */) { - Packet::Format format = HF_UNSPEC; - hicn_packet_get_format((const hicn_header_t *)buffer, &format); - return format; + std::size_t length) { + hicn_packet_buffer_t pkbuf; + /* un-const to be able to use pkbuf API */ + hicn_packet_set_buffer(&pkbuf, (uint8_t *)buffer, length, length); + if (hicn_packet_analyze(&pkbuf) < 0) throw errors::MalformedPacketException(); + + return hicn_packet_get_format(&pkbuf); } std::size_t Packet::getHeaderSizeFromFormat(Format format, @@ -670,44 +557,34 @@ std::size_t Packet::getHeaderSizeFromFormat(Format format, return is_ah * (header_length + signature_size) + (!is_ah) * header_length; } -std::size_t Packet::getHeaderSizeFromBuffer(Format format, - const uint8_t *buffer) { +std::size_t Packet::getHeaderSizeFromBuffer(const uint8_t *buffer, + std::size_t length) { size_t header_length; - if (hicn_packet_get_header_length(format, (hicn_header_t *)buffer, - &header_length) < 0) { - throw errors::MalformedPacketException(); - } + hicn_packet_buffer_t pkbuf; + /* un-const to be able to use pkbuf API */ + hicn_packet_set_buffer(&pkbuf, (uint8_t *)buffer, length, length); + if (hicn_packet_analyze(&pkbuf) < 0) throw errors::MalformedPacketException(); + + int rc = hicn_packet_get_header_len(&pkbuf, &header_length); + if (TRANSPORT_EXPECT_FALSE(rc < 0)) throw errors::MalformedPacketException(); return header_length; } -std::size_t Packet::getPayloadSizeFromBuffer(Format format, - const uint8_t *buffer) { +std::size_t Packet::getPayloadSizeFromBuffer(const uint8_t *buffer, + std::size_t length) { std::size_t payload_length; - if (TRANSPORT_EXPECT_FALSE( - hicn_packet_get_payload_length(format, (hicn_header_t *)buffer, - &payload_length) < 0)) { - throw errors::MalformedPacketException(); - } - return payload_length; -} + hicn_packet_buffer_t pkbuf; + /* un-const to be able to use pkbuf API */ + hicn_packet_set_buffer(&pkbuf, (uint8_t *)buffer, length, length); + if (hicn_packet_analyze(&pkbuf) < 0) throw errors::MalformedPacketException(); -bool Packet::isInterest(const uint8_t *buffer, Format format) { - int is_interest = 0; - - if (TRANSPORT_EXPECT_FALSE(format == Format::HF_UNSPEC)) { - format = getFormatFromBuffer(buffer, /* Unused length */ 128); - } + int rc = hicn_packet_get_payload_len(&pkbuf, &payload_length); + if (TRANSPORT_EXPECT_FALSE(rc < 0)) throw errors::MalformedPacketException(); - if (TRANSPORT_EXPECT_FALSE( - hicn_packet_is_interest(format, (const hicn_header_t *)buffer, - &is_interest) < 0)) { - throw errors::RuntimeException("Error reading ece flag from packet"); - } - - return is_interest; + return payload_length; } void Packet::dump(uint8_t *buffer, std::size_t length) { @@ -723,6 +600,14 @@ void Packet::prependPayload(const uint8_t **buffer, std::size_t *size) { *buffer += to_copy; } +void Packet::saveHeader(u8 *header, size_t *header_len) { + hicn_packet_save_header(&pkbuf_, header, header_len, /* copy_ah */ false); +} + +void Packet::loadHeader(u8 *header, size_t header_len) { + hicn_packet_load_header(&pkbuf_, header, header_len); +} + } // end namespace core } // end namespace transport diff --git a/libtransport/src/core/portal.cc b/libtransport/src/core/portal.cc index c06969f19..72b6a6f37 100644 --- a/libtransport/src/core/portal.cc +++ b/libtransport/src/core/portal.cc @@ -30,11 +30,11 @@ namespace core { #ifdef ANDROID static const constexpr char default_module[] = ""; #elif defined(MACINTOSH) -static const constexpr char default_module[] = "hicnlightng_module.dylib"; +static const constexpr char default_module[] = "hicnlight_module.dylib"; #elif defined(LINUX) -static const constexpr char default_module[] = "hicnlightng_module.so"; +static const constexpr char default_module[] = "hicnlight_module.so"; #elif defined(WINDOWS) -static const constexpr char default_module[] = "hicnlightng_module.lib"; +static const constexpr char default_module[] = "hicnlight_module.lib"; #endif IoModuleConfiguration Portal::conf_; @@ -149,4 +149,4 @@ void Portal::parseIoModuleConfiguration(const libconfig::Setting& io_config, } } // namespace core -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/src/core/portal.h b/libtransport/src/core/portal.h index 6f3a48e83..f2380347b 100644 --- a/libtransport/src/core/portal.h +++ b/libtransport/src/core/portal.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -32,10 +32,6 @@ #include <hicn/transport/utils/event_thread.h> #include <hicn/transport/utils/fixed_block_allocator.h> -extern "C" { -#include <hicn/header.h> -} - #include <future> #include <memory> #include <queue> @@ -575,24 +571,31 @@ class Portal : public ::utils::NonCopyable, return; } - auto format = Packet::getFormatFromBuffer(buffer.data(), buffer.length()); - if (TRANSPORT_EXPECT_TRUE(_is_cmpr(format) || _is_tcp(format))) { - // The buffer is a base class for an interest or a content object - Packet &packet_buffer = static_cast<Packet &>(buffer); - if (is_consumer_ && !packet_buffer.isInterest()) { - processContentObject(static_cast<ContentObject &>(packet_buffer)); - } else if (!is_consumer_ && packet_buffer.isInterest()) { - processInterest(static_cast<Interest &>(packet_buffer)); - } else { - auto packet_type = - packet_buffer.isInterest() ? "Interest" : "ContentObject"; - auto socket_type = is_consumer_ ? "consumer " : "producer "; - LOG(ERROR) << "Received a " << packet_type << " packet with name " - << packet_buffer.getName() << " in a " << socket_type - << " transport. Ignoring it."; - } - } else { - LOG(ERROR) << "Received not supported packet. Ignoring it."; + // The buffer is a base class for an interest or a content object + Packet &packet_buffer = static_cast<Packet &>(buffer); + + switch (packet_buffer.getType()) { + case HICN_PACKET_TYPE_INTEREST: + if (!is_consumer_) { + processInterest(static_cast<Interest &>(packet_buffer)); + } else { + LOG(ERROR) << "Received an Interest packet with name " + << packet_buffer.getName() + << " in a consumer transport. Ignoring it."; + } + break; + case HICN_PACKET_TYPE_DATA: + if (is_consumer_) { + processContentObject(static_cast<ContentObject &>(packet_buffer)); + } else { + LOG(ERROR) << "Received a Data packet with name " + << packet_buffer.getName() + << " in a producer transport. Ignoring it."; + } + break; + default: + LOG(ERROR) << "Received not supported packet. Ignoring it."; + break; } } } diff --git a/libtransport/src/core/prefix.cc b/libtransport/src/core/prefix.cc index 00748148f..d54dc909a 100644 --- a/libtransport/src/core/prefix.cc +++ b/libtransport/src/core/prefix.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -37,7 +37,7 @@ namespace transport { namespace core { -Prefix::Prefix() { std::memset(&ip_prefix_, 0, sizeof(ip_prefix_t)); } +Prefix::Prefix() { std::memset(&hicn_ip_prefix_, 0, sizeof(hicn_ip_prefix_t)); } Prefix::Prefix(const std::string &prefix) { utils::StringTokenizer st(prefix, "/"); @@ -66,9 +66,9 @@ Prefix::Prefix(const core::Name &content_name, uint16_t prefix_length) { throw errors::InvalidIpAddressException(); } - ip_prefix_ = content_name.toIpAddress(); - ip_prefix_.len = (u8)prefix_length; - ip_prefix_.family = family; + hicn_ip_prefix_ = content_name.toIpAddress(); + hicn_ip_prefix_.len = (u8)prefix_length; + hicn_ip_prefix_.family = family; } void Prefix::buildPrefix(const std::string &prefix, uint16_t prefix_length, @@ -77,15 +77,17 @@ void Prefix::buildPrefix(const std::string &prefix, uint16_t prefix_length, throw errors::InvalidIpAddressException(); } - std::memset(&ip_prefix_, 0, sizeof(ip_prefix_t)); + std::memset(&hicn_ip_prefix_, 0, sizeof(hicn_ip_prefix_t)); int ret; switch (family) { case AF_INET: - ret = inet_pton(AF_INET, prefix.c_str(), ip_prefix_.address.v4.buffer); + ret = + inet_pton(AF_INET, prefix.c_str(), hicn_ip_prefix_.address.v4.buffer); break; case AF_INET6: - ret = inet_pton(AF_INET6, prefix.c_str(), ip_prefix_.address.v6.buffer); + ret = inet_pton(AF_INET6, prefix.c_str(), + hicn_ip_prefix_.address.v6.buffer); break; default: throw errors::InvalidIpAddressException(); @@ -95,22 +97,22 @@ void Prefix::buildPrefix(const std::string &prefix, uint16_t prefix_length, throw errors::InvalidIpAddressException(); } - ip_prefix_.len = (u8)prefix_length; - ip_prefix_.family = family; + hicn_ip_prefix_.len = (u8)prefix_length; + hicn_ip_prefix_.family = family; } bool Prefix::operator<(const Prefix &other) const { - return ip_prefix_cmp(&ip_prefix_, &other.ip_prefix_) < 0; + return hicn_ip_prefix_cmp(&hicn_ip_prefix_, &other.hicn_ip_prefix_) < 0; } bool Prefix::operator==(const Prefix &other) const { - return ip_prefix_cmp(&ip_prefix_, &other.ip_prefix_) == 0; + return hicn_ip_prefix_cmp(&hicn_ip_prefix_, &other.hicn_ip_prefix_) == 0; } std::unique_ptr<Sockaddr> Prefix::toSockaddr() const { Sockaddr *ret = nullptr; - switch (ip_prefix_.family) { + switch (hicn_ip_prefix_.family) { case AF_INET6: ret = (Sockaddr *)new Sockaddr6; break; @@ -121,34 +123,37 @@ std::unique_ptr<Sockaddr> Prefix::toSockaddr() const { throw errors::InvalidIpAddressException(); } - if (ip_prefix_to_sockaddr(&ip_prefix_, ret) < 0) { + if (hicn_ip_prefix_to_sockaddr(&hicn_ip_prefix_, ret) < 0) { throw errors::InvalidIpAddressException(); } return std::unique_ptr<Sockaddr>(ret); } -uint16_t Prefix::getPrefixLength() const { return ip_prefix_.len; } +uint16_t Prefix::getPrefixLength() const { return hicn_ip_prefix_.len; } Prefix &Prefix::setPrefixLength(uint16_t prefix_length) { - if (!checkPrefixLengthAndAddressFamily(prefix_length, ip_prefix_.family)) { + if (!checkPrefixLengthAndAddressFamily(prefix_length, + hicn_ip_prefix_.family)) { throw errors::InvalidIpAddressException(); } - ip_prefix_.len = (u8)prefix_length; + hicn_ip_prefix_.len = (u8)prefix_length; return *this; } -int Prefix::getAddressFamily() const { return ip_prefix_.family; } +int Prefix::getAddressFamily() const { return hicn_ip_prefix_.family; } std::string Prefix::getNetwork() const { - if (!checkPrefixLengthAndAddressFamily(ip_prefix_.len, ip_prefix_.family)) { + if (!checkPrefixLengthAndAddressFamily(hicn_ip_prefix_.len, + hicn_ip_prefix_.family)) { throw errors::InvalidIpAddressException(); } char buffer[INET6_ADDRSTRLEN]; - if (ip_prefix_ntop_short(&ip_prefix_, buffer, INET6_ADDRSTRLEN) < 0) { + if (hicn_ip_prefix_ntop_short(&hicn_ip_prefix_, buffer, INET6_ADDRSTRLEN) < + 0) { throw errors::RuntimeException( "Impossible to retrieve network from ip address."); } @@ -156,13 +161,13 @@ std::string Prefix::getNetwork() const { return buffer; } -bool Prefix::contains(const ip_address_t &content_name) const { +bool Prefix::contains(const hicn_ip_address_t &content_name) const { uint64_t mask[2] = {0, 0}; auto content_name_copy = content_name; - auto network_copy = ip_prefix_.address; + auto network_copy = hicn_ip_prefix_.address; auto prefix_length = getPrefixLength(); - if (ip_prefix_.family == AF_INET) { + if (hicn_ip_prefix_.family == AF_INET) { prefix_length += 3 * IPV4_ADDR_LEN_BITS; } @@ -186,8 +191,7 @@ bool Prefix::contains(const ip_address_t &content_name) const { network_copy.v6.as_u64[0] &= mask[0]; network_copy.v6.as_u64[1] &= mask[1]; - return ip_address_cmp(&network_copy, &content_name_copy, ip_prefix_.family) == - 0; + return hicn_ip_address_cmp(&network_copy, &content_name_copy) == 0; } bool Prefix::contains(const core::Name &content_name) const { @@ -200,23 +204,25 @@ bool Prefix::contains(const core::Name &content_name) const { */ Name Prefix::getName(const core::Name &mask, const core::Name &components, const core::Name &content_name) const { - if (ip_prefix_.family != mask.getAddressFamily() || - ip_prefix_.family != components.getAddressFamily() || - ip_prefix_.family != content_name.getAddressFamily()) + if (hicn_ip_prefix_.family != mask.getAddressFamily() || + hicn_ip_prefix_.family != components.getAddressFamily() || + hicn_ip_prefix_.family != content_name.getAddressFamily()) throw errors::RuntimeException( "Prefix, mask, components and content name are not of the same" "address family"); - ip_address_t mask_ip = mask.toIpAddress().address; - ip_address_t component_ip = components.toIpAddress().address; - ip_address_t name_ip = content_name.toIpAddress().address; - const u8 *mask_ip_buffer = ip_address_get_buffer(&mask_ip, ip_prefix_.family); + hicn_ip_address_t mask_ip = mask.toIpAddress().address; + hicn_ip_address_t component_ip = components.toIpAddress().address; + hicn_ip_address_t name_ip = content_name.toIpAddress().address; + const u8 *mask_ip_buffer = + hicn_ip_address_get_buffer(&mask_ip, hicn_ip_prefix_.family); const u8 *component_ip_buffer = - ip_address_get_buffer(&component_ip, ip_prefix_.family); - u8 *name_ip_buffer = - const_cast<u8 *>(ip_address_get_buffer(&name_ip, ip_prefix_.family)); + hicn_ip_address_get_buffer(&component_ip, hicn_ip_prefix_.family); + u8 *name_ip_buffer = const_cast<u8 *>( + hicn_ip_address_get_buffer(&name_ip, hicn_ip_prefix_.family)); - int addr_len = ip_prefix_.family == AF_INET6 ? IPV6_ADDR_LEN : IPV4_ADDR_LEN; + int addr_len = + hicn_ip_prefix_.family == AF_INET6 ? IPV6_ADDR_LEN : IPV4_ADDR_LEN; for (int i = 0; i < addr_len; i++) { if (mask_ip_buffer[i]) { @@ -224,39 +230,40 @@ Name Prefix::getName(const core::Name &mask, const core::Name &components, } } - return Name(ip_prefix_.family, (uint8_t *)&name_ip); + return Name(hicn_ip_prefix_.family, (uint8_t *)&name_ip); } /* * Map a name in a different name prefix to this name prefix */ Name Prefix::mapName(const core::Name &content_name) const { - if (ip_prefix_.family != content_name.getAddressFamily()) + if (hicn_ip_prefix_.family != content_name.getAddressFamily()) throw errors::RuntimeException( "Prefix content name are not of the same address " "family"); - ip_address_t name_ip = content_name.toIpAddress().address; - const u8 *ip_prefix_buffer = - ip_address_get_buffer(&(ip_prefix_.address), ip_prefix_.family); - u8 *name_ip_buffer = - const_cast<u8 *>(ip_address_get_buffer(&name_ip, ip_prefix_.family)); - - memcpy(name_ip_buffer, ip_prefix_buffer, ip_prefix_.len / 8); - - if (ip_prefix_.len != (ip_prefix_.family == AF_INET6 ? IPV6_ADDR_LEN_BITS - : IPV4_ADDR_LEN_BITS)) { - uint8_t mask = 0xFF >> (ip_prefix_.len % 8); - name_ip_buffer[ip_prefix_.len / 8 + 1] = - (name_ip_buffer[ip_prefix_.len / 8 + 1] & mask) | - (ip_prefix_buffer[ip_prefix_.len / 8 + 1] & ~mask); + hicn_ip_address_t name_ip = content_name.toIpAddress().address; + const u8 *hicn_ip_prefix_buffer = hicn_ip_address_get_buffer( + &(hicn_ip_prefix_.address), hicn_ip_prefix_.family); + u8 *name_ip_buffer = const_cast<u8 *>( + hicn_ip_address_get_buffer(&name_ip, hicn_ip_prefix_.family)); + + memcpy(name_ip_buffer, hicn_ip_prefix_buffer, hicn_ip_prefix_.len / 8); + + if (hicn_ip_prefix_.len != (hicn_ip_prefix_.family == AF_INET6 + ? IPV6_ADDR_LEN_BITS + : IPV4_ADDR_LEN_BITS)) { + uint8_t mask = 0xFF >> (hicn_ip_prefix_.len % 8); + name_ip_buffer[hicn_ip_prefix_.len / 8 + 1] = + (name_ip_buffer[hicn_ip_prefix_.len / 8 + 1] & mask) | + (hicn_ip_prefix_buffer[hicn_ip_prefix_.len / 8 + 1] & ~mask); } - return Name(ip_prefix_.family, (uint8_t *)&name_ip); + return Name(hicn_ip_prefix_.family, (uint8_t *)&name_ip); } Prefix &Prefix::setNetwork(const std::string &network) { - if (!ip_address_pton(network.c_str(), &ip_prefix_.address)) { + if (!hicn_ip_address_pton(network.c_str(), &hicn_ip_prefix_.address)) { throw errors::RuntimeException("The network name is not valid."); } @@ -288,7 +295,7 @@ Name Prefix::makeNameWithIndex(std::uint64_t index) const { } std::memcpy(ret.getStructReference().prefix.v6.as_u8, - ip_prefix_.address.v6.as_u8, sizeof(ip_address_t)); + hicn_ip_prefix_.address.v6.as_u8, sizeof(hicn_ip_address_t)); // Convert index in network byte order index = portability::host_to_net(index); @@ -334,7 +341,9 @@ bool Prefix::checkPrefixLengthAndAddressFamily(uint16_t prefix_length, return true; } -const ip_prefix_t &Prefix::toIpPrefixStruct() const { return ip_prefix_; } +const hicn_ip_prefix_t &Prefix::toIpPrefixStruct() const { + return hicn_ip_prefix_; +} } // namespace core diff --git a/libtransport/src/core/udp_connector.cc b/libtransport/src/core/udp_connector.cc index 5d8e76bb1..7d059dd9d 100644 --- a/libtransport/src/core/udp_connector.cc +++ b/libtransport/src/core/udp_connector.cc @@ -105,25 +105,23 @@ void UdpTunnelConnector::doSendPacket( current = current->next(); } while (current != packet); - socket_->async_send_to( - std::move(array), remote_endpoint_send_, - [this, self](const std::error_code &ec, std::size_t length) { - if (TRANSPORT_EXPECT_TRUE(!ec)) { - sent_callback_(this, make_error_code(core_error::success)); - } else if (ec.value() == - static_cast<int>(std::errc::operation_canceled)) { - // The connection has been closed by the application. - return; - } else { - sendFailed(); - sent_callback_(this, ec); - } + socket_->async_send(std::move(array), [this, self](const std::error_code &ec, + std::size_t length) { + if (TRANSPORT_EXPECT_TRUE(!ec)) { + sent_callback_(this, make_error_code(core_error::success)); + } else if (ec.value() == static_cast<int>(std::errc::operation_canceled)) { + // The connection has been closed by the application. + return; + } else { + sendFailed(); + sent_callback_(this, ec); + } - output_buffer_.pop_front(); - if (!output_buffer_.empty()) { - doSendPacket(self); - } - }); + output_buffer_.pop_front(); + if (!output_buffer_.empty()) { + doSendPacket(self); + } + }); #endif } diff --git a/libtransport/src/implementation/socket.cc b/libtransport/src/implementation/socket.cc index b80fbb58c..8e9760a5d 100644 --- a/libtransport/src/implementation/socket.cc +++ b/libtransport/src/implementation/socket.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -28,7 +28,7 @@ Socket::Socket(std::shared_ptr<core::Portal> &&portal) verifier_(std::make_shared<auth::VoidVerifier>()) {} int Socket::setSocketOption(int socket_option_key, - hicn_format_t packet_format) { + hicn_packet_format_t packet_format) { switch (socket_option_key) { case interface::GeneralTransportOptions::PACKET_FORMAT: packet_format_ = packet_format; @@ -41,7 +41,7 @@ int Socket::setSocketOption(int socket_option_key, } int Socket::getSocketOption(int socket_option_key, - hicn_format_t &packet_format) { + hicn_packet_format_t &packet_format) { switch (socket_option_key) { case interface::GeneralTransportOptions::PACKET_FORMAT: packet_format = packet_format_; @@ -54,4 +54,4 @@ int Socket::getSocketOption(int socket_option_key, } } // namespace implementation -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/src/implementation/socket.h b/libtransport/src/implementation/socket.h index 3eb93cff6..55132eb75 100644 --- a/libtransport/src/implementation/socket.h +++ b/libtransport/src/implementation/socket.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -44,8 +44,10 @@ class Socket { return portal_->getThread().getIoService(); } - int setSocketOption(int socket_option_key, hicn_format_t packet_format); - int getSocketOption(int socket_option_key, hicn_format_t &packet_format); + int setSocketOption(int socket_option_key, + hicn_packet_format_t packet_format); + int getSocketOption(int socket_option_key, + hicn_packet_format_t &packet_format); int getSocketOption(int socket_option_key, std::shared_ptr<core::Portal> &socket_option_value) { @@ -69,7 +71,7 @@ class Socket { protected: std::shared_ptr<core::Portal> portal_; bool is_async_; - hicn_format_t packet_format_; + hicn_packet_format_t packet_format_; std::shared_ptr<auth::Signer> signer_; std::shared_ptr<auth::Verifier> verifier_; }; diff --git a/libtransport/src/io_modules/CMakeLists.txt b/libtransport/src/io_modules/CMakeLists.txt index f1a27d3cb..fcf69cd42 100644 --- a/libtransport/src/io_modules/CMakeLists.txt +++ b/libtransport/src/io_modules/CMakeLists.txt @@ -17,11 +17,11 @@ ############################################################## if (${CMAKE_SYSTEM_NAME} MATCHES Android OR ${CMAKE_SYSTEM_NAME} MATCHES iOS) list(APPEND SOURCE_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/hicn-light-ng/hicn_forwarder_module.cc + ${CMAKE_CURRENT_SOURCE_DIR}/hicn-light/hicn_forwarder_module.cc ) list(APPEND HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/hicn-light-ng/hicn_forwarder_module.h + ${CMAKE_CURRENT_SOURCE_DIR}/hicn-light/hicn_forwarder_module.h ) if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) @@ -69,7 +69,7 @@ else() ############################################################## # Compile submodules ############################################################## - add_subdirectory(hicn-light-ng) + add_subdirectory(hicn-light) add_subdirectory(loopback) add_subdirectory(forwarder) diff --git a/libtransport/src/io_modules/hicn-light-ng/CMakeLists.txt b/libtransport/src/io_modules/hicn-light/CMakeLists.txt index 325a8bd1d..ae3aec52d 100644 --- a/libtransport/src/io_modules/hicn-light-ng/CMakeLists.txt +++ b/libtransport/src/io_modules/hicn-light/CMakeLists.txt @@ -12,7 +12,7 @@ # limitations under the License. if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - find_package(Libhicnctrl ${CURRENT_VERSION} REQUIRED NO_MODULE) + find_package(Libhicnctrl ${HICN_CURRENT_VERSION} REQUIRED NO_MODULE) if (DISABLE_SHARED_LIBRARIES) set(LIBTYPE static) @@ -47,16 +47,17 @@ list(APPEND MODULE_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/hicn_forwarder_module.cc ) -build_module(hicnlightng_module - SHARED - SOURCES ${MODULE_SOURCE_FILES} - DEPENDS ${DEPENDENCIES} - COMPONENT ${LIBTRANSPORT_COMPONENT} - LINK_LIBRARIES PRIVATE ${LIBHICNCTRL_LIBRARIES} - INCLUDE_DIRS - PRIVATE - ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS} - ${Libhicnctrl_INCLUDE_DIRS} - DEFINITIONS ${COMPILER_DEFINITIONS} - COMPILE_OPTIONS ${COMPILER_OPTIONS} +build_module(hicnlight_module + SHARED + SOURCES ${MODULE_SOURCE_FILES} + DEPENDS ${DEPENDENCIES} + COMPONENT ${LIBTRANSPORT_COMPONENT} + LINK_LIBRARIES PRIVATE ${LIBHICNCTRL_LIBRARIES} + INCLUDE_DIRS + PRIVATE + ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS} + ${Libhicn_INCLUDE_DIRS} + ${Libhicnctrl_INCLUDE_DIRS} + DEFINITIONS ${COMPILER_DEFINITIONS} + COMPILE_OPTIONS ${COMPILER_OPTIONS} ) diff --git a/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.cc b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc index 95f04822f..ae8aebec6 100644 --- a/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.cc +++ b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.cc @@ -14,10 +14,10 @@ */ #include <core/udp_connector.h> -#include <io_modules/hicn-light-ng/hicn_forwarder_module.h> +#include <io_modules/hicn-light/hicn_forwarder_module.h> extern "C" { -#include <hicn/ctrl/hicn-light-ng.h> +#include <hicn/ctrl/hicn-light.h> } namespace transport { diff --git a/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.h b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h index 7f0e7aca8..0d6acb484 100644 --- a/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.h +++ b/libtransport/src/io_modules/hicn-light/hicn_forwarder_module.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -19,7 +19,7 @@ #include <hicn/transport/core/prefix.h> extern "C" { -#include <hicn/ctrl/hicn-light-ng.h> +#include <hicn/ctrl/hicn-light.h> } namespace transport { @@ -32,6 +32,7 @@ class HicnForwarderModule : public IoModule { static constexpr std::uint16_t interface_mtu = 1500; public: +#if 0 union addressLight { uint32_t ipv4; struct in6_addr ipv6; @@ -50,6 +51,7 @@ class HicnForwarderModule : public IoModule { }; using route_to_self_command = struct route_to_self_command; +#endif HicnForwarderModule(); diff --git a/libtransport/src/io_modules/loopback/local_face.cc b/libtransport/src/io_modules/loopback/local_face.cc index 7ef3f1a59..30a46c93b 100644 --- a/libtransport/src/io_modules/loopback/local_face.cc +++ b/libtransport/src/io_modules/loopback/local_face.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -57,12 +57,18 @@ Face &Face::operator=(Face &&other) { void Face::onPacket(const Packet &packet) { DLOG_IF(INFO, VLOG_IS_ON(3)) << "Sending content to local socket."; - if (Packet::isInterest(packet.data())) { - rescheduleOnIoService<Interest>(packet); - } else { - rescheduleOnIoService<ContentObject>(packet); + switch (packet->getFormat()) { + case HICN_PACKET_FORMAT_INTEREST: + rescheduleOnIoService<Interest>(packet); + break; + case HICN_PACKET_FORMAT_DATA: + rescheduleOnIoService<ContentObject>(packet); + break; + default: + /* Should not occur */ + break; } } } // namespace core -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/src/io_modules/memif/hicn_vapi.c b/libtransport/src/io_modules/memif/hicn_vapi.c index 753679f54..9fc64f720 100644 --- a/libtransport/src/io_modules/memif/hicn_vapi.c +++ b/libtransport/src/io_modules/memif/hicn_vapi.c @@ -53,14 +53,15 @@ static vapi_error_e register_prod_app_cb( if (reply == NULL) return rv; output_params->cs_reserved = reply->cs_reserved; - output_params->prod_addr = (ip_address_t *)malloc(sizeof(ip_address_t)); - memset(output_params->prod_addr, 0, sizeof(ip_address_t)); + output_params->prod_addr = + (hicn_ip_address_t *)malloc(sizeof(hicn_ip_address_t)); + memset(output_params->prod_addr, 0, sizeof(hicn_ip_address_t)); if (reply->prod_addr.af == ADDRESS_IP6) memcpy(&output_params->prod_addr->v6, reply->prod_addr.un.ip6, - sizeof(ip6_address_t)); + sizeof(ipv6_address_t)); else memcpy(&output_params->prod_addr->v4, reply->prod_addr.un.ip4, - sizeof(ip4_address_t)); + sizeof(ipv4_address_t)); output_params->face_id = reply->faceid; return reply->retval; @@ -73,13 +74,14 @@ int hicn_vapi_register_prod_app(vapi_ctx_t ctx, vapi_msg_hicn_api_register_prod_app *msg = vapi_alloc_hicn_api_register_prod_app(ctx); - if (ip_address_is_v4((ip_address_t *)&input_params->prefix->address)) { + if (hicn_ip_address_is_v4( + (hicn_ip_address_t *)&input_params->prefix->address)) { memcpy(&msg->payload.prefix.address.un.ip4, &input_params->prefix->address, - sizeof(ip4_address_t)); + sizeof(ipv4_address_t)); msg->payload.prefix.address.af = ADDRESS_IP4; } else { memcpy(&msg->payload.prefix.address.un.ip6, &input_params->prefix->address, - sizeof(ip6_address_t)); + sizeof(ipv6_address_t)); msg->payload.prefix.address.af = ADDRESS_IP6; } msg->payload.prefix.len = input_params->prefix->len; @@ -121,14 +123,14 @@ static vapi_error_e register_cons_app_cb( if (reply == NULL) return rv; - output_params->src6 = (ip_address_t *)malloc(sizeof(ip_address_t)); - output_params->src4 = (ip_address_t *)malloc(sizeof(ip_address_t)); - memset(output_params->src6, 0, sizeof(ip_address_t)); - memset(output_params->src4, 0, sizeof(ip_address_t)); + output_params->src6 = (hicn_ip_address_t *)malloc(sizeof(hicn_ip_address_t)); + output_params->src4 = (hicn_ip_address_t *)malloc(sizeof(hicn_ip_address_t)); + memset(output_params->src6, 0, sizeof(hicn_ip_address_t)); + memset(output_params->src4, 0, sizeof(hicn_ip_address_t)); memcpy(&output_params->src6->v6, &reply->src_addr6.un.ip6, - sizeof(ip6_address_t)); + sizeof(ipv6_address_t)); memcpy(&output_params->src4->v4, &reply->src_addr4.un.ip4, - sizeof(ip4_address_t)); + sizeof(ipv4_address_t)); output_params->face_id1 = reply->faceid1; output_params->face_id2 = reply->faceid2; @@ -185,27 +187,27 @@ int hicn_vapi_register_route(vapi_ctx_t ctx, vapi_msg_ip_route_add_del *msg = vapi_alloc_ip_route_add_del(ctx, 1); msg->payload.is_add = 1; - if (ip_address_is_v4((ip_address_t *)(input_params->prod_addr))) { + if (hicn_ip_address_is_v4((hicn_ip_address_t *)(input_params->prod_addr))) { memcpy(&msg->payload.route.prefix.address.un.ip4, - &input_params->prefix->address.v4, sizeof(ip4_address_t)); + &input_params->prefix->address.v4, sizeof(ipv4_address_t)); msg->payload.route.prefix.address.af = ADDRESS_IP4; msg->payload.route.prefix.len = input_params->prefix->len; } else { memcpy(&msg->payload.route.prefix.address.un.ip6, - &input_params->prefix->address.v6, sizeof(ip6_address_t)); + &input_params->prefix->address.v6, sizeof(ipv6_address_t)); msg->payload.route.prefix.address.af = ADDRESS_IP6; msg->payload.route.prefix.len = input_params->prefix->len; } msg->payload.route.paths[0].sw_if_index = ~0; msg->payload.route.paths[0].table_id = 0; - if (ip_address_is_v4((ip_address_t *)(input_params->prod_addr))) { + if (hicn_ip_address_is_v4((hicn_ip_address_t *)(input_params->prod_addr))) { memcpy(&(msg->payload.route.paths[0].nh.address.ip4), - input_params->prod_addr->v4.as_u8, sizeof(ip4_address_t)); + input_params->prod_addr->v4.as_u8, sizeof(ipv4_address_t)); msg->payload.route.paths[0].proto = FIB_API_PATH_NH_PROTO_IP4; } else { memcpy(&(msg->payload.route.paths[0].nh.address.ip6), - input_params->prod_addr->v6.as_u8, sizeof(ip6_address_t)); + input_params->prod_addr->v6.as_u8, sizeof(ipv6_address_t)); msg->payload.route.paths[0].proto = FIB_API_PATH_NH_PROTO_IP6; } diff --git a/libtransport/src/io_modules/memif/hicn_vapi.h b/libtransport/src/io_modules/memif/hicn_vapi.h index 967179f68..cfdc93fe3 100644 --- a/libtransport/src/io_modules/memif/hicn_vapi.h +++ b/libtransport/src/io_modules/memif/hicn_vapi.h @@ -27,7 +27,7 @@ extern "C" { #include "stdint.h" typedef struct { - ip_prefix_t* prefix; + hicn_ip_prefix_t* prefix; uint32_t swif; uint32_t cs_reserved; } hicn_producer_input_params; @@ -42,20 +42,20 @@ typedef struct { typedef struct { uint32_t cs_reserved; - ip_address_t* prod_addr; + hicn_ip_address_t* prod_addr; uint32_t face_id; } hicn_producer_output_params; typedef struct { - ip_address_t* src4; - ip_address_t* src6; + hicn_ip_address_t* src4; + hicn_ip_address_t* src6; uint32_t face_id1; uint32_t face_id2; } hicn_consumer_output_params; typedef struct { - ip_prefix_t* prefix; - ip_address_t* prod_addr; + hicn_ip_prefix_t* prefix; + hicn_ip_address_t* prod_addr; } hicn_producer_set_route_params; int hicn_vapi_register_prod_app(vapi_ctx_t ctx, diff --git a/libtransport/src/io_modules/memif/vpp_forwarder_module.cc b/libtransport/src/io_modules/memif/vpp_forwarder_module.cc index c096a71b8..ab11828ec 100644 --- a/libtransport/src/io_modules/memif/vpp_forwarder_module.cc +++ b/libtransport/src/io_modules/memif/vpp_forwarder_module.cc @@ -124,8 +124,8 @@ uint32_t VPPForwarderModule::getMemifConfiguration() { void VPPForwarderModule::consumerConnection() { hicn_consumer_input_params input = {0}; hicn_consumer_output_params output = {0}; - ip_address_t ip4_address; - ip_address_t ip6_address; + hicn_ip_address_t ip4_address; + hicn_ip_address_t ip6_address; output.src4 = &ip4_address; output.src6 = &ip6_address; @@ -181,10 +181,10 @@ void VPPForwarderModule::connect(bool is_consumer) { } void VPPForwarderModule::registerRoute(const Prefix &prefix) { - const ip_prefix_t &addr = prefix.toIpPrefixStruct(); + const hicn_ip_prefix_t &addr = prefix.toIpPrefixStruct(); - ip_prefix_t producer_prefix; - ip_address_t producer_locator; + hicn_ip_prefix_t producer_prefix; + hicn_ip_address_t producer_locator; if (face_id1_ == uint32_t(~0)) { hicn_producer_input_params input; diff --git a/libtransport/src/protocols/prod_protocol_rtc.cc b/libtransport/src/protocols/prod_protocol_rtc.cc index cb8dff6e4..3d1562801 100644 --- a/libtransport/src/protocols/prod_protocol_rtc.cc +++ b/libtransport/src/protocols/prod_protocol_rtc.cc @@ -24,6 +24,10 @@ #include <unordered_set> +extern "C" { +#include <hicn/util/bitmap.h> +} + namespace transport { namespace protocol { @@ -568,7 +572,7 @@ void RTCProductionProtocol::onInterest(Interest &interest) { uint32_t *suffix = interest.firstSuffix(); uint32_t n_suffixes_in_manifest = interest.numberOfSuffixes(); - uint32_t *request_bitmap = interest.getRequestBitmap(); + hicn_uword *request_bitmap = interest.getRequestBitmap(); Name name = interest.getName(); uint32_t pos = 0; // Position of current suffix in manifest @@ -580,7 +584,8 @@ void RTCProductionProtocol::onInterest(Interest &interest) { // Process the suffix in the interest header // (first loop iteration), then suffixes in the manifest do { - if (!interest.hasManifest() || is_bit_set(request_bitmap, pos)) { + if (!interest.hasManifest() || + bitmap_is_set_no_check(request_bitmap, pos)) { const std::shared_ptr<ContentObject> content_object = output_buffer_.find(name); diff --git a/libtransport/src/protocols/rtc/rtc_recovery_strategy.h b/libtransport/src/protocols/rtc/rtc_recovery_strategy.h index aceb85888..405e1ebba 100644 --- a/libtransport/src/protocols/rtc/rtc_recovery_strategy.h +++ b/libtransport/src/protocols/rtc/rtc_recovery_strategy.h @@ -21,6 +21,7 @@ #include <protocols/rtc/rtc_state.h> #include <map> +#include <optional> #include <unordered_map> namespace transport { diff --git a/libtransport/src/test/CMakeLists.txt b/libtransport/src/test/CMakeLists.txt index b7f14766e..356ee0067 100644 --- a/libtransport/src/test/CMakeLists.txt +++ b/libtransport/src/test/CMakeLists.txt @@ -17,7 +17,7 @@ list(APPEND TESTS_SRC main.cc test_aggregated_header.cc - test_auth.cc + #######test_auth.cc # test_consumer_producer_rtc.cc test_core_manifest.cc # test_event_thread.cc @@ -42,11 +42,11 @@ if (ENABLE_RELY) ) endif() -if (UNIX AND NOT APPLE) - list(APPEND TESTS_SRC - test_memif_connector.cc - ) -endif() +#if (UNIX AND NOT APPLE) +# list(APPEND TESTS_SRC +# test_memif_connector.cc +# ) +#endif() ############################################################## diff --git a/libtransport/src/test/packet_samples.h b/libtransport/src/test/packet_samples.h index e98d06a18..216ac7f9f 100644 --- a/libtransport/src/test/packet_samples.h +++ b/libtransport/src/test/packet_samples.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -56,3 +56,16 @@ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + +#define SIGNATURE \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 diff --git a/libtransport/src/test/test_aggregated_header.cc b/libtransport/src/test/test_aggregated_header.cc index 0d88af5ab..4dd71f60d 100644 --- a/libtransport/src/test/test_aggregated_header.cc +++ b/libtransport/src/test/test_aggregated_header.cc @@ -54,6 +54,7 @@ class AggregatedPktHeaderTest : public ::testing::Test { } // namespace +#if 0 TEST_F(AggregatedPktHeaderTest, Add2Packets8bit) { uint8_t buf[1500]; std::vector<uint8_t> pkt1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; @@ -103,6 +104,7 @@ TEST_F(AggregatedPktHeaderTest, Add2Packets8bit) { EXPECT_EQ(*(pkt_ptr + i), pkt2[i]); } } +#endif TEST_F(AggregatedPktHeaderTest, Add2Packets8bit255) { uint8_t buf[1500]; diff --git a/libtransport/src/test/test_auth.cc b/libtransport/src/test/test_auth.cc index 0c47dd958..5b9b04c5c 100644 --- a/libtransport/src/test/test_auth.cc +++ b/libtransport/src/test/test_auth.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -42,7 +42,7 @@ class AuthTest : public ::testing::Test { TEST_F(AuthTest, VoidVerifier) { // Create a content object - core::ContentObject packet(HF_INET6_TCP_AH); + core::ContentObject packet(HICN_PACKET_FORMAT_IPV6_TCP_AH); // Fill it with bogus data uint8_t buffer[256] = {0}; @@ -74,7 +74,8 @@ TEST_F(AuthTest, AsymmetricRSA) { CryptoSuite::RSA_SHA256, privateKey, pubKey); // Create a content object - core::ContentObject packet(HF_INET6_TCP_AH, signer->getSignatureSize()); + core::ContentObject packet(HICN_PACKET_FORMAT_IPV6_TCP_AH, + signer->getSignatureSize()); // Fill it with bogus data uint8_t buffer[256] = {0}; @@ -87,7 +88,7 @@ TEST_F(AuthTest, AsymmetricRSA) { std::shared_ptr<Verifier> verifier = std::make_shared<AsymmetricVerifier>(pubKey); - EXPECT_EQ(packet.getFormat(), HF_INET6_TCP_AH); + EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::RSA_SHA256); EXPECT_EQ(signer->getSignatureSize(), 256u); @@ -189,7 +190,8 @@ TEST_F(AuthTest, AsymmetricVerifierDSA) { CryptoSuite::DSA_SHA256, privateKey, pubKey); // Create a content object - core::ContentObject packet(HF_INET6_TCP_AH, signer->getSignatureSize()); + core::ContentObject packet(HICN_PACKET_FORMAT_IPV6_TCP_AH, + signer->getSignatureSize()); // Fill it with bogus data uint8_t buffer[256] = {0}; @@ -200,7 +202,7 @@ TEST_F(AuthTest, AsymmetricVerifierDSA) { std::shared_ptr<Verifier> verifier = std::make_shared<AsymmetricVerifier>(cert); - EXPECT_EQ(packet.getFormat(), HF_INET6_TCP_AH); + EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::DSA_SHA256); EXPECT_EQ(verifier->verifyPackets(&packet), VerificationPolicy::ACCEPT); @@ -259,14 +261,15 @@ TEST_F(AuthTest, AsymmetricVerifierECDSA) { std::shared_ptr<AsymmetricVerifier> verifier = std::make_shared<AsymmetricVerifier>(pubKey); for (int i = 0; i < 100; i++) { - core::ContentObject packet(HF_INET6_TCP_AH, signer->getSignatureSize()); + core::ContentObject packet(HICN_PACKET_FORMAT_IPV6_TCP_AH, + signer->getSignatureSize()); // Fill it with bogus data uint8_t buffer[256] = {0}; packet.appendPayload(buffer, 256); signer->signPacket(&packet); - EXPECT_EQ(packet.getFormat(), HF_INET6_TCP_AH); + EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); EXPECT_EQ(signer->getHashType(), CryptoHashType::SHA256); EXPECT_EQ(signer->getSuite(), CryptoSuite::ECDSA_SHA256); EXPECT_EQ(verifier->verifyPackets(&packet), VerificationPolicy::ACCEPT); @@ -279,7 +282,8 @@ TEST_F(AuthTest, HMACbuffer) { std::make_shared<SymmetricSigner>(CryptoSuite::HMAC_SHA256, PASSPHRASE); // Create a content object - core::ContentObject packet(HF_INET6_TCP_AH, signer->getSignatureSize()); + core::ContentObject packet(HICN_PACKET_FORMAT_IPV6_TCP_AH, + signer->getSignatureSize()); std::string payload = "bonjour"; std::vector<uint8_t> buffer(payload.begin(), payload.end()); @@ -296,7 +300,8 @@ TEST_F(AuthTest, HMACVerifier) { std::make_shared<SymmetricSigner>(CryptoSuite::HMAC_SHA256, PASSPHRASE); // Create a content object - core::ContentObject packet(HF_INET6_TCP_AH, signer->getSignatureSize()); + core::ContentObject packet(HICN_PACKET_FORMAT_IPV6_TCP_AH, + signer->getSignatureSize()); // Fill it with bogus data uint8_t buffer[256] = {0}; @@ -309,7 +314,7 @@ TEST_F(AuthTest, HMACVerifier) { std::shared_ptr<Verifier> verifier = std::make_shared<SymmetricVerifier>(PASSPHRASE); - EXPECT_EQ(packet.getFormat(), HF_INET6_TCP_AH); + EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32); 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_core_manifest.cc b/libtransport/src/test/test_core_manifest.cc index e3d66c1cd..99c71a56c 100644 --- a/libtransport/src/test/test_core_manifest.cc +++ b/libtransport/src/test/test_core_manifest.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -36,7 +36,9 @@ class ManifestTest : public ::testing::Test { using ContentObjectManifest = Manifest<Fixed>; ManifestTest() - : format_(HF_INET6_TCP_AH), name_("b001::123|321"), signature_size_(0) { + : format_(HICN_PACKET_FORMAT_IPV6_TCP_AH), + name_("b001::123|321"), + signature_size_(0) { manifest_ = ContentObjectManifest::createContentManifest(format_, name_, signature_size_); } diff --git a/libtransport/src/test/test_fec_base_rely.cc b/libtransport/src/test/test_fec_base_rely.cc index 41e1eae49..2ee00e25e 100644 --- a/libtransport/src/test/test_fec_base_rely.cc +++ b/libtransport/src/test/test_fec_base_rely.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -46,7 +46,7 @@ class PacketFactory { // create data packet auto data = packet_manager.getPacket<transport::core::ContentObject>( - HF_INET6_TCP, 0); + HICN_PACKET_FORMAT_IPV6_TCP, 0); struct rtc::data_packet_t header; header.setTimestamp(1000); header.setProductionRate(1); @@ -64,7 +64,7 @@ class PacketFactory { auto &packet_manager = core::PacketManager<>::getInstance(); auto data = packet_manager.getPacket<transport::core::ContentObject>( - HF_INET6_TCP, 0); + HICN_PACKET_FORMAT_IPV6_TCP, 0); struct rtc::data_packet_t header; header.setTimestamp(1000); header.setProductionRate(1); @@ -101,7 +101,8 @@ class Encoder { fec::buffer getBuffer(std::size_t size) { auto ret = core::PacketManager<>::getInstance() - .getPacket<transport::core::ContentObject>(HF_INET6_TCP, 0); + .getPacket<transport::core::ContentObject>( + HICN_PACKET_FORMAT_IPV6_TCP, 0); ret->updateLength(rtc::DATA_HEADER_SIZE + size); ret->append(rtc::DATA_HEADER_SIZE + size); ret->trimStart(ret->headerSize() + rtc::DATA_HEADER_SIZE); diff --git a/libtransport/src/test/test_fec_base_rs.cc b/libtransport/src/test/test_fec_base_rs.cc index 7d7bcebc3..549bb3f08 100644 --- a/libtransport/src/test/test_fec_base_rs.cc +++ b/libtransport/src/test/test_fec_base_rs.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -46,7 +46,7 @@ class PacketFactory { // create data packet auto data = packet_manager.getPacket<transport::core::ContentObject>( - HF_INET6_TCP, 0); + HICN_PACKET_FORMAT_IPV6_TCP, 0); struct rtc::data_packet_t header; header.setTimestamp(1000); header.setProductionRate(1); @@ -64,7 +64,7 @@ class PacketFactory { auto &packet_manager = core::PacketManager<>::getInstance(); auto data = packet_manager.getPacket<transport::core::ContentObject>( - HF_INET6_TCP, 0); + HICN_PACKET_FORMAT_IPV6_TCP, 0); struct rtc::data_packet_t header; header.setTimestamp(1000); header.setProductionRate(1); @@ -99,7 +99,8 @@ class Encoder { fec::buffer getBuffer(std::size_t size) { auto ret = core::PacketManager<>::getInstance() - .getPacket<transport::core::ContentObject>(HF_INET6_TCP, 0); + .getPacket<transport::core::ContentObject>( + HICN_PACKET_FORMAT_IPV6_TCP, 0); ret->updateLength(rtc::DATA_HEADER_SIZE + size); ret->append(rtc::DATA_HEADER_SIZE + size); ret->trimStart(ret->headerSize() + rtc::DATA_HEADER_SIZE); diff --git a/libtransport/src/test/test_interest.cc b/libtransport/src/test/test_interest.cc index e36ca0f93..8d00a9c6d 100644 --- a/libtransport/src/test/test_interest.cc +++ b/libtransport/src/test/test_interest.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -30,7 +30,8 @@ namespace { // The fixture for testing class Foo. class InterestTest : public ::testing::Test { protected: - InterestTest() : name_("b001::123|321"), interest_(HF_INET6_TCP) { + InterestTest() + : name_("b001::123|321"), interest_(HICN_PACKET_FORMAT_IPV6_TCP) { // You can do set-up work for each test here. } @@ -63,15 +64,18 @@ class InterestTest : public ::testing::Test { PAYLOAD}; }; -void testFormatConstructor(Packet::Format format = HF_UNSPEC) { +void testFormatConstructor( + hicn_packet_format_t format = HICN_PACKET_FORMAT_NONE) { try { Interest interest(format, 0); } catch (...) { - FAIL() << "ERROR: Unexpected exception thrown for " << format; + char buf[MAXSZ_HICN_PACKET_FORMAT]; + FAIL() << "ERROR: Unexpected exception thrown for " << buf; } } -void testFormatConstructorException(Packet::Format format = HF_UNSPEC) { +void testFormatConstructorException( + Packet::Format format = HICN_PACKET_FORMAT_NONE) { try { Interest interest(format, 0); FAIL() << "We expected an exception here"; @@ -86,29 +90,29 @@ void testFormatConstructorException(Packet::Format format = HF_UNSPEC) { TEST_F(InterestTest, ConstructorWithFormat) { /** - * Without arguments it should be format = HF_UNSPEC. + * Without arguments it should be format = HICN_PACKET_FORMAT_NONE. * We expect a crash. */ - testFormatConstructor(Packet::Format::HF_INET_TCP); - testFormatConstructor(Packet::Format::HF_INET6_TCP); - testFormatConstructorException(Packet::Format::HF_INET_ICMP); - testFormatConstructorException(Packet::Format::HF_INET6_ICMP); - testFormatConstructor(Packet::Format::HF_INET_TCP_AH); - testFormatConstructor(Packet::Format::HF_INET6_TCP_AH); - testFormatConstructorException(Packet::Format::HF_INET_ICMP_AH); - testFormatConstructorException(Packet::Format::HF_INET6_ICMP_AH); + testFormatConstructor(HICN_PACKET_FORMAT_IPV4_TCP); + testFormatConstructor(HICN_PACKET_FORMAT_IPV6_TCP); + testFormatConstructorException(HICN_PACKET_FORMAT_IPV4_ICMP); + testFormatConstructorException(HICN_PACKET_FORMAT_IPV6_ICMP); + testFormatConstructor(HICN_PACKET_FORMAT_IPV4_TCP_AH); + testFormatConstructor(HICN_PACKET_FORMAT_IPV6_TCP_AH); + testFormatConstructorException(HICN_PACKET_FORMAT_IPV4_ICMP_AH); + testFormatConstructorException(HICN_PACKET_FORMAT_IPV6_ICMP_AH); } TEST_F(InterestTest, ConstructorWithName) { /** - * Without arguments it should be format = HF_UNSPEC. + * Without arguments it should be format = HICN_PACKET_FORMAT_NONE. * We expect a crash. */ Name n("b001::1|123"); try { - Interest interest(HF_INET6_TCP, n); + Interest interest(HICN_PACKET_FORMAT_IPV6_TCP, n); } catch (...) { FAIL() << "ERROR: Unexpected exception thrown"; } @@ -116,8 +120,10 @@ TEST_F(InterestTest, ConstructorWithName) { TEST_F(InterestTest, ConstructorWithBuffer) { // Ensure buffer is interest +#if 0 auto ret = Interest::isInterest(&buffer_[0]); EXPECT_TRUE(ret); +#endif // Create interest from buffer try { @@ -175,9 +181,9 @@ TEST_F(InterestTest, SetGetLocator) { // Get locator auto l = interest.getLocator(); - ip_address_t address; + hicn_ip_address_t address; inet_pton(AF_INET6, "b006::ab:cdab:cdef", &address); - auto ret = !ip_address_cmp(&l, &address, AF_INET6); + auto ret = !hicn_ip_address_cmp(&l, &address); EXPECT_TRUE(ret); @@ -189,14 +195,14 @@ TEST_F(InterestTest, SetGetLocator) { // Check it was set l = interest.getLocator(); - ret = !ip_address_cmp(&l, &address, AF_INET6); + ret = !hicn_ip_address_cmp(&l, &address); EXPECT_TRUE(ret); } TEST_F(InterestTest, SetGetLifetime) { // Create interest from buffer - Interest interest(HF_INET6_TCP); + Interest interest(HICN_PACKET_FORMAT_IPV6_TCP); const constexpr uint32_t lifetime = 10000; // Set lifetime @@ -211,7 +217,7 @@ TEST_F(InterestTest, SetGetLifetime) { TEST_F(InterestTest, HasManifest) { // Create interest from buffer - Interest interest(HF_INET6_TCP); + Interest interest(HICN_PACKET_FORMAT_IPV6_TCP); // Let's expect anexception here try { @@ -232,7 +238,7 @@ TEST_F(InterestTest, HasManifest) { TEST_F(InterestTest, AppendSuffixesEncodeAndIterate) { // Create interest from buffer - Interest interest(HF_INET6_TCP); + Interest interest(HICN_PACKET_FORMAT_IPV6_TCP); // Appenad some suffixes, with some duplicates interest.appendSuffix(1); @@ -260,7 +266,7 @@ TEST_F(InterestTest, AppendSuffixesEncodeAndIterate) { TEST_F(InterestTest, AppendSuffixesWithGaps) { // Create interest from buffer - Interest interest(HF_INET6_TCP); + Interest interest(HICN_PACKET_FORMAT_IPV6_TCP); // Appenad some suffixes, out of order and with gaps interest.appendSuffix(6); @@ -289,7 +295,7 @@ TEST_F(InterestTest, AppendSuffixesWithGaps) { TEST_F(InterestTest, InterestWithoutManifest) { // Create interest without manifest - Interest interest(HF_INET6_TCP); + Interest interest(HICN_PACKET_FORMAT_IPV6_TCP); auto suffix = interest.firstSuffix(); EXPECT_FALSE(interest.hasManifest()); diff --git a/libtransport/src/test/test_packet.cc b/libtransport/src/test/test_packet.cc index ca20cdfb7..3dfca8f9a 100644 --- a/libtransport/src/test/test_packet.cc +++ b/libtransport/src/test/test_packet.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -23,6 +23,8 @@ #include <random> #include <vector> +#include "../../lib/src/protocol.h" + namespace transport { namespace core { @@ -56,13 +58,13 @@ class PacketForTest : public Packet { throw errors::NotImplementedException(); } - void setLocator(const ip_address_t &locator) override { + void setLocator(const hicn_ip_address_t &locator) override { throw errors::NotImplementedException(); } void resetForHash() override { throw errors::NotImplementedException(); } - ip_address_t getLocator() const override { + hicn_ip_address_t getLocator() const override { throw errors::NotImplementedException(); } }; @@ -73,8 +75,9 @@ class PacketTest : public ::testing::Test { protected: PacketTest() : name_("b001::123|321"), - packet(Packet::COPY_BUFFER, &raw_packets_[HF_INET6_TCP][0], - raw_packets_[HF_INET6_TCP].size()) { + packet(Packet::COPY_BUFFER, + &raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0], + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()) { // You can do set-up work for each test here. } @@ -99,7 +102,7 @@ class PacketTest : public ::testing::Test { PacketForTest packet; - static std::map<Packet::Format, std::vector<uint8_t>> raw_packets_; + static std::map<uint32_t, std::vector<uint8_t>> raw_packets_; std::vector<uint8_t> payload = { 0x11, 0x11, 0x01, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -115,8 +118,8 @@ class PacketTest : public ::testing::Test { }; }; -std::map<Packet::Format, std::vector<uint8_t>> PacketTest::raw_packets_ = { - {Packet::Format::HF_INET6_TCP, +std::map<uint32_t, std::vector<uint8_t>> PacketTest::raw_packets_ = { + {HICN_PACKET_FORMAT_IPV6_TCP.as_u32, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(TCP_PROTO, 20 + PAYLOAD_SIZE), @@ -125,7 +128,7 @@ std::map<Packet::Format, std::vector<uint8_t>> PacketTest::raw_packets_ = { // Payload PAYLOAD}}, - {Packet::Format::HF_INET_TCP, + {HICN_PACKET_FORMAT_IPV4_TCP.as_u32, {// 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 @@ -133,64 +136,68 @@ std::map<Packet::Format, std::vector<uint8_t>> PacketTest::raw_packets_ = { // Other PAYLOAD}}, - {Packet::Format::HF_INET_ICMP, + {HICN_PACKET_FORMAT_IPV4_ICMP.as_u32, {// IPv4 src=3.13.127.8, dst=192.168.1.92 IPV4_HEADER(ICMP_PROTO, 64), // ICMP echo request ICMP_ECHO_REQUEST}}, - {Packet::Format::HF_INET6_ICMP, + {HICN_PACKET_FORMAT_IPV6_ICMP.as_u32, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(ICMP6_PROTO, 60), // ICMP6 echo request ICMP6_ECHO_REQUEST}}, - {Packet::Format::HF_INET6_TCP_AH, + {HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(TCP_PROTO, 20 + 44 + 128), // ICMP6 echo request TCP_HEADER(0x18), // hICN AH header - AH_HEADER}}, + AH_HEADER, SIGNATURE}}, - {Packet::Format::HF_INET_TCP_AH, + {HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV4_HEADER(TCP_PROTO, 20 + 44 + 128), // ICMP6 echo request TCP_HEADER(0x18), // hICN AH header - AH_HEADER}}, + AH_HEADER, SIGNATURE}}, // XXX No flag defined in ICMP header to signal AH header. - {Packet::Format::HF_INET_ICMP_AH, + {HICN_PACKET_FORMAT_IPV4_ICMP_AH.as_u32, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV4_HEADER(ICMP_PROTO, 64 + 44), // ICMP6 echo request ICMP_ECHO_REQUEST, // hICN AH header - AH_HEADER}}, + AH_HEADER, SIGNATURE}}, - {Packet::Format::HF_INET6_ICMP_AH, + {HICN_PACKET_FORMAT_IPV6_ICMP_AH.as_u32, {// IPv6 src=b001::ab:cdab:cdef, dst=b002::ca IPV6_HEADER(ICMP6_PROTO, 60 + 44), // ICMP6 echo request ICMP6_ECHO_REQUEST, // hICN AH header - AH_HEADER}}, + AH_HEADER, SIGNATURE}}, }; -void testFormatConstructor(Packet::Format format = HF_UNSPEC) { +void testFormatConstructor(Packet::Format format = HICN_PACKET_FORMAT_NONE) { try { - PacketForTest packet(format); + PacketForTest packet(HICN_PACKET_TYPE_INTEREST, format); } catch (...) { - FAIL() << "ERROR: Unexpected exception thrown for " << format; + char buf[MAXSZ_HICN_PACKET_FORMAT]; + int rc = hicn_packet_format_snprintf(buf, MAXSZ_HICN_PACKET_FORMAT, format); + if (rc < 0 || rc >= MAXSZ_HICN_PACKET_FORMAT) + snprintf(buf, MAXSZ_HICN_PACKET_FORMAT, "%s", "(error"); + FAIL() << "ERROR: Unexpected exception thrown for " << buf; } } void testFormatAndAdditionalHeaderConstructor(Packet::Format format, std::size_t additional_header) { - PacketForTest packet(format, additional_header); + PacketForTest packet(HICN_PACKET_TYPE_INTEREST, format, additional_header); // Packet length should be the one of the normal header + the // additional_header @@ -206,7 +213,7 @@ void testRawBufferConstructor(std::vector<uint8_t> packet, packet.size()); // Check format is expected one. - EXPECT_EQ(p.getFormat(), format); + EXPECT_EQ(p.getFormat().as_u32, format.as_u32); // // Try the same using a MemBuf // auto buf = utils::MemBuf::wrapBuffer(&packet[0], packet.size()); @@ -229,17 +236,19 @@ void testRawBufferConstructor(std::vector<uint8_t> packet, PacketForTest p(Packet::WRAP_BUFFER, &packet[0], packet.size(), packet.size()); - // Format should fallback to HF_UNSPEC - EXPECT_EQ(p.getFormat(), HF_UNSPEC); + // Format should fallback to HICN_PACKET_FORMAT_NONE + EXPECT_EQ(p.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); + } catch (errors::MalformedPacketException &exc) { + // Ok right exception } catch (...) { FAIL() << "ERROR: Unexpected exception thrown."; } } -void getHeaderSizeFromBuffer(Packet::Format format, - std::vector<uint8_t> &packet, +void getHeaderSizeFromBuffer(std::vector<uint8_t> &packet, std::size_t expected) { - auto header_size = PacketForTest::getHeaderSizeFromBuffer(format, &packet[0]); + auto header_size = + PacketForTest::getHeaderSizeFromBuffer(&packet[0], packet.size()); EXPECT_EQ(header_size, expected); } @@ -248,18 +257,17 @@ void getHeaderSizeFromFormat(Packet::Format format, std::size_t expected) { EXPECT_EQ(header_size, expected); } -void getPayloadSizeFromBuffer(Packet::Format format, - std::vector<uint8_t> &packet, +void getPayloadSizeFromBuffer(std::vector<uint8_t> &packet, std::size_t expected) { auto payload_size = - PacketForTest::getPayloadSizeFromBuffer(format, &packet[0]); + PacketForTest::getPayloadSizeFromBuffer(&packet[0], packet.size()); EXPECT_EQ(payload_size, expected); } void getFormatFromBuffer(Packet::Format expected, std::vector<uint8_t> &packet) { auto format = PacketForTest::getFormatFromBuffer(&packet[0], packet.size()); - EXPECT_EQ(format, expected); + EXPECT_EQ(format.as_u32, expected.as_u32); } void getHeaderSize(std::size_t expected, const PacketForTest &packet) { @@ -269,143 +277,160 @@ void getHeaderSize(std::size_t expected, const PacketForTest &packet) { void testGetFormat(Packet::Format expected, const Packet &packet) { auto format = packet.getFormat(); - EXPECT_EQ(format, expected); + EXPECT_EQ(format.as_u32, expected.as_u32); } } // namespace TEST_F(PacketTest, ConstructorWithFormat) { - testFormatConstructor(Packet::Format::HF_INET_TCP); - testFormatConstructor(Packet::Format::HF_INET6_TCP); - testFormatConstructor(Packet::Format::HF_INET_ICMP); - testFormatConstructor(Packet::Format::HF_INET6_ICMP); - testFormatConstructor(Packet::Format::HF_INET_TCP_AH); - testFormatConstructor(Packet::Format::HF_INET6_TCP_AH); - testFormatConstructor(Packet::Format::HF_INET_ICMP_AH); - testFormatConstructor(Packet::Format::HF_INET6_ICMP_AH); + testFormatConstructor(HICN_PACKET_FORMAT_IPV4_TCP); + testFormatConstructor(HICN_PACKET_FORMAT_IPV6_TCP); + testFormatConstructor(HICN_PACKET_FORMAT_IPV4_ICMP); + testFormatConstructor(HICN_PACKET_FORMAT_IPV6_ICMP); + testFormatConstructor(HICN_PACKET_FORMAT_IPV4_TCP_AH); + testFormatConstructor(HICN_PACKET_FORMAT_IPV6_TCP_AH); + testFormatConstructor(HICN_PACKET_FORMAT_IPV4_ICMP_AH); + testFormatConstructor(HICN_PACKET_FORMAT_IPV6_ICMP_AH); } TEST_F(PacketTest, ConstructorWithFormatAndAdditionalHeader) { - testFormatAndAdditionalHeaderConstructor(Packet::Format::HF_INET_TCP, 123); - testFormatAndAdditionalHeaderConstructor(Packet::Format::HF_INET6_TCP, 360); - testFormatAndAdditionalHeaderConstructor(Packet::Format::HF_INET_ICMP, 21); - testFormatAndAdditionalHeaderConstructor(Packet::Format::HF_INET6_ICMP, 444); - testFormatAndAdditionalHeaderConstructor(Packet::Format::HF_INET_TCP_AH, 555); - testFormatAndAdditionalHeaderConstructor(Packet::Format::HF_INET6_TCP_AH, - 321); - testFormatAndAdditionalHeaderConstructor(Packet::Format::HF_INET_ICMP_AH, + testFormatAndAdditionalHeaderConstructor(HICN_PACKET_FORMAT_IPV4_TCP, 123); + testFormatAndAdditionalHeaderConstructor(HICN_PACKET_FORMAT_IPV6_TCP, 360); + testFormatAndAdditionalHeaderConstructor(HICN_PACKET_FORMAT_IPV4_ICMP, 21); + testFormatAndAdditionalHeaderConstructor(HICN_PACKET_FORMAT_IPV6_ICMP, 444); + testFormatAndAdditionalHeaderConstructor(HICN_PACKET_FORMAT_IPV4_TCP_AH, 555); + testFormatAndAdditionalHeaderConstructor(HICN_PACKET_FORMAT_IPV6_TCP_AH, 321); + testFormatAndAdditionalHeaderConstructor(HICN_PACKET_FORMAT_IPV4_ICMP_AH, 123); - testFormatAndAdditionalHeaderConstructor(Packet::Format::HF_INET6_ICMP_AH, - 44); + testFormatAndAdditionalHeaderConstructor(HICN_PACKET_FORMAT_IPV6_ICMP_AH, 44); } TEST_F(PacketTest, ConstructorWithNew) { - auto &_packet = raw_packets_[HF_INET6_TCP]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; auto packet_ptr = new PacketForTest(Packet::WRAP_BUFFER, &_packet[0], _packet.size(), _packet.size()); delete packet_ptr; } TEST_F(PacketTest, ConstructorWithRawBufferInet6Tcp) { - auto format = Packet::Format::HF_INET6_TCP; - testRawBufferConstructor(raw_packets_[format], format); + auto format = HICN_PACKET_FORMAT_IPV6_TCP; + testRawBufferConstructor(raw_packets_[format.as_u32], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetTcp) { - auto format = Packet::Format::HF_INET_TCP; - testRawBufferConstructor(raw_packets_[format], format); + auto format = HICN_PACKET_FORMAT_IPV4_TCP; + testRawBufferConstructor(raw_packets_[format.as_u32], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetIcmp) { - auto format = Packet::Format::HF_INET_ICMP; - testRawBufferConstructor(raw_packets_[format], format); + auto format = HICN_PACKET_FORMAT_IPV4_ICMP; + testRawBufferConstructor(raw_packets_[format.as_u32], format); } TEST_F(PacketTest, ConstructorWithRawBufferInet6Icmp) { - auto format = Packet::Format::HF_INET6_ICMP; - testRawBufferConstructor(raw_packets_[format], format); + auto format = HICN_PACKET_FORMAT_IPV6_ICMP; + testRawBufferConstructor(raw_packets_[format.as_u32], format); } TEST_F(PacketTest, ConstructorWithRawBufferInet6TcpAh) { - auto format = Packet::Format::HF_INET6_TCP_AH; - testRawBufferConstructor(raw_packets_[format], format); + auto format = HICN_PACKET_FORMAT_IPV6_TCP_AH; + testRawBufferConstructor(raw_packets_[format.as_u32], format); } TEST_F(PacketTest, ConstructorWithRawBufferInetTcpAh) { - auto format = Packet::Format::HF_INET_TCP_AH; - testRawBufferConstructor(raw_packets_[format], format); + auto format = HICN_PACKET_FORMAT_IPV4_TCP_AH; + testRawBufferConstructor(raw_packets_[format.as_u32], format); } TEST_F(PacketTest, MoveConstructor) { - PacketForTest p0(Packet::Format::HF_INET6_TCP); + PacketForTest p0(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP); PacketForTest p1(std::move(p0)); - EXPECT_EQ(p0.getFormat(), Packet::Format::HF_UNSPEC); - EXPECT_EQ(p1.getFormat(), Packet::Format::HF_INET6_TCP); + 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); } TEST_F(PacketTest, TestGetHeaderSizeFromBuffer) { - getHeaderSizeFromBuffer(HF_INET6_TCP, raw_packets_[HF_INET6_TCP], - HICN_V6_TCP_HDRLEN); - getHeaderSizeFromBuffer(HF_INET_TCP, raw_packets_[HF_INET_TCP], - HICN_V4_TCP_HDRLEN); - getHeaderSizeFromBuffer(HF_INET6_ICMP, raw_packets_[HF_INET6_ICMP], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32], + IPV6_HDRLEN + TCP_HDRLEN); + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32], + IPV4_HDRLEN + TCP_HDRLEN); + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32], IPV6_HDRLEN + 4); - getHeaderSizeFromBuffer(HF_INET_ICMP, raw_packets_[HF_INET_ICMP], + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32], IPV4_HDRLEN + 4); - getHeaderSizeFromBuffer(HF_INET6_TCP_AH, raw_packets_[HF_INET6_TCP_AH], - HICN_V6_TCP_AH_HDRLEN + 128); - getHeaderSizeFromBuffer(HF_INET_TCP_AH, raw_packets_[HF_INET_TCP_AH], - HICN_V4_TCP_AH_HDRLEN + 128); + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32], + IPV6_HDRLEN + TCP_HDRLEN + AH_HDRLEN + 128); + getHeaderSizeFromBuffer(raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32], + IPV4_HDRLEN + TCP_HDRLEN + AH_HDRLEN + 128); } TEST_F(PacketTest, TestGetHeaderSizeFromFormat) { - getHeaderSizeFromFormat(HF_INET6_TCP, HICN_V6_TCP_HDRLEN); - getHeaderSizeFromFormat(HF_INET_TCP, HICN_V4_TCP_HDRLEN); - getHeaderSizeFromFormat(HF_INET6_ICMP, IPV6_HDRLEN + 4); - getHeaderSizeFromFormat(HF_INET_ICMP, IPV4_HDRLEN + 4); - getHeaderSizeFromFormat(HF_INET6_TCP_AH, HICN_V6_TCP_AH_HDRLEN); - getHeaderSizeFromFormat(HF_INET_TCP_AH, HICN_V4_TCP_AH_HDRLEN); + getHeaderSizeFromFormat(HICN_PACKET_FORMAT_IPV6_TCP, + IPV6_HDRLEN + TCP_HDRLEN); + getHeaderSizeFromFormat(HICN_PACKET_FORMAT_IPV4_TCP, + IPV4_HDRLEN + TCP_HDRLEN); + getHeaderSizeFromFormat(HICN_PACKET_FORMAT_IPV6_ICMP, IPV6_HDRLEN + 4); + getHeaderSizeFromFormat(HICN_PACKET_FORMAT_IPV4_ICMP, IPV4_HDRLEN + 4); + getHeaderSizeFromFormat(HICN_PACKET_FORMAT_IPV6_TCP_AH, + IPV6_HDRLEN + TCP_HDRLEN + AH_HDRLEN); + getHeaderSizeFromFormat(HICN_PACKET_FORMAT_IPV4_TCP_AH, + IPV4_HDRLEN + TCP_HDRLEN + AH_HDRLEN); } TEST_F(PacketTest, TestGetPayloadSizeFromBuffer) { - getPayloadSizeFromBuffer(HF_INET6_TCP, raw_packets_[HF_INET6_TCP], 12); - getPayloadSizeFromBuffer(HF_INET_TCP, raw_packets_[HF_INET_TCP], 12); - getPayloadSizeFromBuffer(HF_INET6_ICMP, raw_packets_[HF_INET6_ICMP], 56); - getPayloadSizeFromBuffer(HF_INET_ICMP, raw_packets_[HF_INET_ICMP], 60); - getPayloadSizeFromBuffer(HF_INET6_TCP_AH, raw_packets_[HF_INET6_TCP_AH], 0); - getPayloadSizeFromBuffer(HF_INET_TCP_AH, raw_packets_[HF_INET_TCP_AH], 0); -} - + 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); +} + +#if 0 TEST_F(PacketTest, TestIsInterest) { - auto ret = PacketForTest::isInterest(&raw_packets_[HF_INET6_TCP][0]); + auto ret = PacketForTest::isInterest(&raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32][0]); EXPECT_TRUE(ret); } +#endif TEST_F(PacketTest, TestGetFormatFromBuffer) { - getFormatFromBuffer(HF_INET6_TCP, raw_packets_[HF_INET6_TCP]); - getFormatFromBuffer(HF_INET_TCP, raw_packets_[HF_INET_TCP]); - getFormatFromBuffer(HF_INET6_ICMP, raw_packets_[HF_INET6_ICMP]); - getFormatFromBuffer(HF_INET_ICMP, raw_packets_[HF_INET_ICMP]); - getFormatFromBuffer(HF_INET6_TCP_AH, raw_packets_[HF_INET6_TCP_AH]); - getFormatFromBuffer(HF_INET_TCP_AH, raw_packets_[HF_INET_TCP_AH]); + getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_TCP, + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]); + getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_TCP, + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32]); + getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_ICMP, + raw_packets_[HICN_PACKET_FORMAT_IPV6_ICMP.as_u32]); + getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_ICMP, + raw_packets_[HICN_PACKET_FORMAT_IPV4_ICMP.as_u32]); + getFormatFromBuffer(HICN_PACKET_FORMAT_IPV6_TCP_AH, + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP_AH.as_u32]); + getFormatFromBuffer(HICN_PACKET_FORMAT_IPV4_TCP_AH, + raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP_AH.as_u32]); } // TEST_F(PacketTest, TestReplace) { -// PacketForTest packet(Packet::WRAP_BUFFER, &raw_packets_[HF_INET6_TCP][0], -// raw_packets_[HF_INET6_TCP].size()); +// 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()); // // Replace current packet with another one -// packet.replace(&raw_packets_[HF_INET_TCP][0], -// raw_packets_[HF_INET_TCP].size()); +// packet.replace(&raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32][0], +// raw_packets_[HICN_PACKET_FORMAT_IPV4_TCP.as_u32].size()); // // Check new format -// ASSERT_EQ(packet.getFormat(), HF_INET_TCP); +// ASSERT_EQ(packet.getFormat(), HICN_PACKET_FORMAT_IPV4_TCP); // } TEST_F(PacketTest, TestPayloadSize) { // Check payload size of existing packet - auto &_packet = raw_packets_[HF_INET6_TCP]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; PacketForTest packet(Packet::WRAP_BUFFER, &_packet[0], _packet.size(), _packet.size()); @@ -415,7 +440,7 @@ TEST_F(PacketTest, TestPayloadSize) { std::string payload0(1024, 'X'); // Create the packet - PacketForTest packet2(HF_INET6_TCP); + PacketForTest packet2(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP); // Payload size should now be zero EXPECT_EQ(packet2.payloadSize(), std::size_t(0)); @@ -442,22 +467,29 @@ TEST_F(PacketTest, TestPayloadSize) { } TEST_F(PacketTest, TestHeaderSize) { - getHeaderSize(HICN_V6_TCP_HDRLEN, - PacketForTest(Packet::Format::HF_INET6_TCP)); - getHeaderSize(HICN_V4_TCP_HDRLEN, PacketForTest(Packet::Format::HF_INET_TCP)); - getHeaderSize(HICN_V6_ICMP_HDRLEN, - PacketForTest(Packet::Format::HF_INET6_ICMP)); - getHeaderSize(HICN_V4_ICMP_HDRLEN, - PacketForTest(Packet::Format::HF_INET_ICMP)); - getHeaderSize(HICN_V6_TCP_AH_HDRLEN, - PacketForTest(Packet::Format::HF_INET6_TCP_AH)); - getHeaderSize(HICN_V4_TCP_AH_HDRLEN, - PacketForTest(Packet::Format::HF_INET_TCP_AH)); + getHeaderSize( + IPV6_HDRLEN + TCP_HDRLEN, + PacketForTest(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP)); + getHeaderSize( + IPV4_HDRLEN + TCP_HDRLEN, + PacketForTest(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV4_TCP)); + getHeaderSize( + IPV6_HDRLEN + ICMP_HDRLEN, + PacketForTest(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_ICMP)); + getHeaderSize( + IPV4_HDRLEN + ICMP_HDRLEN, + PacketForTest(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV4_ICMP)); + getHeaderSize( + IPV6_HDRLEN + TCP_HDRLEN + AH_HDRLEN, + PacketForTest(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP_AH)); + getHeaderSize( + IPV4_HDRLEN + TCP_HDRLEN + AH_HDRLEN, + PacketForTest(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV4_TCP_AH)); } TEST_F(PacketTest, TestMemBufReference) { // Create packet - auto &_packet = raw_packets_[HF_INET6_TCP]; + auto &_packet = raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32]; // Packet was not created as a shared_ptr. If we try to get a membuf shared // ptr we should get an exception. @@ -498,16 +530,17 @@ TEST_F(PacketTest, TestMemBufReference) { TEST_F(PacketTest, TestReset) { // Check everything is ok - EXPECT_EQ(packet.getFormat(), HF_INET6_TCP); - EXPECT_EQ(packet.length(), raw_packets_[HF_INET6_TCP].size()); - EXPECT_EQ(packet.headerSize(), HICN_V6_TCP_HDRLEN); + 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.headerSize(), IPV6_HDRLEN + TCP_HDRLEN); EXPECT_EQ(packet.payloadSize(), packet.length() - packet.headerSize()); // Reset the packet packet.reset(); // Rerun test - EXPECT_EQ(packet.getFormat(), HF_UNSPEC); + EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); EXPECT_EQ(packet.length(), std::size_t(0)); EXPECT_EQ(packet.headerSize(), std::size_t(0)); EXPECT_EQ(packet.payloadSize(), std::size_t(0)); @@ -548,7 +581,7 @@ TEST_F(PacketTest, TestAppendPayload) { // There should be no more bufferls left in the chain EXPECT_EQ(&packet, packet.next()); - EXPECT_EQ(packet.getFormat(), HF_UNSPEC); + EXPECT_EQ(packet.getFormat().as_u32, HICN_PACKET_FORMAT_NONE.as_u32); EXPECT_EQ(packet.length(), std::size_t(0)); EXPECT_EQ(packet.headerSize(), std::size_t(0)); EXPECT_EQ(packet.payloadSize(), std::size_t(0)); @@ -557,6 +590,7 @@ TEST_F(PacketTest, TestAppendPayload) { TEST_F(PacketTest, GetPayload) { // Append payload with raw buffer uint8_t raw_buffer[2048]; + memset(raw_buffer, 0, sizeof(raw_buffer)); auto original_payload_length = packet.payloadSize(); packet.appendPayload(raw_buffer, 2048); @@ -621,61 +655,63 @@ TEST_F(PacketTest, SetGetPayloadType) { TEST_F(PacketTest, GetFormat) { { PacketForTest p0(Packet::WRAP_BUFFER, - &raw_packets_[Packet::Format::HF_INET_TCP][0], - raw_packets_[Packet::Format::HF_INET_TCP].size(), - raw_packets_[Packet::Format::HF_INET_TCP].size()); - testGetFormat(Packet::Format::HF_INET_TCP, p0); + &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()); + testGetFormat(HICN_PACKET_FORMAT_IPV4_TCP, p0); PacketForTest p1(Packet::WRAP_BUFFER, - &raw_packets_[Packet::Format::HF_INET6_TCP][0], - raw_packets_[Packet::Format::HF_INET6_TCP].size(), - raw_packets_[Packet::Format::HF_INET6_TCP].size()); - testGetFormat(Packet::Format::HF_INET6_TCP, p1); + &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()); + testGetFormat(HICN_PACKET_FORMAT_IPV6_TCP, p1); PacketForTest p2(Packet::WRAP_BUFFER, - &raw_packets_[Packet::Format::HF_INET_ICMP][0], - raw_packets_[Packet::Format::HF_INET_ICMP].size(), - raw_packets_[Packet::Format::HF_INET_ICMP].size()); - testGetFormat(Packet::Format::HF_INET_ICMP, p2); + &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()); + testGetFormat(HICN_PACKET_FORMAT_IPV4_ICMP, p2); PacketForTest p3(Packet::WRAP_BUFFER, - &raw_packets_[Packet::Format::HF_INET6_ICMP][0], - raw_packets_[Packet::Format::HF_INET6_ICMP].size(), - raw_packets_[Packet::Format::HF_INET6_ICMP].size()); - testGetFormat(Packet::Format::HF_INET6_ICMP, p3); - - PacketForTest p4(Packet::WRAP_BUFFER, - &raw_packets_[Packet::Format::HF_INET_TCP_AH][0], - raw_packets_[Packet::Format::HF_INET_TCP_AH].size(), - raw_packets_[Packet::Format::HF_INET_TCP_AH].size()); - testGetFormat(Packet::Format::HF_INET_TCP_AH, p4); - - PacketForTest p5(Packet::WRAP_BUFFER, - &raw_packets_[Packet::Format::HF_INET6_TCP_AH][0], - raw_packets_[Packet::Format::HF_INET6_TCP_AH].size(), - raw_packets_[Packet::Format::HF_INET6_TCP_AH].size()); - testGetFormat(Packet::Format::HF_INET6_TCP_AH, p5); + &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()); + 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()); + 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()); + testGetFormat(HICN_PACKET_FORMAT_IPV6_TCP_AH, p5); } // Let's try now creating empty packets { - PacketForTest p0(Packet::Format::HF_INET_TCP); - testGetFormat(Packet::Format::HF_INET_TCP, p0); + PacketForTest p0(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV4_TCP); + testGetFormat(HICN_PACKET_FORMAT_IPV4_TCP, p0); - PacketForTest p1(Packet::Format::HF_INET6_TCP); - testGetFormat(Packet::Format::HF_INET6_TCP, p1); + PacketForTest p1(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP); + testGetFormat(HICN_PACKET_FORMAT_IPV6_TCP, p1); - PacketForTest p2(Packet::Format::HF_INET_ICMP); - testGetFormat(Packet::Format::HF_INET_ICMP, p2); + PacketForTest p2(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV4_ICMP); + testGetFormat(HICN_PACKET_FORMAT_IPV4_ICMP, p2); - PacketForTest p3(Packet::Format::HF_INET6_ICMP); - testGetFormat(Packet::Format::HF_INET6_ICMP, p3); + PacketForTest p3(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_ICMP); + testGetFormat(HICN_PACKET_FORMAT_IPV6_ICMP, p3); - PacketForTest p4(Packet::Format::HF_INET_TCP_AH); - testGetFormat(Packet::Format::HF_INET_TCP_AH, p4); + PacketForTest p4(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV4_TCP_AH); + testGetFormat(HICN_PACKET_FORMAT_IPV4_TCP_AH, p4); - PacketForTest p5(Packet::Format::HF_INET6_TCP_AH); - testGetFormat(Packet::Format::HF_INET6_TCP_AH, p5); + PacketForTest p5(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP_AH); + testGetFormat(HICN_PACKET_FORMAT_IPV6_TCP_AH, p5); } } @@ -707,7 +743,7 @@ TEST_F(PacketTest, SetGetTestSignatureTimestamp) { } // Now let's construct a AH packet, with no additional space for signature - PacketForTest p(HF_INET6_TCP_AH); + PacketForTest p(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP_AH); p.setSignatureTimestamp(now); uint64_t now_get = p.getSignatureTimestamp(); @@ -741,7 +777,7 @@ TEST_F(PacketTest, TestSetGetValidationAlgorithm) { } // Now let's construct a AH packet, with no additional space for signature - PacketForTest p(HF_INET6_TCP_AH); + PacketForTest p(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP_AH); p.setValidationAlgorithm(auth::CryptoSuite::RSA_SHA256); auto v_get = p.getValidationAlgorithm(); @@ -751,6 +787,7 @@ TEST_F(PacketTest, TestSetGetValidationAlgorithm) { TEST_F(PacketTest, TestSetGetKeyId) { uint8_t key[32]; + memset(key, 0, sizeof(key)); auth::KeyId key_id = std::make_pair(key, sizeof(key)); try { @@ -762,7 +799,7 @@ TEST_F(PacketTest, TestSetGetKeyId) { FAIL() << "Unexpected exception"; } - // Same fot get method + // Same for get method try { auto k = packet.getKeyId(); // Let's make compiler happy @@ -775,7 +812,7 @@ TEST_F(PacketTest, TestSetGetKeyId) { } // Now let's construct a AH packet, with no additional space for signature - PacketForTest p(HF_INET6_TCP_AH); + PacketForTest p(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP_AH); p.setKeyId(key_id); auto p_get = p.getKeyId(); @@ -799,7 +836,8 @@ TEST_F(PacketTest, DISABLED_TestChecksum) { EXPECT_TRUE(integrity); // Check with AH header and 300 bytes signature - PacketForTest p(HF_INET6_TCP_AH, 300); + PacketForTest p(HICN_PACKET_TYPE_INTEREST, HICN_PACKET_FORMAT_IPV6_TCP_AH, + 300); std::string payload(5000, 'X'); p.appendPayload((const uint8_t *)payload.c_str(), payload.size() / 2); p.appendPayload((const uint8_t *)(payload.c_str() + payload.size() / 2), @@ -810,116 +848,13 @@ TEST_F(PacketTest, DISABLED_TestChecksum) { EXPECT_TRUE(integrity); } -TEST_F(PacketTest, TestSetSyn) { - // Test syn of non-tcp format and check exception is thrown - try { - auto p = PacketForTest(Packet::WRAP_BUFFER, &raw_packets_[HF_INET6_ICMP][0], - raw_packets_[HF_INET6_ICMP].size(), - raw_packets_[HF_INET6_ICMP].size()); - // Let's make compiler happy - p.setSyn(); - FAIL() << "We should not reach this point."; - } catch (const errors::RuntimeException &exc) { - /* ok right exception*/ - } catch (...) { - FAIL() << "Unexpected exception"; - } - - packet.setSyn(); - EXPECT_TRUE(packet.testSyn()); - - packet.resetSyn(); - EXPECT_FALSE(packet.testSyn()); -} - -TEST_F(PacketTest, TestSetFin) { - // Test syn of non-tcp format and check exception is thrown - try { - auto p = PacketForTest(Packet::WRAP_BUFFER, &raw_packets_[HF_INET6_ICMP][0], - raw_packets_[HF_INET6_ICMP].size(), - raw_packets_[HF_INET6_ICMP].size()); - // Let's make compiler happy - p.setFin(); - FAIL() << "We should not reach this point."; - } catch (const errors::RuntimeException &exc) { - /* ok right exception*/ - } catch (...) { - FAIL() << "Unexpected exception"; - } - - packet.setFin(); - EXPECT_TRUE(packet.testFin()); - - packet.resetFin(); - EXPECT_FALSE(packet.testFin()); -} - -TEST_F(PacketTest, TestSetAck) { - // Test syn of non-tcp format and check exception is thrown - try { - auto p = PacketForTest(Packet::WRAP_BUFFER, &raw_packets_[HF_INET6_ICMP][0], - raw_packets_[HF_INET6_ICMP].size(), - raw_packets_[HF_INET6_ICMP].size()); - // Let's make compiler happy - p.setAck(); - FAIL() << "We should not reach this point."; - } catch (const errors::RuntimeException &exc) { - /* ok right exception*/ - } catch (...) { - FAIL() << "Unexpected exception"; - } - - packet.setAck(); - EXPECT_TRUE(packet.testAck()); - - packet.resetAck(); - EXPECT_FALSE(packet.testAck()); -} - -TEST_F(PacketTest, TestSetRst) { - // Test syn of non-tcp format and check exception is thrown - try { - auto p = PacketForTest(Packet::WRAP_BUFFER, &raw_packets_[HF_INET6_ICMP][0], - raw_packets_[HF_INET6_ICMP].size(), - raw_packets_[HF_INET6_ICMP].size()); - // Let's make compiler happy - p.setRst(); - FAIL() << "We should not reach this point."; - } catch (const errors::RuntimeException &exc) { - /* ok right exception*/ - } catch (...) { - FAIL() << "Unexpected exception"; - } - - packet.setRst(); - EXPECT_TRUE(packet.testRst()); - - packet.resetRst(); - EXPECT_FALSE(packet.testRst()); -} - -TEST_F(PacketTest, TestResetFlags) { - packet.setRst(); - packet.setSyn(); - packet.setAck(); - packet.setFin(); - EXPECT_TRUE(packet.testRst()); - EXPECT_TRUE(packet.testAck()); - EXPECT_TRUE(packet.testFin()); - EXPECT_TRUE(packet.testSyn()); - - packet.resetFlags(); - EXPECT_FALSE(packet.testRst()); - EXPECT_FALSE(packet.testAck()); - EXPECT_FALSE(packet.testFin()); - EXPECT_FALSE(packet.testSyn()); -} - TEST_F(PacketTest, TestSetGetSrcPort) { try { - auto p = PacketForTest(Packet::WRAP_BUFFER, &raw_packets_[HF_INET6_ICMP][0], - raw_packets_[HF_INET6_ICMP].size(), - raw_packets_[HF_INET6_ICMP].size()); + 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."; @@ -935,9 +870,11 @@ TEST_F(PacketTest, TestSetGetSrcPort) { TEST_F(PacketTest, TestSetGetDstPort) { try { - auto p = PacketForTest(Packet::WRAP_BUFFER, &raw_packets_[HF_INET6_ICMP][0], - raw_packets_[HF_INET6_ICMP].size(), - raw_packets_[HF_INET6_ICMP].size()); + 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."; @@ -955,58 +892,73 @@ TEST_F(PacketTest, TestEnsureCapacity) { PacketForTest &p = packet; // This shoul be false - auto ret = p.ensureCapacity(raw_packets_[HF_INET6_TCP].size() + 10); + auto ret = p.ensureCapacity( + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() + 10); EXPECT_FALSE(ret); // This should be true - ret = p.ensureCapacity(raw_packets_[HF_INET6_TCP].size()); + ret = + p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); EXPECT_TRUE(ret); // This should be true - ret = p.ensureCapacity(raw_packets_[HF_INET6_TCP].size() - 10); + ret = p.ensureCapacity( + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - 10); EXPECT_TRUE(ret); // Try to trim the packet start p.trimStart(10); // Now this should be false - ret = p.ensureCapacity(raw_packets_[HF_INET6_TCP].size()); + ret = + p.ensureCapacity(raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size()); EXPECT_FALSE(ret); // Create a new packet - auto p2 = PacketForTest(Packet::WRAP_BUFFER, &raw_packets_[HF_INET6_ICMP][0], - raw_packets_[HF_INET6_ICMP].size(), - raw_packets_[HF_INET6_ICMP].size()); + 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()); p2.appendPayload(utils::MemBuf::createCombined(2000)); // This should be false, since the buffer is chained - ret = p2.ensureCapacity(raw_packets_[HF_INET6_TCP].size() - 10); + ret = p2.ensureCapacity( + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - 10); EXPECT_FALSE(ret); } -TEST_F(PacketTest, TestEnsureCapacityAndFillUnused) { +// +// This test is disabled as it manipulates a ipv6 header with the wrong payload +// length inside. +// +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_[HF_INET6_TCP][0], - raw_packets_[HF_INET6_TCP].size() - PAYLOAD_SIZE, - raw_packets_[HF_INET6_TCP].size()); + 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()); // Copy original packet payload, which is here trated as a unused tailroom uint8_t original_payload[PAYLOAD_SIZE]; - uint8_t *payload = &raw_packets_[HF_INET6_TCP][0] + - raw_packets_[HF_INET6_TCP].size() - 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() - + 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_[HF_INET6_TCP].size() - (PAYLOAD_SIZE + 10), 0); + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() - + (PAYLOAD_SIZE + 10), + 0); EXPECT_TRUE(ret); ret = std::memcmp(original_payload, payload, PAYLOAD_SIZE); EXPECT_EQ(ret, 0); // This should fill the payload with zeros - ret = p.ensureCapacityAndFillUnused(raw_packets_[HF_INET6_TCP].size(), 0); + ret = p.ensureCapacityAndFillUnused( + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size(), 0); EXPECT_TRUE(ret); uint8_t zeros[PAYLOAD_SIZE]; std::memset(zeros, 0, PAYLOAD_SIZE); @@ -1014,7 +966,8 @@ TEST_F(PacketTest, TestEnsureCapacityAndFillUnused) { EXPECT_EQ(ret, 0); // This should fill the payload with ones - ret = p.ensureCapacityAndFillUnused(raw_packets_[HF_INET6_TCP].size(), 1); + ret = p.ensureCapacityAndFillUnused( + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size(), 1); EXPECT_TRUE(ret); uint8_t ones[PAYLOAD_SIZE]; std::memset(ones, 1, PAYLOAD_SIZE); @@ -1022,7 +975,8 @@ TEST_F(PacketTest, TestEnsureCapacityAndFillUnused) { EXPECT_EQ(ret, 0); // This should return false and the payload should be unmodified - ret = p.ensureCapacityAndFillUnused(raw_packets_[HF_INET6_TCP].size() + 1, 1); + ret = p.ensureCapacityAndFillUnused( + raw_packets_[HICN_PACKET_FORMAT_IPV6_TCP.as_u32].size() + 1, 1); EXPECT_FALSE(ret); ret = std::memcmp(payload, ones, PAYLOAD_SIZE); EXPECT_EQ(ret, 0); diff --git a/libtransport/src/test/test_packet_allocator.cc b/libtransport/src/test/test_packet_allocator.cc index 744f1bd24..0de35a817 100644 --- a/libtransport/src/test/test_packet_allocator.cc +++ b/libtransport/src/test/test_packet_allocator.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Cisco and/or its affiliates. + * Copyright (c) 2021-2022 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -70,11 +70,11 @@ class PacketAllocatorTest : public ::testing::Test { }; TEST_F(PacketAllocatorTest, ContentObjectAllocation) { - allocationTest<core::ContentObject>(HF_INET_TCP); + allocationTest<core::ContentObject>(HICN_PACKET_FORMAT_IPV4_TCP); } TEST_F(PacketAllocatorTest, InterestAllocation) { - allocationTest<core::Interest>(HF_INET_TCP); + allocationTest<core::Interest>(HICN_PACKET_FORMAT_IPV4_TCP); } // TEST_F(PacketAllocatorTest, MemBufAllocation) { @@ -83,7 +83,8 @@ TEST_F(PacketAllocatorTest, InterestAllocation) { TEST_F(PacketAllocatorTest, CheckAllocationIsCorrect) { // Create packet - auto packet = allocator_.getPacket<core::ContentObject>(HF_INET_TCP); + auto packet = + allocator_.getPacket<core::ContentObject>(HICN_PACKET_FORMAT_IPV4_TCP); // Address of actual buffer uint8_t *buffer_address = packet->writableData(); @@ -128,4 +129,4 @@ TEST_F(PacketAllocatorTest, CheckAllocationSpeed) { } } // namespace core -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/src/test/test_prefix.cc b/libtransport/src/test/test_prefix.cc index 5de737566..3eab72bcb 100644 --- a/libtransport/src/test/test_prefix.cc +++ b/libtransport/src/test/test_prefix.cc @@ -194,47 +194,47 @@ TEST_F(PrefixTest, SetGetNetwork) { TEST_F(PrefixTest, Contains) { // IPv6 prefix Prefix p0(prefix_str0); - ip_address_t ip0, ip1; + hicn_ip_address_t ip0, ip1; - ip_address_pton("2001:db8:1::1234", &ip0); - ip_address_pton("2001:db9:1::1234", &ip1); + hicn_ip_address_pton("2001:db8:1::1234", &ip0); + hicn_ip_address_pton("2001:db9:1::1234", &ip1); EXPECT_TRUE(p0.contains(ip0)); EXPECT_FALSE(p0.contains(ip1)); Prefix p1(prefix_str1); - ip_address_pton("10.11.12.12", &ip0); - ip_address_pton("10.12.12.13", &ip1); + hicn_ip_address_pton("10.11.12.12", &ip0); + hicn_ip_address_pton("10.12.12.13", &ip1); EXPECT_TRUE(p1.contains(ip0)); EXPECT_FALSE(p1.contains(ip1)); Prefix p2(prefix_str2); - ip_address_pton("2001:db8:1::dbca", &ip0); - ip_address_pton("10.12.12.12", &ip1); + hicn_ip_address_pton("2001:db8:1::dbca", &ip0); + hicn_ip_address_pton("10.12.12.12", &ip1); EXPECT_TRUE(p2.contains(ip0)); EXPECT_FALSE(p2.contains(ip1)); Prefix p3(prefix_str3); - ip_address_pton("10.11.12.245", &ip0); - ip_address_pton("10.11.12.1", &ip1); + hicn_ip_address_pton("10.11.12.245", &ip0); + hicn_ip_address_pton("10.11.12.1", &ip1); EXPECT_TRUE(p3.contains(ip0)); EXPECT_FALSE(p3.contains(ip1)); // Corner cases Prefix p4("::/0"); - ip_address_pton("7001:db8:1::1234", &ip0); - ip_address_pton("8001:db8:1::1234", &ip1); + hicn_ip_address_pton("7001:db8:1::1234", &ip0); + hicn_ip_address_pton("8001:db8:1::1234", &ip1); EXPECT_TRUE(p4.contains(ip0)); EXPECT_TRUE(p4.contains(ip1)); // Corner cases Prefix p5("b001:a:b:c:d:e:f:1/128"); - ip_address_pton("b001:a:b:c:d:e:f:1", &ip0); - ip_address_pton("b001:a:b:c:d:e:f:2", &ip1); + hicn_ip_address_pton("b001:a:b:c:d:e:f:1", &ip0); + hicn_ip_address_pton("b001:a:b:c:d:e:f:2", &ip1); EXPECT_TRUE(p5.contains(ip0)); EXPECT_FALSE(p5.contains(ip1)); @@ -331,4 +331,4 @@ TEST_F(PrefixTest, MakeNameWithIndex) { } // namespace } // namespace core -} // namespace transport
\ No newline at end of file +} // namespace transport |