aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/core')
-rw-r--r--libtransport/src/core/content_object.cc71
-rw-r--r--libtransport/src/core/interest.cc51
-rw-r--r--libtransport/src/core/io_module.cc4
-rw-r--r--libtransport/src/core/manifest_format_fixed.cc4
-rw-r--r--libtransport/src/core/name.cc20
-rw-r--r--libtransport/src/core/packet.cc437
-rw-r--r--libtransport/src/core/portal.cc8
-rw-r--r--libtransport/src/core/portal.h49
-rw-r--r--libtransport/src/core/prefix.cc121
-rw-r--r--libtransport/src/core/udp_connector.cc34
10 files changed, 334 insertions, 465 deletions
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_, &timestamp);
+ int ret = hicn_packet_get_signature_timestamp(&pkbuf_, &timestamp);
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 &timestamp) {
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
}