aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/includes/hicn/transport/core
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/includes/hicn/transport/core')
-rw-r--r--libtransport/includes/hicn/transport/core/connector.h23
-rw-r--r--libtransport/includes/hicn/transport/core/content_object.h29
-rw-r--r--libtransport/includes/hicn/transport/core/interest.h24
-rw-r--r--libtransport/includes/hicn/transport/core/io_module.h4
-rw-r--r--libtransport/includes/hicn/transport/core/name.h2
-rw-r--r--libtransport/includes/hicn/transport/core/packet.h67
-rw-r--r--libtransport/includes/hicn/transport/core/payload_type.h13
-rw-r--r--libtransport/includes/hicn/transport/core/prefix.h6
8 files changed, 89 insertions, 79 deletions
diff --git a/libtransport/includes/hicn/transport/core/connector.h b/libtransport/includes/hicn/transport/core/connector.h
index ad0d4f09d..eaf95b2ec 100644
--- a/libtransport/includes/hicn/transport/core/connector.h
+++ b/libtransport/includes/hicn/transport/core/connector.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:
@@ -160,18 +160,25 @@ class Connector : public std::enable_shared_from_this<Connector> {
std::size_t size) {
utils::MemBuf::Ptr ret;
- auto format = Packet::getFormatFromBuffer(buffer, size);
+ hicn_packet_buffer_t pkbuf;
+ hicn_packet_set_buffer(&pkbuf, buffer, size, size);
+ hicn_packet_analyze(&pkbuf);
+ hicn_packet_type_t type = hicn_packet_get_type(&pkbuf);
- if (TRANSPORT_EXPECT_TRUE(format != HF_UNSPEC && !_is_icmp(format))) {
- if (Packet::isInterest(buffer)) {
+ // XXX reuse pkbuf when creating the packet, to avoid reanalyzing it
+
+ switch (type) {
+ case HICN_PACKET_TYPE_INTEREST:
ret = core::PacketManager<>::getInstance()
.getPacketFromExistingBuffer<Interest>(buffer, size);
- } else {
+ break;
+ case HICN_PACKET_TYPE_DATA:
ret = core::PacketManager<>::getInstance()
.getPacketFromExistingBuffer<ContentObject>(buffer, size);
- }
- } else {
- ret = core::PacketManager<>::getInstance().getMemBuf(buffer, size);
+ break;
+ default:
+ ret = core::PacketManager<>::getInstance().getMemBuf(buffer, size);
+ break;
}
return ret;
diff --git a/libtransport/includes/hicn/transport/core/content_object.h b/libtransport/includes/hicn/transport/core/content_object.h
index f8d95846e..3d6d98c48 100644
--- a/libtransport/includes/hicn/transport/core/content_object.h
+++ b/libtransport/includes/hicn/transport/core/content_object.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:
@@ -29,22 +29,21 @@ namespace core {
class ContentObject : public Packet {
public:
using Ptr = std::shared_ptr<ContentObject>;
- using HICNContentObject = hicn_header_t;
+ using HICNContentObject = u8;
ContentObject(Packet::Format format, std::size_t additional_header_size = 0);
ContentObject(const Name &name, Packet::Format format,
std::size_t additional_header_size = 0);
- ContentObject(const Name &name, hicn_format_t format,
+ ContentObject(const Name &name, hicn_packet_format_t format,
std::size_t additional_header_size, const uint8_t *payload,
std::size_t payload_size);
template <typename... Args>
ContentObject(CopyBufferOp op, Args &&...args)
: Packet(op, std::forward<Args>(args)...) {
- if (hicn_data_get_name(format_, packet_start_,
- &name_.getStructReference()) < 0) {
+ if (hicn_data_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
@@ -52,21 +51,15 @@ class ContentObject : public Packet {
template <typename... Args>
ContentObject(WrapBufferOp op, Args &&...args)
: Packet(op, std::forward<Args>(args)...) {
- if (hicn_data_get_name(format_, packet_start_,
- &name_.getStructReference()) < 0) {
+ if (hicn_data_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
template <typename... Args>
ContentObject(CreateOp op, Args &&...args)
- : Packet(op, std::forward<Args>(args)...) {
- if (hicn_packet_set_data(format_, packet_start_) < 0) {
- throw errors::MalformedPacketException();
- }
-
- if (hicn_data_get_name(format_, packet_start_,
- &name_.getStructReference()) < 0) {
+ : Packet(op, HICN_PACKET_TYPE_DATA, std::forward<Args>(args)...) {
+ if (hicn_data_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
@@ -85,13 +78,13 @@ class ContentObject : public Packet {
void setName(const Name &name) override;
- uint32_t getPathLabel() const;
+ hicn_path_label_t getPathLabel() const;
- ContentObject &setPathLabel(uint32_t path_label);
+ ContentObject &setPathLabel(hicn_path_label_t path_label);
- void setLocator(const ip_address_t &ip_address) override;
+ void setLocator(const hicn_ip_address_t &ip_address) override;
- ip_address_t getLocator() const override;
+ hicn_ip_address_t getLocator() const override;
void setLifetime(uint32_t lifetime) override;
diff --git a/libtransport/includes/hicn/transport/core/interest.h b/libtransport/includes/hicn/transport/core/interest.h
index 9e6cdccb9..23dc8f75e 100644
--- a/libtransport/includes/hicn/transport/core/interest.h
+++ b/libtransport/includes/hicn/transport/core/interest.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:
@@ -21,6 +21,10 @@
#include <set>
+extern "C" {
+#include <hicn/interest_manifest.h>
+}
+
namespace transport {
namespace core {
@@ -42,8 +46,7 @@ class Interest
template <typename... Args>
Interest(CopyBufferOp op, Args &&...args)
: Packet(op, std::forward<Args>(args)...) {
- if (hicn_interest_get_name(format_, packet_start_,
- &name_.getStructReference()) < 0) {
+ if (hicn_interest_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
@@ -51,19 +54,14 @@ class Interest
template <typename... Args>
Interest(WrapBufferOp op, Args &&...args)
: Packet(op, std::forward<Args>(args)...) {
- if (hicn_interest_get_name(format_, packet_start_,
- &name_.getStructReference()) < 0) {
+ if (hicn_interest_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
template <typename... Args>
Interest(CreateOp op, Args &&...args)
- : Packet(op, std::forward<Args>(args)...) {
- if (hicn_packet_set_interest(format_, packet_start_) < 0) {
- throw errors::MalformedPacketException();
- }
- }
+ : Packet(op, HICN_PACKET_TYPE_INTEREST, std::forward<Args>(args)...) {}
/* Move constructor */
Interest(Interest &&other_interest);
@@ -82,9 +80,9 @@ class Interest
void setName(const Name &name) override;
- void setLocator(const ip_address_t &ip_address) override;
+ void setLocator(const hicn_ip_address_t &ip_address) override;
- ip_address_t getLocator() const override;
+ hicn_ip_address_t getLocator() const override;
void setLifetime(uint32_t lifetime) override;
@@ -100,7 +98,7 @@ class Interest
uint32_t numberOfSuffixes();
- uint32_t *getRequestBitmap();
+ hicn_uword *getRequestBitmap();
void setRequestBitmap(const uint32_t *request_bitmap);
diff --git a/libtransport/includes/hicn/transport/core/io_module.h b/libtransport/includes/hicn/transport/core/io_module.h
index 31da0b882..ce6f3a629 100644
--- a/libtransport/includes/hicn/transport/core/io_module.h
+++ b/libtransport/includes/hicn/transport/core/io_module.h
@@ -110,8 +110,8 @@ class IoModule : utils::NonCopyable {
const std::string &getOutputInterface() { return output_interface_; }
protected:
- ip_address_t inet_address_;
- ip_address_t inet6_address_;
+ hicn_ip_address_t inet_address_;
+ hicn_ip_address_t inet6_address_;
uint16_t mtu_;
std::string output_interface_;
uint32_t content_store_reserved_;
diff --git a/libtransport/includes/hicn/transport/core/name.h b/libtransport/includes/hicn/transport/core/name.h
index cf6d3097c..90b665c15 100644
--- a/libtransport/includes/hicn/transport/core/name.h
+++ b/libtransport/includes/hicn/transport/core/name.h
@@ -96,7 +96,7 @@ class Name {
Name &setSuffix(uint32_t seq_number);
- ip_prefix_t toIpAddress() const;
+ hicn_ip_prefix_t toIpAddress() const;
void copyPrefixToDestination(uint8_t *destination) const;
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;
diff --git a/libtransport/includes/hicn/transport/core/payload_type.h b/libtransport/includes/hicn/transport/core/payload_type.h
index 3a682e177..a528500ad 100644
--- a/libtransport/includes/hicn/transport/core/payload_type.h
+++ b/libtransport/includes/hicn/transport/core/payload_type.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:
@@ -15,6 +15,15 @@
#pragma once
+#include <hicn/transport/portability/portability.h>
+
+extern "C" {
+#ifndef _WIN32
+TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
+#endif
+#include <hicn/base.h>
+};
+
namespace transport {
namespace core {
@@ -27,4 +36,4 @@ enum class PayloadType : uint16_t {
} // end namespace core
-} // end namespace transport \ No newline at end of file
+} // end namespace transport
diff --git a/libtransport/includes/hicn/transport/core/prefix.h b/libtransport/includes/hicn/transport/core/prefix.h
index 778491a31..791fbc770 100644
--- a/libtransport/includes/hicn/transport/core/prefix.h
+++ b/libtransport/includes/hicn/transport/core/prefix.h
@@ -49,7 +49,7 @@ class Prefix {
int getAddressFamily() const;
- bool contains(const ip_address_t &content_name) const;
+ bool contains(const hicn_ip_address_t &content_name) const;
bool contains(const core::Name &content_name) const;
@@ -62,7 +62,7 @@ class Prefix {
Name makeRandomName() const;
Name makeNameWithIndex(std::uint64_t index) const;
- const ip_prefix_t &toIpPrefixStruct() const;
+ const hicn_ip_prefix_t &toIpPrefixStruct() const;
private:
static bool checkPrefixLengthAndAddressFamily(uint16_t prefix_length,
@@ -72,7 +72,7 @@ class Prefix {
int family);
private:
- ip_prefix_t ip_prefix_;
+ hicn_ip_prefix_t hicn_ip_prefix_;
};
} // end namespace core