aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/includes/hicn/transport/core/packet.h
diff options
context:
space:
mode:
authorLuca Muscariello <muscariello@ieee.org>2022-08-04 16:06:34 +0200
committerLuca Muscariello <muscariello@ieee.org>2022-08-04 16:31:51 +0200
commit6d22a0db96aa7f8e3102ae44d00c09e36a2e9c57 (patch)
tree79546bbf09f6fbf74db7bc89117843f06ce937ea /libtransport/includes/hicn/transport/core/packet.h
parent012843b1c0bc0838e69085ed83a79ec8b6f97360 (diff)
feat: Due to the deep modifications related to names and packet format,
this task cover a large part of the codebase and involves several changes: - the library provides a name data structure (hicn_name_t ), which is composed of a name prefix (hicn_name_prefix_t) and a name suffix (hicn_name_suffix_t), and it has been extended to provide all support functions required for name manipulation, including common prefix computation, as required for the Longest Prefix Match (LPM)in the forwarder, in addition to Exact Prefix Match (EPM). - all code has been rewritten to use this data structure instead of having for instance the forwarder define its own name class (used to be Name and NameBitVector) the code has been refactored to minimize name allocations and copies, one remaining aspect is the difference of name storage between PIT and CS entries (respectively in the PIT entry, and in the message buffer), which causes the packet cache index to be updated when a PIT entry is converted into a CS entry. By storing the name in the PIT/CS entry everytime, we might save on this operation). - hicn-light FIB has been rewritten : code has been refactored and should now be shorter and documented; unit tests have been drafted but more would be required to cover all cases and match the algorithms to add/remove nodes, as specified in the doc. all protocol details and hICN header formats are now abstracted by the library for the forwarder (and thus header.h and  protocols/*.h have been removed from public includes, and replaced by packet.h providing protocol agnostic packet level functions, completely replacing the compat.h header that used to provide similar functions. - this works by exposing a opaque buffer to the application (a kind of socket buffer) which is used by the lib to cache the packet format and offsets of the different layers in the buffer and provider efficient operations (the packet format is either defined for packet construction, or guessed at ingress, and this structure is updated accordingly only once). Co-authored-by: Jordan Augé <jordan.auge+fdio@cisco.com> Signed-off-by: Luca Muscariello <muscariello@ieee.org> Change-Id: I31e321897f85f0267fe8ba4720363c180564492f
Diffstat (limited to 'libtransport/includes/hicn/transport/core/packet.h')
-rw-r--r--libtransport/includes/hicn/transport/core/packet.h67
1 files changed, 35 insertions, 32 deletions
diff --git a/libtransport/includes/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h
index c1671d439..9277a52c2 100644
--- a/libtransport/includes/hicn/transport/core/packet.h
+++ b/libtransport/includes/hicn/transport/core/packet.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:
@@ -26,6 +26,13 @@
#include <hicn/transport/utils/membuf.h>
#include <hicn/transport/utils/object_pool.h>
+extern "C" {
+#ifndef _WIN32
+TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
+#endif
+#include <hicn/packet.h>
+}
+
namespace transport {
namespace auth {
@@ -52,7 +59,8 @@ class Packet : public utils::MemBuf,
public:
using Ptr = std::shared_ptr<Packet>;
using MemBufPtr = std::shared_ptr<utils::MemBuf>;
- using Format = hicn_format_t;
+ using Format = hicn_packet_format_t;
+ using Type = hicn_packet_type_t;
static constexpr size_t default_mtu = 1500;
@@ -61,14 +69,15 @@ class Packet : public utils::MemBuf,
* 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, std::size_t additional_header_size = 0);
+ Packet(Type type, Format format, std::size_t additional_header_size = 0);
/* 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, std::size_t additional_header_size = 0);
+ Packet(CreateOp, Type type, uint8_t *buffer, std::size_t length,
+ std::size_t size, Format format,
+ std::size_t additional_header_size = 0);
Packet(MemBuf &&buffer);
Packet(Packet &&other);
@@ -86,7 +95,15 @@ class Packet : public utils::MemBuf,
// Format
Format getFormat() const;
- void setFormat(Packet::Format format, std::size_t additional_header_size = 0);
+ void setFormat(Packet::Format format);
+
+ void initialize(std::size_t additional_header_size = 0);
+ void analyze();
+
+ hicn_packet_type_t getType() const;
+ void setType(Packet::Type type);
+
+ void setBuffer();
// Name
virtual const Name &getName() const = 0;
@@ -98,8 +115,8 @@ class Packet : public utils::MemBuf,
virtual uint32_t getLifetime() const = 0;
// Locator
- virtual void setLocator(const ip_address_t &locator) = 0;
- virtual ip_address_t getLocator() const = 0;
+ virtual void setLocator(const hicn_ip_address_t &locator) = 0;
+ virtual hicn_ip_address_t getLocator() const = 0;
// Payload type
PayloadType getPayloadType() const;
@@ -117,31 +134,18 @@ class Packet : public utils::MemBuf,
// Digest
auth::CryptoHash computeDigest(auth::CryptoHashType algorithm) const;
+ bool isInterest();
+
// Reset packet
void reset();
// Utils
- bool isInterest();
Packet &updateLength(std::size_t length = 0);
void dump() const;
// TCP methods
void setChecksum();
bool checkIntegrity() const;
- Packet &setSyn();
- Packet &resetSyn();
- bool testSyn() const;
- Packet &setAck();
- Packet &resetAck();
- bool testAck() const;
- Packet &setRst();
- Packet &resetRst();
- bool testRst() const;
- Packet &setFin();
- Packet &resetFin();
- bool testFin() const;
- Packet &resetFlags();
- std::string printFlags() const;
Packet &setSrcPort(uint16_t srcPort);
Packet &setDstPort(uint16_t dstPort);
uint16_t getSrcPort() const;
@@ -164,17 +168,18 @@ class Packet : public utils::MemBuf,
void setKeyId(const auth::KeyId &key_id);
void setValidationAlgorithm(const auth::CryptoSuite &algo);
+ void saveHeader(u8 *header, size_t *header_len);
+ void loadHeader(u8 *header, size_t header_len);
+
// Static methods
static Format toAHFormat(const Format &format);
static Format getFormatFromBuffer(const uint8_t *buffer, std::size_t length);
static std::size_t getHeaderSizeFromFormat(Format format,
std::size_t signature_size = 0);
- static std::size_t getHeaderSizeFromBuffer(Format format,
- const uint8_t *buffer);
- static std::size_t getPayloadSizeFromBuffer(Format format,
- const uint8_t *buffer);
- static bool isInterest(const uint8_t *buffer,
- Format format = Format::HF_UNSPEC);
+ static std::size_t getHeaderSizeFromBuffer(const uint8_t *buffer,
+ size_t length);
+ static std::size_t getPayloadSizeFromBuffer(const uint8_t *buffer,
+ size_t length);
static void dump(uint8_t *buffer, std::size_t length);
private:
@@ -182,9 +187,7 @@ class Packet : public utils::MemBuf,
void prependPayload(const uint8_t **buffer, std::size_t *size);
protected:
- hicn_header_t *packet_start_;
- std::size_t header_offset_;
- mutable Format format_;
+ hicn_packet_buffer_t pkbuf_;
Name name_;
mutable PayloadType payload_type_;
static const core::Name base_name;