diff options
author | Mauro Sardara <msardara@cisco.com> | 2020-03-04 16:21:54 +0100 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2020-03-09 13:02:50 +0000 |
commit | afe807c61372fe2481e73af63c8382af1e1d3011 (patch) | |
tree | 181269bc2548bba9eb667df4301ded197183a4cf /libtransport/src/core | |
parent | 248bfd5ad0ae3cc17bbd3ea3b9a47fa8d075ee58 (diff) |
[HICN-540] Optimizations for libhicntransport
Change-Id: I8b46b4eb2ef5488c09041887cc8296a216440f33
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/core')
-rw-r--r-- | libtransport/src/core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libtransport/src/core/content_object.cc | 9 | ||||
-rw-r--r-- | libtransport/src/core/forwarder_interface.h | 4 | ||||
-rw-r--r-- | libtransport/src/core/interest.cc | 9 | ||||
-rw-r--r-- | libtransport/src/core/memif_connector.cc | 2 | ||||
-rw-r--r-- | libtransport/src/core/packet.cc | 54 | ||||
-rw-r--r-- | libtransport/src/core/pending_interest.h | 50 | ||||
-rw-r--r-- | libtransport/src/core/portal.h | 4 |
8 files changed, 42 insertions, 91 deletions
diff --git a/libtransport/src/core/CMakeLists.txt b/libtransport/src/core/CMakeLists.txt index 12ef9cfe4..5c8ab9270 100644 --- a/libtransport/src/core/CMakeLists.txt +++ b/libtransport/src/core/CMakeLists.txt @@ -33,7 +33,6 @@ list(APPEND HEADER_FILES list(APPEND SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/content_object.cc ${CMAKE_CURRENT_SOURCE_DIR}/interest.cc - ${CMAKE_CURRENT_SOURCE_DIR}/pending_interest.cc ${CMAKE_CURRENT_SOURCE_DIR}/packet.cc ${CMAKE_CURRENT_SOURCE_DIR}/name.cc ${CMAKE_CURRENT_SOURCE_DIR}/prefix.cc diff --git a/libtransport/src/core/content_object.cc b/libtransport/src/core/content_object.cc index 6cbcdb29e..f5cccf404 100644 --- a/libtransport/src/core/content_object.cc +++ b/libtransport/src/core/content_object.cc @@ -86,15 +86,6 @@ ContentObject::ContentObject(ContentObject &&other) : Packet(std::move(other)) { ContentObject::~ContentObject() {} -void ContentObject::replace(MemBufPtr &&buffer) { - Packet::replace(std::move(buffer)); - - if (hicn_data_get_name(format_, packet_start_, name_.getStructReference()) < - 0) { - throw errors::RuntimeException("Error getting name from content object."); - } -} - const Name &ContentObject::getName() const { if (!name_) { if (hicn_data_get_name(format_, packet_start_, diff --git a/libtransport/src/core/forwarder_interface.h b/libtransport/src/core/forwarder_interface.h index 3e70e221d..3b016c4bb 100644 --- a/libtransport/src/core/forwarder_interface.h +++ b/libtransport/src/core/forwarder_interface.h @@ -95,15 +95,11 @@ class ForwarderInterface { packet.setLocator(inet6_address_); } - // TRANSPORT_LOGI("Sending packet %s at %lu", - // packet.getName().toString().c_str(), - // utils::SteadyClock::now().time_since_epoch().count()); packet.setChecksum(); connector_.send(packet.acquireMemBufReference()); } TRANSPORT_ALWAYS_INLINE void send(const uint8_t *packet, std::size_t len) { - // ASIO_COMPLETION_HANDLER_CHECK(Handler, packet_sent) type_check; counters_.tx_packets++; counters_.tx_bytes += len; diff --git a/libtransport/src/core/interest.cc b/libtransport/src/core/interest.cc index 166632f0a..9ee662615 100644 --- a/libtransport/src/core/interest.cc +++ b/libtransport/src/core/interest.cc @@ -72,15 +72,6 @@ Interest::Interest(Interest &&other_interest) Interest::~Interest() {} -void Interest::replace(MemBufPtr &&buffer) { - Packet::replace(std::move(buffer)); - - if (hicn_interest_get_name(format_, packet_start_, - name_.getStructReference()) < 0) { - throw errors::MalformedPacketException(); - } -} - const Name &Interest::getName() const { if (!name_) { if (hicn_interest_get_name(format_, packet_start_, diff --git a/libtransport/src/core/memif_connector.cc b/libtransport/src/core/memif_connector.cc index 2292e9b41..179db63e4 100644 --- a/libtransport/src/core/memif_connector.cc +++ b/libtransport/src/core/memif_connector.cc @@ -353,7 +353,7 @@ int MemifConnector::onInterrupt(memif_conn_handle_t conn, void *private_ctx, c->rx_buf_num += rx; - if (TRANSPORT_EXPECT_TRUE(connector->io_service_.stopped())) { + if (TRANSPORT_EXPECT_FALSE(connector->io_service_.stopped())) { TRANSPORT_LOGE("socket stopped: ignoring %u packets", rx); goto error; } diff --git a/libtransport/src/core/packet.cc b/libtransport/src/core/packet.cc index 67e647fca..6815868f0 100644 --- a/libtransport/src/core/packet.cc +++ b/libtransport/src/core/packet.cc @@ -69,14 +69,6 @@ Packet::Packet(Packet &&other) Packet::~Packet() {} -std::size_t Packet::getHeaderSizeFromFormat(Format format, - size_t signature_size) { - 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; -} - std::size_t Packet::getHeaderSizeFromBuffer(Format format, const uint8_t *buffer) { size_t header_length; @@ -99,17 +91,6 @@ bool Packet::isInterest(const uint8_t *buffer) { return !is_interest; } -Packet::Format Packet::getFormatFromBuffer(const uint8_t *buffer) { - Format format = HF_UNSPEC; - - if (TRANSPORT_EXPECT_FALSE( - hicn_packet_get_format((const hicn_header_t *)buffer, &format) < 0)) { - throw errors::MalformedPacketException(); - } - - return format; -} - std::size_t Packet::getPayloadSizeFromBuffer(Format format, const uint8_t *buffer) { std::size_t payload_length; @@ -122,14 +103,6 @@ std::size_t Packet::getPayloadSizeFromBuffer(Format format, return payload_length; } -void Packet::replace(MemBufPtr &&buffer) { - packet_ = std::move(buffer); - packet_start_ = reinterpret_cast<hicn_header_t *>(packet_->writableData()); - header_head_ = packet_.get(); - payload_head_ = nullptr; - format_ = getFormatFromBuffer(reinterpret_cast<uint8_t *>(packet_start_)); -} - std::size_t Packet::payloadSize() const { return getPayloadSizeFromBuffer(format_, reinterpret_cast<uint8_t *>(packet_start_)); @@ -270,17 +243,6 @@ uint8_t *Packet::getSignature() const { return signature; } -std::size_t Packet::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; -} - void Packet::setSignatureTimestamp(const uint64_t ×tamp) { int ret = hicn_packet_set_signature_timestamp(format_, packet_start_, timestamp); @@ -366,22 +328,6 @@ utils::CryptoHash Packet::computeDigest(utils::CryptoHashType algorithm) const { return hasher.finalize(); } -void Packet::setChecksum() { - uint16_t partial_csum = 0; - - for (utils::MemBuf *current = header_head_->next(); - current && current != header_head_; current = current->next()) { - if (partial_csum != 0) { - partial_csum = ~partial_csum; - } - partial_csum = csum(current->data(), current->length(), partial_csum); - } - if (hicn_packet_compute_header_checksum(format_, packet_start_, - partial_csum) < 0) { - throw errors::MalformedPacketException(); - } -} - bool Packet::checkIntegrity() const { if (hicn_packet_check_integrity(format_, packet_start_) < 0) { return false; diff --git a/libtransport/src/core/pending_interest.h b/libtransport/src/core/pending_interest.h index d9ec2ed40..aeff78ea2 100644 --- a/libtransport/src/core/pending_interest.h +++ b/libtransport/src/core/pending_interest.h @@ -47,17 +47,29 @@ class PendingInterest { public: using Ptr = utils::ObjectPool<PendingInterest>::Ptr; - PendingInterest(); + PendingInterest() + : interest_(nullptr, nullptr), + timer_(), + on_content_object_callback_(), + on_interest_timeout_callback_() {} PendingInterest(Interest::Ptr &&interest, - std::unique_ptr<asio::steady_timer> &&timer); + std::unique_ptr<asio::steady_timer> &&timer) + : interest_(std::move(interest)), + timer_(std::move(timer)), + on_content_object_callback_(), + on_interest_timeout_callback_() {} PendingInterest(Interest::Ptr &&interest, OnContentObjectCallback &&on_content_object, OnInterestTimeoutCallback &&on_interest_timeout, - std::unique_ptr<asio::steady_timer> &&timer); + std::unique_ptr<asio::steady_timer> &&timer) + : interest_(std::move(interest)), + timer_(std::move(timer)), + on_content_object_callback_(std::move(on_content_object)), + on_interest_timeout_callback_(std::move(on_interest_timeout)) {} - ~PendingInterest(); + ~PendingInterest() = default; template <typename Handler> TRANSPORT_ALWAYS_INLINE void startCountdown(Handler &&cb) { @@ -66,19 +78,35 @@ class PendingInterest { timer_->async_wait(std::forward<Handler &&>(cb)); } - void cancelTimer(); + TRANSPORT_ALWAYS_INLINE void cancelTimer() { timer_->cancel(); } - Interest::Ptr &&getInterest(); + TRANSPORT_ALWAYS_INLINE Interest::Ptr &&getInterest() { + return std::move(interest_); + } - void setInterest(Interest::Ptr &&interest); + TRANSPORT_ALWAYS_INLINE void setInterest(Interest::Ptr &&interest) { + interest_ = std::move(interest); + } - const OnContentObjectCallback &getOnDataCallback() const; + TRANSPORT_ALWAYS_INLINE const OnContentObjectCallback &getOnDataCallback() + const { + return on_content_object_callback_; + } - void setOnContentObjectCallback(OnContentObjectCallback &&on_content_object); + TRANSPORT_ALWAYS_INLINE void setOnContentObjectCallback( + OnContentObjectCallback &&on_content_object) { + PendingInterest::on_content_object_callback_ = on_content_object; + } - const OnInterestTimeoutCallback &getOnTimeoutCallback() const; + TRANSPORT_ALWAYS_INLINE const OnInterestTimeoutCallback & + getOnTimeoutCallback() const { + return on_interest_timeout_callback_; + } - void setOnTimeoutCallback(OnInterestTimeoutCallback &&on_interest_timeout); + TRANSPORT_ALWAYS_INLINE void setOnTimeoutCallback( + OnInterestTimeoutCallback &&on_interest_timeout) { + PendingInterest::on_interest_timeout_callback_ = on_interest_timeout; + } private: Interest::Ptr interest_; diff --git a/libtransport/src/core/portal.h b/libtransport/src/core/portal.h index cf1010068..34dfbd826 100644 --- a/libtransport/src/core/portal.h +++ b/libtransport/src/core/portal.h @@ -627,6 +627,8 @@ class Portal { } private: + portal_details::HandlerMemory async_callback_memory_; + asio::io_service &io_service_; asio::io_service internal_io_service_; portal_details::Pool packet_pool_; @@ -639,8 +641,6 @@ class Portal { ConsumerCallback *consumer_callback_; ProducerCallback *producer_callback_; - portal_details::HandlerMemory async_callback_memory_; - typename ForwarderInt::ConnectorType connector_; ForwarderInt forwarder_interface_; }; |