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/CMakeLists.txt2
-rw-r--r--libtransport/includes/hicn/transport/core/asio_wrapper.h3
-rw-r--r--libtransport/includes/hicn/transport/core/connector.h88
-rw-r--r--libtransport/includes/hicn/transport/core/content_object.h40
-rw-r--r--libtransport/includes/hicn/transport/core/endpoint.h18
-rw-r--r--libtransport/includes/hicn/transport/core/global_object_pool.h14
-rw-r--r--libtransport/includes/hicn/transport/core/interest.h51
-rw-r--r--libtransport/includes/hicn/transport/core/io_module.h27
-rw-r--r--libtransport/includes/hicn/transport/core/name.h22
-rw-r--r--libtransport/includes/hicn/transport/core/packet.h248
-rw-r--r--libtransport/includes/hicn/transport/core/payload_type.h13
-rw-r--r--libtransport/includes/hicn/transport/core/prefix.h38
12 files changed, 263 insertions, 301 deletions
diff --git a/libtransport/includes/hicn/transport/core/CMakeLists.txt b/libtransport/includes/hicn/transport/core/CMakeLists.txt
index 14c795a7a..34048d93a 100644
--- a/libtransport/includes/hicn/transport/core/CMakeLists.txt
+++ b/libtransport/includes/hicn/transport/core/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Copyright (c) 2021 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:
diff --git a/libtransport/includes/hicn/transport/core/asio_wrapper.h b/libtransport/includes/hicn/transport/core/asio_wrapper.h
index 78cad35dc..41b660587 100644
--- a/libtransport/includes/hicn/transport/core/asio_wrapper.h
+++ b/libtransport/includes/hicn/transport/core/asio_wrapper.h
@@ -23,6 +23,9 @@ TRANSPORT_CLANG_DISABLE_WARNING("-Wdeprecated-declarations")
#ifndef ASIO_STANDALONE
#define ASIO_STANDALONE
#endif
+#ifdef __APPLE__
+TRANSPORT_CLANG_DISABLE_WARNING("-Wshorten-64-to-32")
+#endif
#include <asio.hpp>
TRANSPORT_POP_WARNING
diff --git a/libtransport/includes/hicn/transport/core/connector.h b/libtransport/includes/hicn/transport/core/connector.h
index dcf38cdc8..7882b285d 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:
@@ -15,6 +15,7 @@
#pragma once
+#include <glog/logging.h>
#include <hicn/transport/core/connector_stats.h>
#include <hicn/transport/core/content_object.h>
#include <hicn/transport/core/endpoint.h>
@@ -29,6 +30,7 @@
#include <deque>
#include <functional>
+#include <system_error>
namespace transport {
@@ -50,54 +52,51 @@ class Connector : public std::enable_shared_from_this<Connector> {
enum class Role : std::uint8_t { CONSUMER, PRODUCER };
- public:
static constexpr std::size_t queue_size = 4096;
static constexpr std::uint32_t invalid_connector = ~0;
-
-#ifdef LINUX
+ static constexpr std::uint32_t max_reconnection_reattempts = 5;
static constexpr std::uint16_t max_burst = 256;
-#endif
using Ptr = std::shared_ptr<Connector>;
- using PacketQueue = std::deque<Packet::Ptr>;
+ using ReceptionBuffer = std::vector<utils::MemBuf::Ptr>;
+ using PacketQueue = std::deque<utils::MemBuf::Ptr>;
using PacketReceivedCallback = std::function<void(
- Connector *, utils::MemBuf &, const std::error_code &)>;
+ Connector *, const ReceptionBuffer &, const std::error_code &)>;
using PacketSentCallback =
std::function<void(Connector *, const std::error_code &)>;
using OnCloseCallback = std::function<void(Connector *)>;
- using OnReconnectCallback = std::function<void(Connector *)>;
+ using OnReconnectCallback =
+ std::function<void(Connector *, const std::error_code &)>;
using Id = std::uint64_t;
template <typename ReceiveCallback, typename SentCallback, typename OnClose,
typename OnReconnect>
Connector(ReceiveCallback &&receive_callback, SentCallback &&packet_sent,
OnClose &&close_callback, OnReconnect &&on_reconnect)
- : receive_callback_(std::forward<ReceiveCallback &&>(receive_callback)),
- sent_callback_(std::forward<SentCallback &&>(packet_sent)),
- on_close_callback_(std::forward<OnClose &&>(close_callback)),
- on_reconnect_callback_(std::forward<OnReconnect &&>(on_reconnect)),
- state_(State::CLOSED),
- connector_id_(invalid_connector) {}
+ : receive_callback_(std::forward<ReceiveCallback>(receive_callback)),
+ sent_callback_(std::forward<SentCallback>(packet_sent)),
+ on_close_callback_(std::forward<OnClose>(close_callback)),
+ on_reconnect_callback_(std::forward<OnReconnect>(on_reconnect)) {}
virtual ~Connector(){};
template <typename ReceiveCallback>
void setReceiveCallback(ReceiveCallback &&callback) {
- receive_callback_ = std::forward<ReceiveCallback &&>(callback);
+ receive_callback_ = std::forward<ReceiveCallback>(callback);
}
template <typename SentCallback>
void setSentCallback(SentCallback &&callback) {
- sent_callback_ = std::forward<SentCallback &&>(callback);
+ sent_callback_ = std::forward<SentCallback>(callback);
}
template <typename OnClose>
void setOnCloseCallback(OnClose &&callback) {
- on_close_callback_ = std::forward<OnClose &&>(callback);
+ on_close_callback_ = std::forward<OnClose>(callback);
}
template <typename OnReconnect>
- void setReconnectCallback(const OnReconnect &&callback) {
+ void setReconnectCallback(OnReconnect &&callback) {
on_reconnect_callback_ = std::forward<OnReconnect>(callback);
}
@@ -115,7 +114,15 @@ class Connector : public std::enable_shared_from_this<Connector> {
virtual void send(Packet &packet) = 0;
- virtual void send(const uint8_t *packet, std::size_t len) = 0;
+ virtual void send(const utils::MemBuf::Ptr &buffer) = 0;
+
+ virtual void receive(const std::vector<utils::MemBuf::Ptr> &buffers) {
+ receive_callback_(this, buffers, std::make_error_code(std::errc()));
+ }
+
+ virtual void reconnect() {
+ on_reconnect_callback_(this, std::make_error_code(std::errc()));
+ }
virtual void close() = 0;
@@ -127,36 +134,48 @@ class Connector : public std::enable_shared_from_this<Connector> {
Id getConnectorId() { return connector_id_; }
- void setConnectorName(std::string connector_name) {
+ void setConnectorName(const std::string &connector_name) {
connector_name_ = connector_name;
}
- std::string getConnectorName() { return connector_name_; }
+ std::string getConnectorName() const { return connector_name_; }
+
+ template <typename EP>
+ void setLocalEndpoint(EP &&endpoint) {
+ local_endpoint_ = std::forward<EP>(endpoint);
+ }
- Endpoint getLocalEndpoint() { return local_endpoint_; }
+ Endpoint getLocalEndpoint() const { return local_endpoint_; }
- Endpoint getRemoteEndpoint() { return remote_endpoint_; }
+ Endpoint getRemoteEndpoint() const { return remote_endpoint_; }
void setRole(Role r) { role_ = r; }
- Role getRole() { return role_; }
+ Role getRole() const { return role_; }
static utils::MemBuf::Ptr getPacketFromBuffer(uint8_t *buffer,
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;
@@ -191,8 +210,8 @@ class Connector : public std::enable_shared_from_this<Connector> {
OnReconnectCallback on_reconnect_callback_;
// Connector state
- std::atomic<State> state_;
- Id connector_id_;
+ std::atomic<State> state_ = State::CLOSED;
+ Id connector_id_ = invalid_connector;
// Endpoints
Endpoint local_endpoint_;
@@ -206,6 +225,9 @@ class Connector : public std::enable_shared_from_this<Connector> {
// Stats
AtomicConnectorStats stats_;
+
+ // Connection attempts
+ std::uint32_t connection_reattempts_ = 0;
};
} // namespace core
diff --git a/libtransport/includes/hicn/transport/core/content_object.h b/libtransport/includes/hicn/transport/core/content_object.h
index 38baafc69..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) 2017-2019 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,41 +29,37 @@ 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 = HF_INET6_TCP,
- std::size_t additional_header_size = 0);
+ ContentObject(Packet::Format format, std::size_t additional_header_size = 0);
- ContentObject(const Name &name, Packet::Format format = HF_INET6_TCP,
+ 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)
+ 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();
}
}
template <typename... Args>
- ContentObject(WrapBufferOp op, Args &&... 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_data_get_name(format_, packet_start_, name_.getStructReference()) <
- 0) {
+ ContentObject(CreateOp op, Args &&...args)
+ : Packet(op, HICN_PACKET_TYPE_DATA, std::forward<Args>(args)...) {
+ if (hicn_data_get_name(&pkbuf_, &name_.getStructReference()) < 0) {
throw errors::MalformedPacketException();
}
}
@@ -82,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;
@@ -96,6 +92,10 @@ class ContentObject : public Packet {
auto shared_from_this() { return utils::shared_from(this); }
+ bool isLast() const;
+
+ void setLast();
+
private:
void resetForHash() override;
};
diff --git a/libtransport/includes/hicn/transport/core/endpoint.h b/libtransport/includes/hicn/transport/core/endpoint.h
index cb6b0f562..2278a1759 100644
--- a/libtransport/includes/hicn/transport/core/endpoint.h
+++ b/libtransport/includes/hicn/transport/core/endpoint.h
@@ -42,22 +42,28 @@ class Endpoint {
~Endpoint() = default;
Endpoint &operator=(const Endpoint &other) {
- address_ = other.address_;
- port_ = other.port_;
+ if (this != &other) {
+ address_ = other.address_;
+ port_ = other.port_;
+ }
+
return *this;
}
Endpoint &operator=(Endpoint &&other) {
- address_ = std::move(other.address_);
- port_ = std::move(other.port_);
+ if (this != &other) {
+ address_ = std::move(other.address_);
+ port_ = std::move(other.port_);
+ }
+
return *this;
}
#if 0
template <typename Ip, typename Port>
Endpoint(Ip &&ip_address, Port &&port)
- : address_(std::forward<Ip &&>(ip_address)),
- port_(std::forward<Port &&>(port)) {}
+ : address_(std::forward<Ip>(ip_address)),
+ port_(std::forward<Port>(port)) {}
#endif
asio::ip::address getAddress() { return address_; }
diff --git a/libtransport/includes/hicn/transport/core/global_object_pool.h b/libtransport/includes/hicn/transport/core/global_object_pool.h
index d7f3a9e41..f98df521f 100644
--- a/libtransport/includes/hicn/transport/core/global_object_pool.h
+++ b/libtransport/includes/hicn/transport/core/global_object_pool.h
@@ -27,9 +27,10 @@ namespace transport {
namespace core {
template <std::size_t packet_pool_size = 1024, std::size_t chunk_size = 2048>
-class PacketManager
- : public utils::Singleton<PacketManager<packet_pool_size, chunk_size>> {
- friend class utils::Singleton<PacketManager<packet_pool_size, chunk_size>>;
+class PacketManager : public utils::ThreadLocalSingleton<
+ PacketManager<packet_pool_size, chunk_size>> {
+ friend class utils::ThreadLocalSingleton<
+ PacketManager<packet_pool_size, chunk_size>>;
public:
using MemoryPool = utils::FixedBlockAllocator<chunk_size, packet_pool_size>;
@@ -71,7 +72,10 @@ class PacketManager
template <
typename PacketType, typename... Args,
typename = std::enable_if_t<std::is_base_of<Packet, PacketType>::value>>
- typename PacketType::Ptr getPacket(Args &&... args) {
+ typename PacketType::Ptr getPacket(Args &&...args) {
+ static_assert(sizeof(PacketType) + sizeof(std::shared_ptr<PacketType>) +
+ sizeof(std::max_align_t) <=
+ sizeof(PacketStorage::packet_and_shared_ptr));
PacketType *memory = nullptr;
memory = reinterpret_cast<PacketType *>(memory_pool_.allocateBlock());
@@ -98,7 +102,7 @@ class PacketManager
template <typename PacketType, typename... Args>
typename PacketType::Ptr getPacketFromExistingBuffer(uint8_t *buffer,
std::size_t length,
- Args &&... args) {
+ Args &&...args) {
auto offset = offsetof(PacketStorage, align);
auto memory = reinterpret_cast<PacketType *>(buffer - offset);
utils::STLAllocator<PacketType, MemoryPool> allocator(memory,
diff --git a/libtransport/includes/hicn/transport/core/interest.h b/libtransport/includes/hicn/transport/core/interest.h
index a5b9cf375..270ea7027 100644
--- a/libtransport/includes/hicn/transport/core/interest.h
+++ b/libtransport/includes/hicn/transport/core/interest.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 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 {
@@ -29,46 +33,35 @@ const uint32_t MAX_AGGREGATED_INTEREST = 128;
class Interest
: public Packet /*, public std::enable_shared_from_this<Interest>*/ {
- private:
- struct InterestManifestHeader {
- /* This can be 16 bits, but we use 32 bits for alignment */
- uint32_t n_suffixes;
- /* Followed by the list of prefixes to ask */
- /* ... */
- };
-
public:
using Ptr = std::shared_ptr<Interest>;
- Interest(Packet::Format format = HF_INET6_TCP,
- std::size_t additional_header_size = 0);
+ Interest(Packet::Format format, std::size_t additional_header_size = 0);
- Interest(const Name &interest_name, Packet::Format format = HF_INET6_TCP,
+ Interest(const Name &interest_name, Packet::Format format,
std::size_t additional_header_size = 0);
Interest(MemBuf &&buffer);
template <typename... Args>
- Interest(CopyBufferOp op, Args &&... 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();
}
}
template <typename... Args>
- Interest(WrapBufferOp op, Args &&... 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)...) {}
+ Interest(CreateOp op, Args &&...args)
+ : Packet(op, HICN_PACKET_TYPE_INTEREST, std::forward<Args>(args)...) {}
/* Move constructor */
Interest(Interest &&other_interest);
@@ -87,24 +80,36 @@ 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;
uint32_t getLifetime() const override;
- bool hasManifest();
+ bool hasManifest() const;
void appendSuffix(std::uint32_t suffix);
void encodeSuffixes();
+ void serializeSuffixes();
+
+ void deserializeSuffixes();
+
uint32_t *firstSuffix();
uint32_t numberOfSuffixes();
+ hicn_uword *getRequestBitmap();
+
+ interest_manifest_header_t *getIntManifestHeader();
+
+ void setRequestBitmap(const uint32_t *request_bitmap);
+
+ bool isValid();
+
auto shared_from_this() { return utils::shared_from(this); }
private:
diff --git a/libtransport/includes/hicn/transport/core/io_module.h b/libtransport/includes/hicn/transport/core/io_module.h
index ea3cf4e16..cfaa61975 100644
--- a/libtransport/includes/hicn/transport/core/io_module.h
+++ b/libtransport/includes/hicn/transport/core/io_module.h
@@ -19,6 +19,7 @@
#include <hicn/transport/core/connector.h>
#include <hicn/transport/core/packet.h>
#include <hicn/transport/core/prefix.h>
+#include <hicn/transport/portability/endianess.h>
#include <hicn/transport/portability/portability.h>
#include <hicn/transport/utils/chrono_typedefs.h>
#include <hicn/transport/utils/membuf.h>
@@ -40,7 +41,7 @@ typedef struct {
class Connector;
-class IoModule {
+class IoModule : utils::NonCopyable {
protected:
IoModule()
: inet_address_({}),
@@ -48,13 +49,12 @@ class IoModule {
mtu_(1500),
output_interface_(""),
content_store_reserved_(5000) {
- inet_address_.v4.as_u32 = htonl(0x7f00001);
+ inet_address_.v4.as_u32 = portability::host_to_net(0x7f00001);
inet6_address_.v6.as_u8[15] = 0x01;
}
public:
static IoModule *load(const char *);
- static bool unload(IoModule *);
public:
virtual ~IoModule();
@@ -64,15 +64,21 @@ class IoModule {
virtual bool isConnected() = 0;
virtual void init(Connector::PacketReceivedCallback &&receive_callback,
+ Connector::PacketSentCallback &&sent_callback,
+ Connector::OnCloseCallback &&close_callback,
Connector::OnReconnectCallback &&reconnect_callback,
asio::io_service &io_service,
const std::string &app_name = "Libtransport") = 0;
virtual void registerRoute(const Prefix &prefix) = 0;
+ virtual void sendMapme() {}
+
+ virtual void setForwardingStrategy(const Prefix &prefix,
+ std::string &strategy){};
virtual std::uint32_t getMtu() = 0;
- virtual bool isControlMessage(const uint8_t *message) = 0;
+ virtual bool isControlMessage(utils::MemBuf &packet_buffer) = 0;
virtual void processControlMessageReply(utils::MemBuf &packet_buffer) = 0;
@@ -82,14 +88,14 @@ class IoModule {
counters_.tx_packets++;
counters_.tx_bytes += packet.payloadSize() + packet.headerSize();
- if (_is_ipv4(packet.getFormat())) {
+ if (HICN_PACKET_FORMAT_IS_IPV4(packet.getFormat())) {
packet.setLocator(inet_address_);
} else {
packet.setLocator(inet6_address_);
}
}
- virtual void send(const uint8_t *packet, std::size_t len) = 0;
+ virtual void send(const utils::MemBuf::Ptr &buffer) = 0;
void setContentStoreSize(uint32_t cs_size) {
content_store_reserved_ = cs_size;
@@ -103,14 +109,9 @@ class IoModule {
const std::string &getOutputInterface() { return output_interface_; }
-#ifndef ANDROID
- private:
- void *handle_;
-#endif
-
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 033582289..14ea10898 100644
--- a/libtransport/includes/hicn/transport/core/name.h
+++ b/libtransport/includes/hicn/transport/core/name.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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,12 +46,13 @@ class Name {
friend class Packet;
friend class ContentObject;
friend class Interest;
+ friend class Prefix;
static const uint32_t standard_name_string_length = 100;
public:
using NameStruct = hicn_name_t;
- using Type = hicn_name_type_t;
+ enum class Type { UNDEFINED, V4, V6 };
Name();
@@ -69,6 +70,8 @@ class Name {
Name(const Name &name);
+ ~Name();
+
Name &operator=(const Name &name);
bool operator==(const Name &name) const;
@@ -91,23 +94,22 @@ class Name {
uint32_t getSuffix() const;
- std::shared_ptr<Sockaddr> getAddress() const;
-
Name &setSuffix(uint32_t seq_number);
- ip_prefix_t toIpAddress() const;
+ hicn_ip_prefix_t toIpAddress() const;
+
+ std::string getPrefix() const;
- void copyToDestination(uint8_t *destination,
- bool include_suffix = false) const;
+ void copyPrefixToDestination(uint8_t *destination) const;
int getAddressFamily() const;
private:
- TRANSPORT_ALWAYS_INLINE const NameStruct *getConstStructReference() const {
- return &name_;
+ TRANSPORT_ALWAYS_INLINE const NameStruct &getConstStructReference() const {
+ return name_;
}
- TRANSPORT_ALWAYS_INLINE NameStruct *getStructReference() { return &name_; }
+ TRANSPORT_ALWAYS_INLINE NameStruct &getStructReference() { return name_; }
NameStruct name_;
};
diff --git a/libtransport/includes/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h
index 269a1571a..31d856cd5 100644
--- a/libtransport/includes/hicn/transport/core/packet.h
+++ b/libtransport/includes/hicn/transport/core/packet.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 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,15 +26,18 @@
#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 {
class Signer;
-class AsymmetricSigner;
-class SymmetricSigner;
class Verifier;
-class AsymmetricVerifier;
-class SymmetricVerifier;
} // namespace auth
namespace core {
@@ -51,16 +54,14 @@ namespace core {
class Packet : public utils::MemBuf,
public std::enable_shared_from_this<Packet> {
friend class auth::Signer;
- friend class auth::SymmetricSigner;
- friend class auth::AsymmetricSigner;
friend class auth::Verifier;
- friend class auth::AsymmetricVerifier;
- friend class auth::SymmetricVerifier;
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;
/**
@@ -68,211 +69,120 @@ 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 = HF_INET6_TCP, std::size_t additional_header_size = 0);
-
- /**
- * Create new IP packet using raw buffer.
- */
-
+ 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 = HF_INET6_TCP, std::size_t additional_header_size = 0);
- /* Move MemBuf */
- Packet(MemBuf &&buffer);
+ 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);
-
- /*
- * Copy constructor and assignemnt operators.
- */
Packet(const Packet &other);
- Packet &operator=(const Packet &other);
-
- friend bool operator==(const Packet &l_packet, const Packet &r_packet);
+ // Destructor
virtual ~Packet();
- static std::size_t getHeaderSizeFromFormat(Format format,
- std::size_t signature_size = 0) {
- std::size_t header_length;
- hicn_packet_get_header_length_from_format(format, &header_length);
- int is_ah = _is_ah(format);
- return is_ah * (header_length + signature_size) + (!is_ah) * header_length;
- }
-
- 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);
-
- bool isInterest();
-
- static Format getFormatFromBuffer(const uint8_t *buffer, std::size_t length) {
- Format format = HF_UNSPEC;
- hicn_packet_get_format((const hicn_header_t *)buffer, &format);
- return format;
- }
-
- void reset() {
- clear();
- packet_start_ = reinterpret_cast<hicn_header_t *>(writableData());
- header_offset_ = 0;
- format_ = HF_UNSPEC;
- payload_type_ = PayloadType::UNSPECIFIED;
- name_.clear();
+ // Operators
+ Packet &operator=(const Packet &other);
+ friend bool operator==(const Packet &l_packet, const Packet &r_packet);
- if (isChained()) {
- separateChain(next(), prev());
- }
- }
+ // Cast to MemBuf
+ std::shared_ptr<utils::MemBuf> acquireMemBufReference();
- void setFormat(Packet::Format format = HF_INET6_TCP,
- std::size_t additional_header_size = 0);
+ // Format
+ Format getFormat() const;
+ void setFormat(Packet::Format format);
- std::size_t payloadSize() const;
+ void initialize(std::size_t additional_header_size = 0);
+ void analyze();
- std::size_t headerSize() const;
+ void initializeType(Packet::Type type);
+ hicn_packet_type_t getType() const;
+ void setType(Packet::Type type);
- std::shared_ptr<utils::MemBuf> acquireMemBufReference();
+ void setBuffer();
+ // Name
virtual const Name &getName() const = 0;
-
virtual Name &getWritableName() = 0;
-
virtual void setName(const Name &name) = 0;
+ // Lifetime
virtual void setLifetime(uint32_t lifetime) = 0;
-
virtual uint32_t getLifetime() const = 0;
- Packet &appendPayload(const uint8_t *buffer, std::size_t length);
+ // Locator
+ virtual void setLocator(const hicn_ip_address_t &locator) = 0;
+ virtual hicn_ip_address_t getLocator() const = 0;
- Packet &appendPayload(std::unique_ptr<utils::MemBuf> &&payload);
+ // Payload type
+ PayloadType getPayloadType() const;
+ Packet &setPayloadType(PayloadType payload_type);
+ // Payload
std::unique_ptr<utils::MemBuf> getPayload() const;
+ Packet &appendPayload(std::unique_ptr<utils::MemBuf> &&payload);
+ Packet &appendPayload(const uint8_t *buffer, std::size_t length);
- Packet &updateLength(std::size_t length = 0);
+ // Sizes
+ std::size_t headerSize() const;
+ std::size_t payloadSize() const;
- PayloadType getPayloadType() const;
+ // Digest
+ auth::CryptoHash computeDigest(auth::CryptoHashType algorithm) const;
- Packet &setPayloadType(PayloadType payload_type);
+ bool isInterest();
- Format getFormat() const;
+ // Reset packet
+ void reset();
+ // Utils
+ Packet &updateLength(std::size_t length = 0);
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;
-
- /**
- * @brief Set signature timestamp, in milliseconds.
- */
- void setSignatureTimestamp(const uint64_t &timestamp_milliseconds);
+ // TCP methods
+ void setChecksum();
+ bool checkIntegrity() const;
+ // Authentication Header methods
+ bool hasAH() const;
+ utils::MemBuf::Ptr getSignature() const;
+ std::size_t getSignatureFieldSize() const;
+ std::size_t getSignatureSize() const;
uint64_t getSignatureTimestamp() const;
-
- void setValidationAlgorithm(const auth::CryptoSuite &validation_algorithm);
-
+ auth::KeyId getKeyId() const;
auth::CryptoSuite getValidationAlgorithm() const;
-
+ void setSignature(const utils::MemBuf::Ptr &signature);
+ void setSignatureFieldSize(std::size_t size);
+ void setSignatureSize(std::size_t size);
+ void setSignatureTimestamp(const uint64_t &timestamp_ms);
void setKeyId(const auth::KeyId &key_id);
+ void setValidationAlgorithm(const auth::CryptoSuite &algo);
- auth::KeyId getKeyId() const;
-
- virtual auth::CryptoHash computeDigest(auth::CryptoHashType algorithm) const;
-
- void setChecksum() {
- 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();
- }
- }
+ void saveHeader(u8 *header, size_t *header_len);
+ void loadHeader(u8 *header, size_t header_len);
- 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;
- uint16_t getDstPort() const;
-
- Packet &setTTL(uint8_t hops);
- uint8_t getTTL() const;
+ // 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(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:
virtual void resetForHash() = 0;
- void setSignatureSize(std::size_t size_bytes);
- void setSignatureSizeGap(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;
- int ret =
- hicn_packet_get_signature_size(format_, packet_start_, &size_bytes);
-
- if (ret < 0) {
- throw errors::RuntimeException("Packet without Authentication Header.");
- }
-
- return size_bytes;
- }
-
- std::size_t getSignatureSizeGap() const {
- uint8_t size_bytes;
- int ret =
- hicn_packet_get_signature_gap(format_, packet_start_, &size_bytes);
-
- if (ret < 0) {
- throw errors::RuntimeException("Packet without Authentication Header.");
- }
-
- return (size_t)size_bytes;
- }
-
- std::size_t getSignatureSizeReal() const {
- return getSignatureSize() - getSignatureSizeGap();
- }
-
- uint8_t *getSignature() const;
-
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 8c918f792..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) 2017-2019 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 7ef667bc8..791fbc770 100644
--- a/libtransport/includes/hicn/transport/core/prefix.h
+++ b/libtransport/includes/hicn/transport/core/prefix.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2021 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:
@@ -25,16 +25,18 @@ class Prefix {
public:
Prefix();
- Prefix(const char *prefix);
-
Prefix(const std::string &prefix);
- Prefix(std::string &&prefix);
-
- Prefix(std::string &prefix, uint16_t prefix_length);
+ Prefix(const std::string &prefix, uint16_t prefix_length);
Prefix(const core::Name &content_name, uint16_t prefix_length);
+ bool operator<(const Prefix &prefix) const;
+
+ bool operator==(const Prefix &prefix) const;
+
+ bool operator!=(const Prefix &prefix) const { return !operator==(prefix); }
+
std::unique_ptr<Sockaddr> toSockaddr() const;
uint16_t getPrefixLength() const;
@@ -43,36 +45,34 @@ class Prefix {
std::string getNetwork() const;
- int contains(const ip_address_t &content_name) const;
+ Prefix &setNetwork(const std::string &network);
- int contains(const core::Name &content_name) const;
+ int getAddressFamily() const;
- Name getName() const;
+ bool contains(const hicn_ip_address_t &content_name) const;
- Name getRandomName() const;
+ bool contains(const core::Name &content_name) const;
Name getName(const core::Name &mask, const core::Name &components,
const core::Name &content_name) const;
Name mapName(const core::Name &content_name) const;
- Prefix &setNetwork(std::string &network);
-
- int getAddressFamily() const;
-
- Prefix &setAddressFamily(int address_family);
-
+ Name makeName() const;
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,
int family);
- void buildPrefix(std::string &prefix, uint16_t prefix_length, int family);
+ void buildPrefix(const std::string &prefix, uint16_t prefix_length,
+ int family);
- ip_prefix_t ip_prefix_;
+ private:
+ hicn_ip_prefix_t hicn_ip_prefix_;
};
} // end namespace core