From bac3da61644515f05663789b122554dc77549286 Mon Sep 17 00:00:00 2001 From: Luca Muscariello Date: Thu, 17 Jan 2019 13:47:57 +0100 Subject: This is the first commit of the hicn project Change-Id: I6f2544ad9b9f8891c88cc4bcce3cf19bd3cc863f Signed-off-by: Luca Muscariello --- libtransport/src/hicn/transport/protocols/vegas.h | 161 ++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 libtransport/src/hicn/transport/protocols/vegas.h (limited to 'libtransport/src/hicn/transport/protocols/vegas.h') diff --git a/libtransport/src/hicn/transport/protocols/vegas.h b/libtransport/src/hicn/transport/protocols/vegas.h new file mode 100755 index 000000000..7791ffc94 --- /dev/null +++ b/libtransport/src/hicn/transport/protocols/vegas.h @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2017-2019 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: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace transport { + +namespace protocol { + +typedef utils::CircularFifo SuffixQueue; +typedef std::chrono::time_point Time; +typedef std::chrono::milliseconds TimeDuration; + +class VegasTransportProtocol : public TransportProtocol { + public: + VegasTransportProtocol(interface::BaseSocket *icnet_socket); + + virtual ~VegasTransportProtocol(); + + virtual void start(utils::SharableVector &content_buffer) override; + + void stop() override; + + void resume() override; + + protected: + void reset(); + + void sendInterest(std::uint64_t next_suffix); + + void onContentSegment(Interest::Ptr &&interest, + ContentObject::Ptr &&content_object); + + bool verifyContentObject(const ContentObject &content_object); + + bool verifyManifest(const interface::ContentObjectManifest &manifest); + + virtual void onTimeout(Interest::Ptr &&interest) override; + + void onManifest(std::unique_ptr &&manifest); + + void onContentObject(Interest::Ptr &&interest, + ContentObject::Ptr &&content_object) override; + + virtual void changeInterestLifetime(uint64_t segment); + + void scheduleNextInterests(); + + virtual void decreaseWindow(); + + virtual void increaseWindow(); + + virtual void afterContentReception(const Interest &interest, + const ContentObject &content_object); + + virtual void afterDataUnsatisfied(uint64_t segment); + + void reassemble(); + + void returnContentToUser(); + + void partialDownload(); + + virtual void copyContent(const ContentObject &content_object); + + // virtual void checkForFastRetransmission(const Interest &interest); + + // void fastRetransmit(const Interest &interest, uint32_t chunk_number); + + void removeAllPendingInterests(); + + protected: + void handleTimeout(const std::error_code &ec); + + // reassembly variables + volatile bool is_final_block_number_discovered_; + std::atomic final_block_number_; + uint64_t last_reassembled_segment_; + std::shared_ptr> content_buffer_; + size_t content_buffer_size_; + + // transmission variablesis_final_block_number_discovered_ + double current_window_size_; + double pending_window_size_; + uint64_t interests_in_flight_; + uint64_t next_suffix_; + std::vector interest_retransmissions_; + std::vector interest_timepoints_; + RtoEstimator rtt_estimator_; + + uint32_t retx_count_; + + // buffers + std::unordered_map + receive_buffer_; // verified segments by segment number + std::unordered_map + unverified_segments_; // used with embedded manifests + std::unordered_map + verified_manifests_; // by segment number + + std::uint16_t interest_pool_index_; + std::uint16_t mask_; + + // suffix randomization: since the suffixes in the manifests could not be in a + // sequential order, we need to map those suffixes into an ordered sequence. + std::unordered_map + incremental_suffix_to_real_suffix_map_; + std::unordered_map + real_suffix_to_incremental_suffix_map_; + std::uint32_t incremental_suffix_index_; + + // verification + std::unordered_map, HashAlgorithm>> + suffix_hash_map_; + + // Fast Retransmission + std::map received_segments_; + std::unordered_map fast_retransmitted_segments; + + // Suffix queue + volatile bool suffix_queue_completed_; + SuffixQueue suffix_queue_; + + volatile bool download_with_manifest_; + uint32_t next_manifest_; + std::atomic next_manifest_interval_; + + std::unique_ptr verifier_thread_; + + uint32_t interest_tx_; + uint32_t interest_count_; + + uint64_t byte_count_; + double average_rtt_; + + std::unordered_map sign_time_; +}; + +} // namespace protocol + +} // end namespace transport -- cgit 1.2.3-korg