diff options
Diffstat (limited to 'libtransport/includes/hicn/transport/interfaces')
14 files changed, 458 insertions, 365 deletions
diff --git a/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt b/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt index 7370ad1b0..43f95a466 100644 --- a/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt +++ b/libtransport/includes/hicn/transport/interfaces/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: @@ -11,26 +11,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -cmake_minimum_required(VERSION 3.5 FATAL_ERROR) - list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/socket_consumer.h ${CMAKE_CURRENT_SOURCE_DIR}/socket_producer.h - ${CMAKE_CURRENT_SOURCE_DIR}/rtc_socket_producer.h ${CMAKE_CURRENT_SOURCE_DIR}/publication_options.h ${CMAKE_CURRENT_SOURCE_DIR}/socket_options_default_values.h ${CMAKE_CURRENT_SOURCE_DIR}/socket_options_keys.h ${CMAKE_CURRENT_SOURCE_DIR}/callbacks.h - ${CMAKE_CURRENT_SOURCE_DIR}/verification_policy.h + ${CMAKE_CURRENT_SOURCE_DIR}/global_conf_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/statistics.h ${CMAKE_CURRENT_SOURCE_DIR}/portal.h + ${CMAKE_CURRENT_SOURCE_DIR}/notification.h ) -if (${OPENSSL_VERSION} VERSION_EQUAL "1.1.1a" OR ${OPENSSL_VERSION} VERSION_GREATER "1.1.1a") - list(APPEND HEADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/p2psecure_socket_producer.h - ${CMAKE_CURRENT_SOURCE_DIR}/p2psecure_socket_consumer.h - ) -endif() - set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) diff --git a/libtransport/includes/hicn/transport/interfaces/callbacks.h b/libtransport/includes/hicn/transport/interfaces/callbacks.h index 6ae07797e..41e4fba3b 100644 --- a/libtransport/includes/hicn/transport/interfaces/callbacks.h +++ b/libtransport/includes/hicn/transport/interfaces/callbacks.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: @@ -15,8 +15,9 @@ #pragma once +#include <hicn/transport/auth/policies.h> +#include <hicn/transport/interfaces/notification.h> #include <hicn/transport/interfaces/statistics.h> -#include <hicn/transport/interfaces/verification_policy.h> #include <functional> #include <system_error> @@ -60,6 +61,12 @@ using ConsumerTimerCallback = std::function<void(ConsumerSocket &, const TransportStatistics &stats)>; /** + * The ConsumerTimerCallback is called when the forwarding/recovery stategy is + * changes. + */ +using StrategyCallback = std::function<void(notification::Strategy strategy)>; + +/** * The ProducerContentCallback will be called by the producer socket right after * a content has been segmented and published. */ @@ -75,25 +82,6 @@ using ConsumerContentObjectCallback = std::function<void(ConsumerSocket &, const core::ContentObject &)>; /** - * The ConsumerContentObjectVerificationCallback will be called by the transport - * if an application is willing to verify each content object. Note that a - * better alternative is to instrument the transport to perform the verification - * autonomously, without requiring the intervention of the application. - */ -using ConsumerContentObjectVerificationCallback = - std::function<bool(ConsumerSocket &, const core::ContentObject &)>; - -/** - * The ConsumerContentObjectVerificationFailedCallback will be caled by the - * transport if a data packet (either manifest or content object) cannot be - * verified. The application here decides what to do by returning a - * VerificationFailedPolicy object. - */ -using ConsumerContentObjectVerificationFailedCallback = - std::function<VerificationPolicy( - ConsumerSocket &, const core::ContentObject &, std::error_code ec)>; - -/** * The ProducerContentObjectCallback will be called in different parts of the * consumer socket processing pipeline, with a ProducerSocket and an * ContentObject as parameters. diff --git a/libtransport/includes/hicn/transport/interfaces/global_conf_interface.h b/libtransport/includes/hicn/transport/interfaces/global_conf_interface.h new file mode 100644 index 000000000..e1465d375 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/global_conf_interface.h @@ -0,0 +1,70 @@ +/* + * 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: + * + * 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 <string> +#include <vector> + +/** + * Global configuration interface. + */ + +namespace transport { +namespace interface { +namespace global_config { + +class GlobalConfigInterface { + public: + GlobalConfigInterface(); + ~GlobalConfigInterface(); + void parseConfigurationFile(const std::string& path = "") const; + + private: + void libtransportConfigInit() const; + void libtransportConfigTerminate() const; +}; + +class ConfigurationObject { + public: + /** + * Set configuration. + */ + void set(); + + /** + * Get configuration. + */ + void get(); + + /** + * Get configuration key + */ + virtual std::string getKey() const = 0; +}; + +class IoModuleConfiguration : public ConfigurationObject { + public: + static inline char section[] = "io_module"; + + std::string getKey() const override { return section; } + + std::string name; + std::vector<std::string> search_path; +}; + +} // namespace global_config +} // namespace interface +} // namespace transport
\ No newline at end of file diff --git a/libtransport/includes/hicn/transport/interfaces/rtc_socket_producer.h b/libtransport/includes/hicn/transport/interfaces/notification.h index 218240f83..a0945c3f0 100644 --- a/libtransport/includes/hicn/transport/interfaces/rtc_socket_producer.h +++ b/libtransport/includes/hicn/transport/interfaces/notification.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Cisco and/or its affiliates. + * Copyright (c) 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,18 +15,17 @@ #pragma once -#include <hicn/transport/interfaces/socket_producer.h> +#include <variant> namespace transport { - namespace interface { +namespace notification { -class RTCProducerSocket : public ProducerSocket { - public: - RTCProducerSocket(); - ~RTCProducerSocket() = default; -}; +enum class ForwardingStrategy { BEST_PATH, REPLICATION, BOTH, NONE }; +enum class RecoveryStrategy { RECOVERY_OFF, RTX_ONLY, FEC_ONLY, RTX_AND_FEC }; -} // namespace interface +using Strategy = std::variant<ForwardingStrategy, RecoveryStrategy>; -} // end namespace transport +} // namespace notification +} // namespace interface +} // namespace transport
\ No newline at end of file diff --git a/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h deleted file mode 100644 index 224493f00..000000000 --- a/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 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 <hicn/transport/interfaces/socket_consumer.h> - -namespace transport { - -namespace interface { - -class P2PSecureConsumerSocket : public ConsumerSocket { - public: - P2PSecureConsumerSocket(int handshake_protocol, int transport_protocol); - ~P2PSecureConsumerSocket() = default; - void registerPrefix(const Prefix &producer_namespace); -}; - -} // namespace interface -} // end namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_producer.h b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_producer.h deleted file mode 100644 index 6f0d48bb9..000000000 --- a/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_producer.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 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 <hicn/transport/interfaces/socket_producer.h> - -#include <hicn/transport/security/identity.h> - -namespace transport { - -namespace interface { - -class P2PSecureProducerSocket : public ProducerSocket { - public: - P2PSecureProducerSocket(); - P2PSecureProducerSocket(bool rtc, - const std::shared_ptr<utils::Identity> &identity); - ~P2PSecureProducerSocket() = default; -}; - -} // namespace interface - -} // end namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/portal.h b/libtransport/includes/hicn/transport/interfaces/portal.h index 724cd7592..bca78cb3b 100644 --- a/libtransport/includes/hicn/transport/interfaces/portal.h +++ b/libtransport/includes/hicn/transport/interfaces/portal.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: @@ -15,14 +15,12 @@ #pragma once +#include <hicn/transport/core/asio_wrapper.h> #include <hicn/transport/core/content_object.h> #include <hicn/transport/core/interest.h> #include <hicn/transport/core/prefix.h> - -#ifndef ASIO_STANDALONE -#define ASIO_STANDALONE -#endif -#include <asio/io_service.hpp> +#include <hicn/transport/utils/event_thread.h> +#include <hicn/transport/utils/noncopyable.h> #include <functional> @@ -32,82 +30,35 @@ namespace transport { namespace interface { -template <typename PrefixType> -class BasicBindConfig { - static_assert(std::is_same<core::Prefix, PrefixType>::value, - "Prefix must be a Prefix type."); - - const uint32_t standard_cs_reserved = 5000; - - public: - template <typename T> - BasicBindConfig(T &&prefix) - : prefix_(std::forward<T &&>(prefix)), - content_store_reserved_(standard_cs_reserved) {} - - template <typename T> - BasicBindConfig(T &&prefix, uint32_t cs_reserved) - : prefix_(std::forward<T &&>(prefix)), - content_store_reserved_(cs_reserved) {} - - TRANSPORT_ALWAYS_INLINE const PrefixType &prefix() const { return prefix_; } - - TRANSPORT_ALWAYS_INLINE uint32_t csReserved() const { - return content_store_reserved_; - } - - private: - PrefixType prefix_; - uint32_t content_store_reserved_; -}; - -using BindConfig = BasicBindConfig<core::Prefix>; - -class Portal { +class Portal : private utils::NonCopyable { public: /** - * Consumer callback is an abstract class containing two methods to be - * implemented by a consumer application. + * Transport callback is an abstract class containing two methods to be + * implemented by a consumer/producer application. */ - class ConsumerCallback { + class TransportCallback { public: - virtual void onContentObject(core::Interest::Ptr &&i, - core::ContentObject::Ptr &&c) = 0; - virtual void onTimeout(core::Interest::Ptr &&i) = 0; - virtual void onError(std::error_code ec) = 0; - }; - - /** - * Producer callback is an abstract class containing two methods to be - * implemented by a producer application. - */ - class ProducerCallback { - public: - virtual void onInterest(core::Interest::Ptr &&i) = 0; - virtual void onError(std::error_code ec) = 0; + virtual void onInterest(core::Interest &i) = 0; + virtual void onContentObject(core::Interest &i, core::ContentObject &c) = 0; + virtual void onTimeout(core::Interest::Ptr &i, const core::Name &n) = 0; + virtual void onError(const std::error_code &ec) = 0; }; using OnContentObjectCallback = - std::function<void(core::Interest::Ptr &&, core::ContentObject::Ptr &&)>; - using OnInterestTimeoutCallback = std::function<void(core::Interest::Ptr &&)>; + std::function<void(core::Interest &, core::ContentObject &)>; + using OnInterestTimeoutCallback = + std::function<void(core::Interest::Ptr &, const core::Name &)>; Portal(); - Portal(asio::io_service &io_service); - - /** - * Set the consumer callback. - * - * @param consumer_callback - The pointer to the ConsumerCallback object. - */ - void setConsumerCallback(ConsumerCallback *consumer_callback); + Portal(::utils::EventThread &worker); /** - * Set the producer callback. + * Set the transport protocl callback. * * @param producer_callback - The pointer to the ProducerCallback object. */ - void setProducerCallback(ProducerCallback *producer_callback); + void registerTransportCallback(TransportCallback *transport_callback); /** * Connect the transport to the local hicn forwarder. @@ -144,40 +95,18 @@ class Portal { * parameter. Otherwise ConsumerCallback::onTimeout will be used. */ void sendInterest( - core::Interest::Ptr &&interest, + core::Interest::Ptr &interest, uint32_t lifetime, OnContentObjectCallback &&on_content_object_callback = UNSET_CALLBACK, OnInterestTimeoutCallback &&on_interest_timeout_callback = UNSET_CALLBACK); /** - * Register a producer name to the local forwarder and optionally set the - * content store size in a per-face manner. - * - * @param config - The configuration for the local forwarder binding. - */ - void bind(const BindConfig &config); - - void runEventsLoop(); - - /** - * Run one event and return. - */ - void runOneEvent(); - - /** * Send a data packet to the local forwarder. As opposite to sendInterest, the * ownership of the content object is not transferred to the portal. * * @param content_object - The data packet. */ void sendContentObject(core::ContentObject &content_object); - /** - * Stop the event loop, canceling all the pending events in the event queue. - * - * Beware that stopping the event loop DOES NOT disconnect the transport from - * the local forwarder, the connector underneath will stay connected. - */ - void stopEventsLoop(); /** * Disconnect the transport from the local forwarder. @@ -192,16 +121,27 @@ class Portal { /** * Get a reference to the io_service object. */ - asio::io_service &getIoService(); + utils::EventThread &getThread(); /** * Register a route to the local forwarder. */ void registerRoute(core::Prefix &prefix); + /** + * Send a MAP-Me command to traverse NATs. + */ + void sendMapme(); + + /** + * Set forwarding strategy + */ + void setForwardingStrategy(core::Prefix &prefix, std::string &strategy); + private: - void *implementation_; + class Impl; + Impl *implementation_; }; } // namespace interface -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/publication_options.h b/libtransport/includes/hicn/transport/interfaces/publication_options.h index 6910e5371..f4f409d00 100644 --- a/libtransport/includes/hicn/transport/interfaces/publication_options.h +++ b/libtransport/includes/hicn/transport/interfaces/publication_options.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,7 +25,7 @@ class PublicationOptions { public: template <typename T> PublicationOptions(T&& name, uint32_t lifetime) - : name_(std::forward<T&&>(name)), + : name_(std::forward<T>(name)), content_lifetime_milliseconds_(lifetime) {} TRANSPORT_ALWAYS_INLINE const core::Name& getName() const { return name_; } diff --git a/libtransport/includes/hicn/transport/interfaces/socket_consumer.h b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h index 2447f9b5b..1c709eb72 100644 --- a/libtransport/includes/hicn/transport/interfaces/socket_consumer.h +++ b/libtransport/includes/hicn/transport/interfaces/socket_consumer.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: @@ -15,18 +15,16 @@ #pragma once +#include <hicn/transport/auth/verifier.h> #include <hicn/transport/config.h> +#include <hicn/transport/core/asio_wrapper.h> #include <hicn/transport/core/name.h> #include <hicn/transport/core/prefix.h> #include <hicn/transport/interfaces/callbacks.h> #include <hicn/transport/interfaces/socket_options_default_values.h> #include <hicn/transport/interfaces/socket_options_keys.h> -#include <hicn/transport/security/verifier.h> - -#ifndef ASIO_STANDALONE -#define ASIO_STANDALONE -#endif -#include <asio/io_service.hpp> +#include <hicn/transport/utils/event_thread.h> +#include <hicn/transport/utils/noncopyable.h> #define CONSUMER_FINISHED 0 #define CONSUMER_BUSY 1 @@ -49,7 +47,7 @@ using namespace core; * It allows to retrieve an application data from one/many producers, by * hiding all the complexity of the transport protocol used underneath. */ -class ConsumerSocket { +class ConsumerSocket : private utils::NonCopyable { public: /** * The ReadCallback is a class which can be used by the transport for both @@ -128,7 +126,7 @@ class ConsumerSocket { * * @param ec - An error code describing the error. */ - virtual void readError(const std::error_code ec) noexcept = 0; + virtual void readError(const std::error_code &ec) noexcept = 0; /** * This callback will be invoked when the whole content is retrieved. The @@ -170,7 +168,12 @@ class ConsumerSocket { * 110, 104-117 * - RTC: Real time communication */ - explicit ConsumerSocket(int protocol, asio::io_service &io_service); + explicit ConsumerSocket(int protocol, ::utils::EventThread &worker); + + /** + * @brief Move contructor + */ + ConsumerSocket(ConsumerSocket &&other) noexcept; /** * @brief Destroy the consumer socket. @@ -204,20 +207,10 @@ class ConsumerSocket { * content retrieval succeeded. This information can be obtained from the * error code in CONTENT_RETRIEVED callback. */ - int consume(const Name &name); - int asyncConsume(const Name &name); + int consume(const Name &name, bool blocking = false); /** - * Verify the packets containing a key after the origin of the key has been - * validated by the client. - * - * @return true if all packets are valid, false otherwise - */ - bool verifyKeyPackets(); - - /** - * Stops the consumer socket. If several downloads are queued (using - * asyncConsume), this call stops just the current one. + * Stops the consumer socket. */ void stop(); @@ -251,23 +244,18 @@ class ConsumerSocket { int setSocketOption(int socket_option_key, ConsumerContentObjectCallback socket_option_value); - int setSocketOption( - int socket_option_key, - ConsumerContentObjectVerificationFailedCallback socket_option_value); - - int setSocketOption( - int socket_option_key, - ConsumerContentObjectVerificationCallback socket_option_value); - int setSocketOption(int socket_option_key, ConsumerInterestCallback socket_option_value); int setSocketOption(int socket_option_key, interface::IcnObserver *socket_option_value); + int setSocketOption(int socket_option_key, + const std::shared_ptr<auth::Signer> &socket_option_value); + int setSocketOption( int socket_option_key, - const std::shared_ptr<utils::Verifier> &socket_option_value); + const std::shared_ptr<auth::Verifier> &socket_option_value); int setSocketOption(int socket_option_key, const std::string &socket_option_value); @@ -275,6 +263,9 @@ class ConsumerSocket { int setSocketOption(int socket_option_key, ConsumerTimerCallback socket_option_value); + int setSocketOption(int socket_option_key, + StrategyCallback socket_option_value); + int getSocketOption(int socket_option_key, double &socket_option_value); int getSocketOption(int socket_option_key, uint32_t &socket_option_value); @@ -286,21 +277,16 @@ class ConsumerSocket { int getSocketOption(int socket_option_key, ConsumerContentObjectCallback **socket_option_value); - int getSocketOption( - int socket_option_key, - ConsumerContentObjectVerificationFailedCallback **socket_option_value); - - int getSocketOption( - int socket_option_key, - ConsumerContentObjectVerificationCallback **socket_option_value); - int getSocketOption(int socket_option_key, ConsumerInterestCallback **socket_option_value); int getSocketOption(int socket_option_key, IcnObserver **socket_option_value); int getSocketOption(int socket_option_key, - std::shared_ptr<utils::Verifier> &socket_option_value); + std::shared_ptr<auth::Signer> &socket_option_value); + + int getSocketOption(int socket_option_key, + std::shared_ptr<auth::Verifier> &socket_option_value); int getSocketOption(int socket_option_key, std::string &socket_option_value); @@ -308,6 +294,9 @@ class ConsumerSocket { ConsumerTimerCallback **socket_option_value); int getSocketOption(int socket_option_key, + StrategyCallback **socket_option_value); + + int getSocketOption(int socket_option_key, interface::TransportStatistics **socket_option_value); protected: diff --git a/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h b/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h index bcf103b8c..5558197f8 100644 --- a/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h +++ b/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.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,7 +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> +}; + #include <chrono> #include <cstdint> @@ -25,13 +33,17 @@ namespace interface { namespace default_values { -static constexpr uint32_t interest_lifetime = 1001; // milliseconds -static constexpr uint32_t never_expire_time = HICN_MAX_LIFETIME; -static constexpr uint32_t content_object_expiry_time = +// Packet format +static constexpr hicn_packet_format_t packet_format = + HICN_PACKET_FORMAT_DEFAULT; + +// Parameters +static const uint32_t interest_lifetime = 1001; // milliseconds +static const uint32_t never_expire_time = HICN_MAX_LIFETIME; +static const uint32_t content_object_expiry_time = never_expire_time; // milliseconds -> 50 seconds -static constexpr uint32_t content_object_packet_size = - 1500; // The ethernet MTU -static constexpr uint32_t producer_socket_output_buffer_size = +static const uint32_t content_object_packet_size = 1500; // The ethernet MTU +static const uint32_t producer_socket_output_buffer_size = 150000; // Content Object static constexpr uint32_t log_2_default_buffer_size = 12; static constexpr uint32_t signature_size = 260; // bytes @@ -39,28 +51,31 @@ static constexpr uint32_t key_locator_size = 60; // bytes static constexpr uint32_t limit_guard = 80; // bytes static constexpr uint32_t digest_size = 34; // bytes static constexpr uint32_t max_out_of_order_segments = 3; // content object +static constexpr uint32_t manifest_max_capacity = 30; +static constexpr uint32_t manifest_factor_relevant = 100; +static constexpr uint32_t manifest_factor_alert = 20; // RAAQM -static constexpr int sample_number = 30; -static constexpr double gamma_value = 1; -static constexpr double beta_value = 0.8; -static constexpr double drop_factor = 0.2; -static constexpr double minimum_drop_probability = 0.00001; -static constexpr int path_id = 0; -static constexpr double rate_alpha = 0.8; +static const int sample_number = 30; +static const double gamma_value = 1; +static const double beta_value = 0.8; +static const double drop_factor = 0.2; +static const double minimum_drop_probability = 0.00001; +static const int path_id = 0; +static const double rate_alpha = 0.8; // Rate estimation -static constexpr uint32_t batch = 50; -static constexpr uint32_t kv = 20; -static constexpr double alpha = 0.8; -static constexpr uint32_t rate_choice = 0; +static const uint32_t batch = 50; +static const uint32_t kv = 20; +static const double alpha = 0.8; +static const uint32_t rate_choice = 0; // maximum allowed values -static constexpr uint32_t transport_protocol_min_retransmissions = 0; -static constexpr uint32_t transport_protocol_max_retransmissions = 128; -static constexpr uint32_t max_content_object_size = 8096; -static constexpr uint32_t min_window_size = 1; // Interests -static constexpr uint32_t max_window_size = 256 * 2; // Interests +static const uint32_t transport_protocol_min_retransmissions = 0; +static const uint32_t transport_protocol_max_retransmissions = 128; +static const uint32_t max_content_object_size = 8096; +static const uint32_t min_window_size = 1; // Interests +static const uint32_t max_window_size = 256 * 2; // Interests } // namespace default_values diff --git a/libtransport/includes/hicn/transport/interfaces/socket_options_keys.h b/libtransport/includes/hicn/transport/interfaces/socket_options_keys.h index 0b7a79c3d..a14c8414c 100644 --- a/libtransport/includes/hicn/transport/interfaces/socket_options_keys.h +++ b/libtransport/includes/hicn/transport/interfaces/socket_options_keys.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: @@ -26,12 +26,32 @@ namespace transport { namespace interface { typedef enum { - RAAQM = 0, - CBR = 1, - RTC = 2, + UNKNOWN = 0, + BYTE_STREAM = 1, + RTC_PROD = 2, +} ProductionProtocolAlgorithms; + +typedef enum { + RAAQM = 10, + CBR = 11, + RTC = 12, } TransportProtocolAlgorithms; typedef enum { + RECOVERY_OFF = 20, + RTX_ONLY = 21, + FEC_ONLY = 22, + DELAY_BASED = 23, + LOW_RATE = 24, + LOW_RATE_AND_BESTPATH = 25, + LOW_RATE_AND_REPLICATION = 26, + LOW_RATE_AND_ALL_FWD_STRATEGIES = 27, + FEC_ONLY_LOW_RES_LOSSES = 28, + DELAY_AND_BESTPATH = 29, + DELAY_AND_REPLICATION = 30, +} RtcTransportRecoveryStrategies; + +typedef enum { INPUT_BUFFER_SIZE = 101, OUTPUT_BUFFER_SIZE = 102, NETWORK_NAME = 103, @@ -40,22 +60,24 @@ typedef enum { DATA_PACKET_SIZE = 106, INTEREST_LIFETIME = 107, CONTENT_OBJECT_EXPIRY_TIME = 108, - KEY_CONTENT = 110, - MIN_WINDOW_SIZE = 111, - MAX_WINDOW_SIZE = 112, - CURRENT_WINDOW_SIZE = 113, - ASYNC_MODE = 114, - MAKE_MANIFEST = 115, - PORTAL = 116, - RUNNING = 117, - APPLICATION_BUFFER = 118, - HASH_ALGORITHM = 119, - CRYPTO_SUITE = 120, - SIGNER = 121, - VERIFIER = 122, - CERTIFICATE = 123, - VERIFY_SIGNATURE = 124, - STATS_INTERVAL = 125, + MAX_SEGMENT_SIZE = 109, + MIN_WINDOW_SIZE = 110, + MAX_WINDOW_SIZE = 111, + CURRENT_WINDOW_SIZE = 112, + ASYNC_MODE = 113, + PORTAL = 114, + RUNNING = 115, + APPLICATION_BUFFER = 116, + HASH_ALGORITHM = 117, + SIGNER = 118, + VERIFIER = 119, + MANIFEST_MAX_CAPACITY = 120, + MANIFEST_FACTOR_RELEVANT = 121, + MANIFEST_FACTOR_ALERT = 122, + STATS_INTERVAL = 123, + SUFFIX_STRATEGY = 124, + PACKET_FORMAT = 125, + FEC_TYPE = 126, } GeneralTransportOptions; typedef enum { @@ -66,6 +88,7 @@ typedef enum { MINIMUM_DROP_PROBABILITY = 205, PATH_ID = 206, RTT_STATS = 207, + PER_SESSION_CWINDOW_RESET = 208 } RaaqmTransportOptions; typedef enum { @@ -84,7 +107,9 @@ typedef enum { CONTENT_OBJECT_TO_VERIFY = 413, VERIFICATION_FAILED = 414, READ_CALLBACK = 415, - STATS_SUMMARY = 416 + STATS_SUMMARY = 416, + FWD_STRATEGY_CHANGE = 417, + REC_STRATEGY_CHANGE = 418, } ConsumerCallbacksOptions; typedef enum { @@ -97,6 +122,8 @@ typedef enum { CONTENT_OBJECT_READY = 510, CONTENT_OBJECT_OUTPUT = 511, CONTENT_PRODUCED = 512, + CONTENT_OBJECT_TO_SIGN = 513, + PRODUCER_CALLBACK = 514, } ProducerCallbacksOptions; typedef enum { OUTPUT_INTERFACE = 601 } DataLinkOptions; @@ -112,6 +139,13 @@ typedef enum { RSA_256 = 802, } SignatureType; +typedef enum { + RECOVERY_STRATEGY = 901, + AGGREGATED_DATA = 902, + CONTENT_SHARING_MODE = 903, + AGGREGATED_INTERESTS = 904, +} RtcTransportOptions; + } // namespace interface } // end namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/socket_producer.h b/libtransport/includes/hicn/transport/interfaces/socket_producer.h index e269fb83d..2627b3138 100644 --- a/libtransport/includes/hicn/transport/interfaces/socket_producer.h +++ b/libtransport/includes/hicn/transport/interfaces/socket_producer.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: @@ -15,18 +15,16 @@ #pragma once +#include <hicn/transport/auth/signer.h> #include <hicn/transport/config.h> +#include <hicn/transport/core/asio_wrapper.h> #include <hicn/transport/core/name.h> #include <hicn/transport/core/prefix.h> #include <hicn/transport/interfaces/callbacks.h> #include <hicn/transport/interfaces/socket_options_default_values.h> #include <hicn/transport/interfaces/socket_options_keys.h> -#include <hicn/transport/security/signer.h> - -#ifndef ASIO_STANDALONE -#define ASIO_STANDALONE -#endif -#include <asio/io_service.hpp> +#include <hicn/transport/utils/event_thread.h> +#include <hicn/transport/utils/noncopyable.h> namespace transport { @@ -38,9 +36,28 @@ namespace interface { using namespace core; -class ProducerSocket { +class ProducerSocket : private utils::NonCopyable { public: - explicit ProducerSocket(int protocol = 0); + /** + * @brief This class is used by the transport to notify events to the + * application. + */ + class Callback { + public: + /** + * @brief This will invoked in an error occurred in the production protocol. + * + * @param ec - An error code describing the error. + */ + virtual void produceError(const std::error_code &ec) noexcept = 0; + }; + + explicit ProducerSocket( + int protocol = ProductionProtocolAlgorithms::BYTE_STREAM); + + explicit ProducerSocket(int protocol, ::utils::EventThread &worker); + + ProducerSocket(ProducerSocket &&other) noexcept; virtual ~ProducerSocket(); @@ -48,40 +65,34 @@ class ProducerSocket { bool isRunning(); - uint32_t produce(Name content_name, const uint8_t *buffer, size_t buffer_size, - bool is_last = true, uint32_t start_offset = 0) { - return produce(content_name, utils::MemBuf::copyBuffer(buffer, buffer_size), - is_last, start_offset); - } - - uint32_t produce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer, - bool is_last = true, uint32_t start_offset = 0); - - void produce(ContentObject &content_object); - - void produce(const uint8_t *buffer, size_t buffer_size) { - produce(utils::MemBuf::copyBuffer(buffer, buffer_size)); - } + void registerPrefix(const Prefix &producer_namespace); - void produce(std::unique_ptr<utils::MemBuf> &&buffer); + uint32_t produceStream(const Name &content_name, const uint8_t *buffer, + size_t buffer_size, bool is_last = true, + uint32_t start_offset = 0); - void asyncProduce(const Name &suffix, const uint8_t *buf, size_t buffer_size, - bool is_last = true, uint32_t *start_offset = nullptr); + uint32_t produceStream(const Name &content_name, + std::unique_ptr<utils::MemBuf> &&buffer, + bool is_last = true, uint32_t start_offset = 0); - void asyncProduce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer, - bool is_last, uint32_t offset, - uint32_t **last_segment = nullptr); + uint32_t produceDatagram(const Name &content_name, const uint8_t *buffer, + size_t buffer_size); - void asyncProduce(ContentObject &content_object); + uint32_t produceDatagram(const Name &content_name, + std::unique_ptr<utils::MemBuf> &&buffer); - void registerPrefix(const Prefix &producer_namespace); + void produce(ContentObject &content_object); - void serveForever(); + void sendMapme(); void stop(); + void start(); + asio::io_service &getIoService(); + int setSocketOption(int socket_option_key, Callback *socket_option_value); + int setSocketOption(int socket_option_key, uint32_t socket_option_value); int setSocketOption(int socket_option_key, @@ -104,14 +115,17 @@ class ProducerSocket { ProducerContentCallback socket_option_value); int setSocketOption(int socket_option_key, - utils::CryptoHashType socket_option_value); + auth::CryptoHashType socket_option_value); int setSocketOption(int socket_option_key, - utils::CryptoSuite socket_option_value); + auth::CryptoSuite socket_option_value); + + int setSocketOption(int socket_option_key, + const std::shared_ptr<auth::Signer> &socket_option_value); int setSocketOption( int socket_option_key, - const std::shared_ptr<utils::Signer> &socket_option_value); + const std::shared_ptr<auth::Verifier> &socket_option_value); int setSocketOption(int socket_option_key, const std::string &socket_option_value); @@ -133,13 +147,16 @@ class ProducerSocket { ProducerInterestCallback **socket_option_value); int getSocketOption(int socket_option_key, - utils::CryptoHashType &socket_option_value); + auth::CryptoHashType &socket_option_value); + + int getSocketOption(int socket_option_key, + auth::CryptoSuite &socket_option_value); int getSocketOption(int socket_option_key, - utils::CryptoSuite &socket_option_value); + std::shared_ptr<auth::Signer> &socket_option_value); int getSocketOption(int socket_option_key, - std::shared_ptr<utils::Signer> &socket_option_value); + std::shared_ptr<auth::Verifier> &socket_option_value); int getSocketOption(int socket_option_key, std::string &socket_option_value); diff --git a/libtransport/includes/hicn/transport/interfaces/statistics.h b/libtransport/includes/hicn/transport/interfaces/statistics.h index 26831fbf1..e83aa9a27 100644 --- a/libtransport/includes/hicn/transport/interfaces/statistics.h +++ b/libtransport/includes/hicn/transport/interfaces/statistics.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: @@ -16,6 +16,7 @@ #pragma once #include <hicn/transport/portability/c_portability.h> +#include <hicn/transport/utils/chrono_typedefs.h> #include <cstdint> @@ -31,10 +32,14 @@ class IcnObserver { virtual void notifyDownloadTime(double downloadTime) = 0; }; +class ProductionStatistics {}; + class TransportStatistics { static constexpr double default_alpha = 0.7; public: + enum class statsAlerts : uint8_t { CONGESTION, LATENCY, LOSSES }; + TransportStatistics(double alpha = default_alpha) : retx_count_(0), bytes_received_(0), @@ -43,7 +48,21 @@ class TransportStatistics { interest_tx_(0), alpha_(alpha), loss_ratio_(0.0), - queuing_delay_(0.0) {} + queuing_delay_(0.0), + interest_FEC_tx_(0), + bytes_FEC_received_(0), + lost_data_(0), + definitely_lost_data_(0), + recovered_data_(0), + status_(0), + // avg_data_rtt_(0), + avg_pending_pkt_(0.0), + received_nacks_(0), + received_fec_(0), + in_congestion_(false), + residual_loss_rate_(0.0), + quality_score_(5), + alerts_(0) {} TRANSPORT_ALWAYS_INLINE void updateRetxCount(uint64_t retx) { retx_count_ += retx; @@ -53,8 +72,11 @@ class TransportStatistics { bytes_received_ += bytes; } - TRANSPORT_ALWAYS_INLINE void updateAverageRtt(uint64_t rtt) { - average_rtt_ = (alpha_ * average_rtt_) + ((1. - alpha_) * double(rtt)); + TRANSPORT_ALWAYS_INLINE void updateAverageRtt( + const utils::SteadyTime::Microseconds &rtt) { + double rtt_milliseconds = double(rtt.count()) / 1000.0; + + average_rtt_ = (alpha_ * average_rtt_) + ((1. - alpha_) * rtt_milliseconds); } TRANSPORT_ALWAYS_INLINE void updateAverageWindowSize(double current_window) { @@ -74,6 +96,60 @@ class TransportStatistics { queuing_delay_ = queuing_delay; } + TRANSPORT_ALWAYS_INLINE void updateInterestFecTx(uint64_t int_tx) { + interest_FEC_tx_ += int_tx; + } + + TRANSPORT_ALWAYS_INLINE void updateBytesFecRecv(uint64_t bytes) { + bytes_FEC_received_ += bytes; + } + + TRANSPORT_ALWAYS_INLINE void updateLostData(uint64_t pkt) { + lost_data_ += pkt; + } + + TRANSPORT_ALWAYS_INLINE void updateDefinitelyLostData(uint64_t pkt) { + definitely_lost_data_ += pkt; + } + + TRANSPORT_ALWAYS_INLINE void updateRecoveredData(uint64_t bytes) { + recovered_data_ += bytes; + } + + TRANSPORT_ALWAYS_INLINE void updateCCState(int status) { status_ = status; } + + TRANSPORT_ALWAYS_INLINE void updateAveragePendingPktCount(double pkt) { + avg_pending_pkt_ = (alpha_ * avg_pending_pkt_) + ((1. - alpha_) * pkt); + } + + TRANSPORT_ALWAYS_INLINE void updateReceivedNacks(uint32_t nacks) { + received_nacks_ += nacks; + } + + TRANSPORT_ALWAYS_INLINE void updateReceivedFEC(uint32_t pkt) { + received_fec_ += pkt; + } + + TRANSPORT_ALWAYS_INLINE void updateResidualLossRate(double val) { + residual_loss_rate_ = val; + } + + TRANSPORT_ALWAYS_INLINE void updateQualityScore(uint8_t val) { + quality_score_ = val; + } + + TRANSPORT_ALWAYS_INLINE void updateCongestionState(bool state) { + in_congestion_ = state; + } + + TRANSPORT_ALWAYS_INLINE void setAlert(statsAlerts x) { + alerts_ |= 1UL << (uint32_t)x; + } + + TRANSPORT_ALWAYS_INLINE void clearAlert(statsAlerts x) { + alerts_ &= ~(1UL << (uint32_t)x); + } + TRANSPORT_ALWAYS_INLINE uint64_t getRetxCount() const { return retx_count_; } TRANSPORT_ALWAYS_INLINE uint64_t getBytesRecv() const { @@ -96,6 +172,52 @@ class TransportStatistics { return queuing_delay_; } + TRANSPORT_ALWAYS_INLINE uint64_t getInterestFecTxCount() const { + return interest_FEC_tx_; + } + + TRANSPORT_ALWAYS_INLINE uint64_t getBytesFecRecv() const { + return bytes_FEC_received_; + } + + TRANSPORT_ALWAYS_INLINE uint64_t getLostData() const { return lost_data_; } + + TRANSPORT_ALWAYS_INLINE uint64_t getDefinitelyLostData() const { + return definitely_lost_data_; + } + + TRANSPORT_ALWAYS_INLINE uint64_t getBytesRecoveredData() const { + return recovered_data_; + } + + TRANSPORT_ALWAYS_INLINE int getCCStatus() const { return status_; } + + TRANSPORT_ALWAYS_INLINE double getAveragePendingPktCount() const { + return avg_pending_pkt_; + } + + TRANSPORT_ALWAYS_INLINE uint32_t getReceivedNacks() const { + return received_nacks_; + } + + TRANSPORT_ALWAYS_INLINE uint32_t getReceivedFEC() const { + return received_fec_; + } + + TRANSPORT_ALWAYS_INLINE double getResidualLossRate() const { + return residual_loss_rate_; + } + + TRANSPORT_ALWAYS_INLINE uint8_t getQualityScore() const { + return quality_score_; + } + + TRANSPORT_ALWAYS_INLINE bool isCongested() const { return in_congestion_; } + + TRANSPORT_ALWAYS_INLINE uint32_t getAlerts() const { return alerts_; } + + TRANSPORT_ALWAYS_INLINE void setAlpha(double val) { alpha_ = val; } + TRANSPORT_ALWAYS_INLINE void reset() { retx_count_ = 0; bytes_received_ = 0; @@ -103,6 +225,18 @@ class TransportStatistics { avg_window_size_ = 0; interest_tx_ = 0; loss_ratio_ = 0; + interest_FEC_tx_ = 0; + bytes_FEC_received_ = 0; + lost_data_ = 0; + definitely_lost_data_ = 0; + recovered_data_ = 0; + status_ = 0; + // avg_data_rtt_ = 0; + avg_pending_pkt_ = 0; + received_nacks_ = 0; + received_fec_ = 0; + in_congestion_ = false; + quality_score_ = 5; } private: @@ -114,6 +248,23 @@ class TransportStatistics { double alpha_; double loss_ratio_; double queuing_delay_; + uint64_t interest_FEC_tx_; + uint64_t bytes_FEC_received_; + uint64_t lost_data_; + uint64_t definitely_lost_data_; + uint64_t recovered_data_; + int status_; // transport status (e.g. sync status, congestion etc.) + double avg_pending_pkt_; + uint32_t received_nacks_; + uint32_t received_fec_; + bool in_congestion_; + double residual_loss_rate_; + uint8_t quality_score_; + + // alerts is a bit vector used to signal to the upper layer that + // something bad is appening in the network, the encode is done accoding to + // the enum alerts; + uint32_t alerts_; }; } // namespace interface diff --git a/libtransport/includes/hicn/transport/interfaces/verification_policy.h b/libtransport/includes/hicn/transport/interfaces/verification_policy.h deleted file mode 100644 index cb5140ac1..000000000 --- a/libtransport/includes/hicn/transport/interfaces/verification_policy.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 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 <cstdint> - -namespace transport { -namespace interface { - -/** - * This policy allows the application to tell the transport what to do in case - * the verification of a content object fails. - */ -enum class VerificationPolicy : std::uint8_t { - DROP_PACKET, - ACCEPT_PACKET, - ABORT_SESSION -}; -} // namespace interface -} // namespace transport
\ No newline at end of file |