diff options
author | Luca Muscariello <muscariello@ieee.org> | 2021-04-15 09:05:46 +0200 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2021-04-15 16:36:16 +0200 |
commit | e92e9e839ca2cf42b56322b2489ccc0d8bf767af (patch) | |
tree | 9f1647c83a87fbf982ae329e800af25dbfb226b5 /libtransport/includes/hicn/transport/core/packet.h | |
parent | 3e541d7c947cc2f9db145f26c9274efd29a6fb56 (diff) |
[HICN-690] Transport Library Major Refactory
The current patch provides a major refactory of the transportlibrary.
A summary of the different components that underwent major modifications is
reported below.
- Transport protocol updates
The hierarchy of classes has been optimized to have common transport services
across different transport protocols. This can allow to customize a transport
protocol with new features.
- A new real-time communication protocol
The RTC protocol has been optimized in terms of algorithms to reduce
consumer-producer synchronization latency.
- A novel socket API
The API has been reworked to be easier to consumer but also to have a more
efficient integration in L4 proxies.
- Several performance improvements
A large number of performance improvements have been included in
particular to make the entire stack zero-copy and optimize cache miss.
- New memory buffer framework
Memory management has been reworked entirely to provide a more efficient infra
with a richer API. Buffers are now allocated in blocks and a single buffer
holds the memory for (1) the shared_ptr control block, (2) the metadata of the
packet (e.g. name, pointer to other buffers if buffer is chained and relevant
offsets), and (3) the packet itself, as it is sent/received over the network.
- A new slab allocator
Dynamic memory allocation is now managed by a novel slab allocator that is
optimised for packet processing and connection management. Memory is organized
in pools of blocks all of the same size which are used during the processing of
outgoing/incoming packets. When a memory block Is allocated is always taken
from a global pool and when it is deallocated is returned to the pool, thus
avoiding the cost of any heap allocation in the data path.
- New transport connectors
Consumer and producer end-points can communication either using an hicn packet
forwarder or with direct connector based on shared memories or sockets.
The usage of transport connectors typically for unit and funcitonal
testing but may have additional usage.
- Support for FEC/ECC for transport services
FEC/ECC via reed solomon is supported by default and made available to
transport services as a modular component. Reed solomon block codes is a
default FEC model that can be replaced in a modular way by many other
codes including RLNC not avaiable in this distribution.
The current FEC framework support variable size padding and efficiently
makes use of the infra memory buffers to avoid additiona copies.
- Secure transport framework for signature computation and verification
Crypto support is nativelty used in hICN for integrity and authenticity.
Novel support that includes RTC has been implemented and made modular
and reusable acrosso different transport protocols.
- TLS - Transport layer security over hicn
Point to point confidentiality is provided by integrating TLS on top of
hICN reliable and non-reliable transport. The integration is common and
makes a different use of the TLS record.
- MLS - Messaging layer security over hicn
MLS integration on top of hICN is made by using the MLSPP implemetation
open sourced by Cisco. We have included instrumentation tools to deploy
performance and functional tests of groups of end-points.
- Android support
The overall code has been heavily tested in Android environments and
has received heavy lifting to better run natively in recent Android OS.
Co-authored-by: Mauro Sardara <msardara@cisco.com>
Co-authored-by: Michele Papalini <micpapal@cisco.com>
Co-authored-by: Olivier Roques <oroques+fdio@cisco.com>
Co-authored-by: Giulio Grassi <gigrassi@cisco.com>
Change-Id: If477ba2fa686e6f47bdf96307ac60938766aef69
Signed-off-by: Luca Muscariello <muscariello@ieee.org>
Diffstat (limited to 'libtransport/includes/hicn/transport/core/packet.h')
-rw-r--r-- | libtransport/includes/hicn/transport/core/packet.h | 143 |
1 files changed, 64 insertions, 79 deletions
diff --git a/libtransport/includes/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h index 91f957964..68daea841 100644 --- a/libtransport/includes/hicn/transport/core/packet.h +++ b/libtransport/includes/hicn/transport/core/packet.h @@ -19,21 +19,15 @@ #include <hicn/transport/core/payload_type.h> #include <hicn/transport/errors/malformed_packet_exception.h> #include <hicn/transport/portability/portability.h> -#include <hicn/transport/security/crypto_hasher.h> -#include <hicn/transport/security/crypto_suite.h> -#include <hicn/transport/security/key_id.h> +#include <hicn/transport/auth/crypto_hasher.h> +#include <hicn/transport/auth/crypto_suite.h> +#include <hicn/transport/auth/key_id.h> #include <hicn/transport/utils/branch_prediction.h> #include <hicn/transport/utils/log.h> #include <hicn/transport/utils/membuf.h> #include <hicn/transport/utils/object_pool.h> -namespace utils { -class Signer; -class Verifier; -} // namespace utils - namespace transport { - namespace core { /* @@ -45,11 +39,13 @@ namespace core { * \_______________________________________| */ -class Packet : public std::enable_shared_from_this<Packet> { - friend class utils::Signer; - friend class utils::Verifier; +class Packet : public utils::MemBuf, + public std::enable_shared_from_this<Packet> { + friend class auth::Signer; + friend class auth::Verifier; public: + using Ptr = std::shared_ptr<Packet>; using MemBufPtr = std::shared_ptr<utils::MemBuf>; using Format = hicn_format_t; static constexpr size_t default_mtu = 1500; @@ -59,24 +55,29 @@ class Packet : public std::enable_shared_from_this<Packet> { * the eventual payload will be added by prepending the payload buffer * to the buffer chain whose the fist buffer is the header itself. */ - Packet(Format format = HF_UNSPEC); + Packet(Format format = HF_INET6_TCP, std::size_t additional_header_size = 0); /** * Create new IP packet using raw buffer. */ - Packet(const uint8_t *buffer, std::size_t size); - Packet(MemBufPtr &&buffer); - /* - * Enforce zero-copy lifestyle. - */ - Packet(const Packet &other) = delete; - Packet &operator=(const Packet &other) = delete; + /* Copy buffer */ + Packet(CopyBufferOp, const uint8_t *buffer, std::size_t size); + /* Wrap buffer */ + Packet(WrapBufferOp, uint8_t *buffer, std::size_t length, std::size_t size); + /* Create new using pre-allocated buffer */ + Packet(CreateOp, uint8_t *buffer, std::size_t length, std::size_t size, + Format format = HF_INET6_TCP, std::size_t additional_header_size = 0); + /* Move MemBuf */ + Packet(MemBuf &&buffer); + + Packet(Packet &&other); /* - * Move constructor. + * Copy constructor and assignemnt operators. */ - Packet(Packet &&other); + Packet(const Packet &other); + Packet &operator=(const Packet &other); friend bool operator==(const Packet &l_packet, const Packet &r_packet); @@ -98,36 +99,35 @@ class Packet : public std::enable_shared_from_this<Packet> { static bool isInterest(const uint8_t *buffer); + bool isInterest(); + static Format getFormatFromBuffer(const uint8_t *buffer, std::size_t length) { Format format = HF_UNSPEC; - - if (TRANSPORT_EXPECT_FALSE( - hicn_packet_get_format((const hicn_header_t *)buffer, &format) < - 0)) { - TRANSPORT_LOGE( - "Error while getting format from packet buffer. Packet will be " - "discarded."); - hicn_packet_dump(buffer, length); - } - + hicn_packet_get_format((const hicn_header_t *)buffer, &format); return format; } - TRANSPORT_ALWAYS_INLINE void replace(MemBufPtr &&buffer) { - packet_ = std::move(buffer); - packet_start_ = reinterpret_cast<hicn_header_t *>(packet_->writableData()); - header_head_ = packet_.get(); - payload_head_ = nullptr; - format_ = getFormatFromBuffer(reinterpret_cast<uint8_t *>(packet_start_), - packet_->length()); + void reset() { + clear(); + packet_start_ = reinterpret_cast<hicn_header_t *>(writableData()); + header_offset_ = 0; + format_ = HF_UNSPEC; + payload_type_ = PayloadType::UNSPECIFIED; name_.clear(); + + if (isChained()) { + separateChain(next(), prev()); + } } + void setFormat(Packet::Format format = HF_INET6_TCP, + std::size_t additional_header_size = 0); + std::size_t payloadSize() const; std::size_t headerSize() const; - const std::shared_ptr<utils::MemBuf> acquireMemBufReference() const; + std::shared_ptr<utils::MemBuf> acquireMemBufReference(); virtual const Name &getName() const = 0; @@ -145,25 +145,8 @@ class Packet : public std::enable_shared_from_this<Packet> { Packet &appendPayload(std::unique_ptr<utils::MemBuf> &&payload); - Packet &appendHeader(std::unique_ptr<utils::MemBuf> &&header); - - Packet &appendHeader(const uint8_t *buffer, std::size_t length); - std::unique_ptr<utils::MemBuf> getPayload() const; - std::pair<const uint8_t *, std::size_t> getPayloadReference() const { - int signature_size = 0; - - if (_is_ah(format_)) { - signature_size = (uint32_t)getSignatureSize(); - } - - auto header_size = getHeaderSizeFromFormat(format_, signature_size); - auto payload_length = payloadSize(); - - return std::make_pair(packet_->data() + header_size, payload_length); - } - Packet &updateLength(std::size_t length = 0); PayloadType getPayloadType() const; @@ -174,35 +157,38 @@ class Packet : public std::enable_shared_from_this<Packet> { void dump() const; + static void dump(uint8_t *buffer, std::size_t length); + virtual void setLocator(const ip_address_t &locator) = 0; virtual ip_address_t getLocator() const = 0; - void setSignatureTimestamp(const uint64_t ×tamp); + /** + * @brief Set signature timestamp, in milliseconds. + */ + void setSignatureTimestamp(const uint64_t ×tamp_milliseconds); uint64_t getSignatureTimestamp() const; - void setValidationAlgorithm(const utils::CryptoSuite &validation_algorithm); + void setValidationAlgorithm(const auth::CryptoSuite &validation_algorithm); - utils::CryptoSuite getValidationAlgorithm() const; + auth::CryptoSuite getValidationAlgorithm() const; - void setKeyId(const utils::KeyId &key_id); + void setKeyId(const auth::KeyId &key_id); - utils::KeyId getKeyId() const; + auth::KeyId getKeyId() const; - virtual utils::CryptoHash computeDigest( - utils::CryptoHashType algorithm) const; + virtual auth::CryptoHash computeDigest(auth::CryptoHashType algorithm) const; void setChecksum() { - uint16_t partial_csum = 0; - - for (utils::MemBuf *current = header_head_->next(); - current && current != header_head_; current = current->next()) { - if (partial_csum != 0) { - partial_csum = ~partial_csum; - } - partial_csum = csum(current->data(), current->length(), partial_csum); + 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(); @@ -234,12 +220,12 @@ class Packet : public std::enable_shared_from_this<Packet> { Packet &setTTL(uint8_t hops); uint8_t getTTL() const; - void separateHeaderPayload(); - void resetPayload(); - private: virtual void resetForHash() = 0; void setSignatureSize(std::size_t size_bytes); + void prependPayload(const uint8_t **buffer, std::size_t *size); + + bool authenticationHeader() const { return _is_ah(format_); } std::size_t getSignatureSize() const { size_t size_bytes; @@ -256,12 +242,11 @@ class Packet : public std::enable_shared_from_this<Packet> { uint8_t *getSignature() const; protected: - Name name_; - MemBufPtr packet_; hicn_header_t *packet_start_; - utils::MemBuf *header_head_; - utils::MemBuf *payload_head_; + std::size_t header_offset_; mutable Format format_; + Name name_; + mutable PayloadType payload_type_; static const core::Name base_name; }; |