diff options
Diffstat (limited to 'libtransport/includes/hicn/transport/interfaces')
12 files changed, 1082 insertions, 0 deletions
diff --git a/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt b/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt new file mode 100644 index 000000000..38e6143f0 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt @@ -0,0 +1,35 @@ +# 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. + +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}/statistics.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 new file mode 100644 index 000000000..6ae07797e --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/callbacks.h @@ -0,0 +1,116 @@ +/* + * 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 <hicn/transport/interfaces/statistics.h> +#include <hicn/transport/interfaces/verification_policy.h> + +#include <functional> +#include <system_error> + +namespace utils { +class MemBuf; +} + +namespace transport { + +namespace protocol { + +class IcnObserver; + +} // namespace protocol + +namespace core { +class ContentObject; +class Interest; +} // namespace core + +namespace interface { + +// Forward declarations +class ConsumerSocket; +class ProducerSocket; + +/** + * The ConsumerInterestCallback will be called in different parts of the + * consumer socket processing pipeline, with a ConsumerSocket and an Interest as + * parameters. + */ +using ConsumerInterestCallback = + std::function<void(ConsumerSocket &, const core::Interest &)>; + +/** + * The ConsumerTimerCallback is called periodically for exposing to applications + * a summary of the statistics of the transport protocol in use. + */ +using ConsumerTimerCallback = + std::function<void(ConsumerSocket &, const TransportStatistics &stats)>; + +/** + * The ProducerContentCallback will be called by the producer socket right after + * a content has been segmented and published. + */ +using ProducerContentCallback = std::function<void( + ProducerSocket &, const std::error_code &, uint64_t bytes_written)>; + +/** + * The ConsumerContentObjectCallback will be called in different parts of the + * consumer socket processing pipeline, with a ConsumerSocket and an + * ContentObject as parameters. + */ +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. + */ +using ProducerContentObjectCallback = + std::function<void(ProducerSocket &, core::ContentObject &)>; + +/** + * The ProducerContentObjectCallback will be called in different parts of the + * consumer socket processing pipeline, with a ProducerSocket and an + * Interest as parameters. + */ +using ProducerInterestCallback = + std::function<void(ProducerSocket &, core::Interest &)>; + +extern std::nullptr_t VOID_HANDLER; + +} // namespace interface + +} // namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h new file mode 100644 index 000000000..097b0a8c0 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h @@ -0,0 +1,32 @@ +/* + * 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 protocol); + ~P2PSecureConsumerSocket() = default; +}; + +} // 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 new file mode 100644 index 000000000..6f0d48bb9 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_producer.h @@ -0,0 +1,36 @@ +/* + * 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/publication_options.h b/libtransport/includes/hicn/transport/interfaces/publication_options.h new file mode 100644 index 000000000..6910e5371 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/publication_options.h @@ -0,0 +1,43 @@ +/* + * 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 <hicn/transport/core/name.h> + +namespace transport { + +namespace interface { + +class PublicationOptions { + public: + template <typename T> + PublicationOptions(T&& name, uint32_t lifetime) + : name_(std::forward<T&&>(name)), + content_lifetime_milliseconds_(lifetime) {} + + TRANSPORT_ALWAYS_INLINE const core::Name& getName() const { return name_; } + TRANSPORT_ALWAYS_INLINE uint32_t getLifetime() const { + return content_lifetime_milliseconds_; + } + + private: + core::Name name_; + uint32_t content_lifetime_milliseconds_; + // TODO Signature +}; +} // 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/rtc_socket_producer.h new file mode 100644 index 000000000..218240f83 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/rtc_socket_producer.h @@ -0,0 +1,32 @@ +/* + * 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> + +namespace transport { + +namespace interface { + +class RTCProducerSocket : public ProducerSocket { + public: + RTCProducerSocket(); + ~RTCProducerSocket() = default; +}; + +} // namespace interface + +} // end namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/socket_consumer.h b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h new file mode 100644 index 000000000..e9e671edd --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h @@ -0,0 +1,298 @@ +/* + * 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 <hicn/transport/config.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> + +#include <asio/io_service.hpp> + +#define CONSUMER_FINISHED 0 +#define CONSUMER_BUSY 1 +#define CONSUMER_RUNNING 2 + +namespace transport { + +namespace implementation { +class ConsumerSocket; +} + +namespace interface { + +using namespace core; + +/** + * @brief Main interface for consumer applications. + * + * The consumer socket is the main interface for a consumer application. + * It allows to retrieve an application data from one/many producers, by + * hiding all the complexity of the transport protocol used underneath. + */ +class ConsumerSocket { + public: + /** + * The ReadCallback is a class which can be used by the transport for both + * querying the application needs and notifying events. + * + * Beware that the methods of this class will be called synchronously while + * the transport is working, so the operations the application is performing + * on the data retrieved should be executed in another thread in an + * asynchronous manner. Blocking one of these callbacks means blocking the + * transport. + */ + class ReadCallback { + public: + virtual ~ReadCallback() = default; + + /** + * This API will specify to the transport whether the buffer should be + * allocated by the application (and then the retrieved content will be + * copied there) or the transport should allocate the buffer and "move" it + * to the application. In other words, if isBufferMovable return true, the + * transport will transfer the ownership of the read buffer to the + * application, without performing an additional copy, while if it returns + * false the transport will use the getReadBuffer API. + * + * By default this method returns true. + * + */ + virtual bool isBufferMovable() noexcept { return true; } + + /** + * This method will be called by the transport when the content is + * available. The application can then allocate its own buffer and provide + * the address to the transport, which will use it for writing the data. + * Note that if the application won't allocate enough memory this method + * will be called several times, until the internal read buffer will be + * emptied. For ensuring this method will be called once, applications + * should allocate at least maxBufferSize() bytes. + * + * @param application_buffer - Pointer to the application's buffer. + * @param max_length - The length of the application buffer. + */ + virtual void getReadBuffer(uint8_t **application_buffer, + size_t *max_length) = 0; + + /** + * This method will be called by the transport after calling getReadBuffer, + * in order to notify the application that length bytes are available in the + * buffer. The max_length size of the buffer could be larger than the actual + * amount of bytes written. + * + * @param length - The number of bytes placed in the buffer. + */ + virtual void readDataAvailable(size_t length) noexcept = 0; + + /** + * This method will be called by the transport for understanding how many + * bytes it should read (at most) before notifying the application. + * + * By default it reads 64 KB. + */ + virtual size_t maxBufferSize() const { return 64 * 1024; } + + /** + * This method will be called by the transport iff (isBufferMovable == + * true). The unique_ptr underlines the fact that the ownership of the + * buffer is being transferred to the application. + * + * @param buffer - The buffer + */ + virtual void readBufferAvailable( + std::unique_ptr<utils::MemBuf> &&buffer) noexcept {} + + /** + * readError() will be invoked if an error occurs reading from the + * transport. + * + * @param ec - An error code describing the error. + */ + virtual void readError(const std::error_code ec) noexcept = 0; + + /** + * This callback will be invoked when the whole content is retrieved. The + * transport itself knows when a content is retrieved (since it is not an + * opaque bytestream like TCP), and the transport itself is able to tell + * the application when the transfer is done. + */ + virtual void readSuccess(std::size_t total_size) noexcept = 0; + }; + + /** + * @brief Create a new consumer socket. + * + * @param protocol - The transport protocol to use. So far the following + * transport are supported: + * - CBR: Constant bitrate + * - Raaqm: Based on paper: Optimal multipath congestion control and request + * forwarding in information-centric networks: Protocol design and + * experimentation. G Carofiglio, M Gallo, L Muscariello. Computer Networks + * 110, 104-117 + * - RTC: Real time communication + */ + explicit ConsumerSocket(int protocol); + + /** + * @brief Destroy the consumer socket. + */ + ~ConsumerSocket(); + + /** + * @brief Connect the consumer socket to the underlying hICN forwarder. + */ + void connect(); + + /** + * @brief Check whether consumer socket is active or not. + */ + bool isRunning(); + + /** + * Retrieve a content using the protocol specified in the constructor. + * This function blocks until the whole content is downloaded. + * For monitoring the status of the download, the application MUST set the + * ConsumerRead callback. This callback will be called periodically (depending + * on the needs of the application), allowing the application to save the + * retrieved data. + * + * @param name - The name of the content to retrieve. + * + * @return CONSUMER_BUSY if a pending download exists + * @return CONSUMER_FINISHED when the download finishes + * + * Notice that the fact consume() returns CONSUMER_FINISHED does not imply the + * 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); + + /** + * 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. + */ + void stop(); + + /** + * Resume the download from the same exact point it stopped. + */ + void resume(); + + /** + * Get the io_service which is running the transport protocol event loop. + * + * @return A reference to the internal io_service where the transport protocol + * is running. + */ + asio::io_service &getIoService(); + + int setSocketOption(int socket_option_key, ReadCallback *socket_option_value); + + int getSocketOption(int socket_option_key, + ReadCallback **socket_option_value); + + int setSocketOption(int socket_option_key, double socket_option_value); + + int setSocketOption(int socket_option_key, uint32_t socket_option_value); + + int setSocketOption(int socket_option_key, + std::nullptr_t socket_option_value); + + int setSocketOption(int socket_option_key, bool socket_option_value); + + 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<utils::Verifier> &socket_option_value); + + int setSocketOption(int socket_option_key, + const std::string &socket_option_value); + + int setSocketOption(int socket_option_key, + ConsumerTimerCallback socket_option_value); + + int getSocketOption(int socket_option_key, double &socket_option_value); + + int getSocketOption(int socket_option_key, uint32_t &socket_option_value); + + int getSocketOption(int socket_option_key, bool &socket_option_value); + + int getSocketOption(int socket_option_key, Name **socket_option_value); + + 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); + + int getSocketOption(int socket_option_key, std::string &socket_option_value); + + int getSocketOption(int socket_option_key, + ConsumerTimerCallback **socket_option_value); + + int getSocketOption(int socket_option_key, + interface::TransportStatistics **socket_option_value); + + protected: + ConsumerSocket(); + std::unique_ptr<implementation::ConsumerSocket> socket_; +}; + +} // namespace interface + +} // end namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h b/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h new file mode 100644 index 000000000..bcf103b8c --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h @@ -0,0 +1,69 @@ +/* + * 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 <hicn/base.h> +#include <chrono> +#include <cstdint> + +namespace transport { + +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 = + 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 = + 150000; // Content Object +static constexpr uint32_t log_2_default_buffer_size = 12; +static constexpr uint32_t signature_size = 260; // bytes +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 + +// 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; + +// 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; + +// 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 + +} // namespace default_values + +} // namespace interface + +} // end namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/socket_options_keys.h b/libtransport/includes/hicn/transport/interfaces/socket_options_keys.h new file mode 100644 index 000000000..7910a4422 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/socket_options_keys.h @@ -0,0 +1,118 @@ +/* + * 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 + +#define SOCKET_OPTION_GET 0 +#define SOCKET_OPTION_NOT_GET 1 +#define SOCKET_OPTION_SET 2 +#define SOCKET_OPTION_NOT_SET 3 +#define SOCKET_OPTION_DEFAULT 12345 + +namespace transport { + +namespace interface { + +typedef enum { + RAAQM = 0, + CBR = 1, + RTC = 2, +} TransportProtocolAlgorithms; + +typedef enum { + INPUT_BUFFER_SIZE = 101, + OUTPUT_BUFFER_SIZE = 102, + NETWORK_NAME = 103, + NAME_SUFFIX = 104, + MAX_INTEREST_RETX = 105, + 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, +} GeneralTransportOptions; + +typedef enum { + SAMPLE_NUMBER = 201, + GAMMA_VALUE = 202, + BETA_VALUE = 203, + DROP_FACTOR = 204, + MINIMUM_DROP_PROBABILITY = 205, + PATH_ID = 206, + RTT_STATS = 207, +} RaaqmTransportOptions; + +typedef enum { + RATE_ESTIMATION_ALPHA = 301, + RATE_ESTIMATION_OBSERVER = 302, + RATE_ESTIMATION_BATCH_PARAMETER = 303, + RATE_ESTIMATION_CHOICE = 304, +} RateEstimationOptions; + +typedef enum { + INTEREST_OUTPUT = 401, + INTEREST_RETRANSMISSION = 402, + INTEREST_EXPIRED = 403, + INTEREST_SATISFIED = 404, + CONTENT_OBJECT_INPUT = 411, + CONTENT_OBJECT_TO_VERIFY = 413, + VERIFICATION_FAILED = 414, + READ_CALLBACK = 415, + STATS_SUMMARY = 416 +} ConsumerCallbacksOptions; + +typedef enum { + INTEREST_INPUT = 501, + INTEREST_DROP = 502, + INTEREST_PASS = 503, + CACHE_HIT = 506, + CACHE_MISS = 508, + NEW_CONTENT_OBJECT = 509, + CONTENT_OBJECT_SIGN = 513, + CONTENT_OBJECT_READY = 510, + CONTENT_OBJECT_OUTPUT = 511, + CONTENT_PRODUCED = 512, +} ProducerCallbacksOptions; + +typedef enum { OUTPUT_INTERFACE = 601 } DataLinkOptions; + +typedef enum { + VIRTUAL_DOWNLOAD = 701, + USE_CFG_FILE = 702, + STATISTICS +} OtherOptions; + +typedef enum { + SHA_256 = 801, + RSA_256 = 802, +} SignatureType; + +} // 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 new file mode 100644 index 000000000..3fe99fbd4 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/socket_producer.h @@ -0,0 +1,149 @@ +/* + * 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 <hicn/transport/config.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> + +#include <asio/io_service.hpp> + +namespace transport { + +namespace implementation { +class ProducerSocket; +} + +namespace interface { + +using namespace core; + +class ProducerSocket { + public: + explicit ProducerSocket(int protocol = 0); + + virtual ~ProducerSocket(); + + void connect(); + + 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 produce(std::unique_ptr<utils::MemBuf> &&buffer); + + void asyncProduce(const Name &suffix, const uint8_t *buf, size_t buffer_size, + bool is_last = true, uint32_t *start_offset = nullptr); + + void asyncProduce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer, + bool is_last, uint32_t offset, + uint32_t **last_segment = nullptr); + + void asyncProduce(ContentObject &content_object); + + void registerPrefix(const Prefix &producer_namespace); + + void serveForever(); + + void stop(); + + asio::io_service &getIoService(); + + int setSocketOption(int socket_option_key, uint32_t socket_option_value); + + int setSocketOption(int socket_option_key, + std::nullptr_t socket_option_value); + + int setSocketOption(int socket_option_key, bool socket_option_value); + + int setSocketOption(int socket_option_key, Name *socket_option_value); + + int setSocketOption(int socket_option_key, + std::list<Prefix> socket_option_value); + + int setSocketOption(int socket_option_key, + ProducerContentObjectCallback socket_option_value); + + int setSocketOption(int socket_option_key, + ProducerInterestCallback socket_option_value); + + int setSocketOption(int socket_option_key, + ProducerContentCallback socket_option_value); + + int setSocketOption(int socket_option_key, HashAlgorithm socket_option_value); + + int setSocketOption(int socket_option_key, + utils::CryptoSuite socket_option_value); + + int setSocketOption( + int socket_option_key, + const std::shared_ptr<utils::Signer> &socket_option_value); + + int setSocketOption(int socket_option_key, + const std::string &socket_option_value); + + int getSocketOption(int socket_option_key, uint32_t &socket_option_value); + + int getSocketOption(int socket_option_key, bool &socket_option_value); + + int getSocketOption(int socket_option_key, + std::list<Prefix> &socket_option_value); + + int getSocketOption(int socket_option_key, + ProducerContentObjectCallback **socket_option_value); + + int getSocketOption(int socket_option_key, + ProducerContentCallback **socket_option_value); + + int getSocketOption(int socket_option_key, + ProducerInterestCallback **socket_option_value); + + int getSocketOption(int socket_option_key, + HashAlgorithm &socket_option_value); + + int getSocketOption(int socket_option_key, + utils::CryptoSuite &socket_option_value); + + int getSocketOption(int socket_option_key, + std::shared_ptr<utils::Signer> &socket_option_value); + + int getSocketOption(int socket_option_key, std::string &socket_option_value); + + protected: + ProducerSocket(bool); + std::unique_ptr<implementation::ProducerSocket> socket_; +}; + +} // namespace interface + +} // namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/statistics.h b/libtransport/includes/hicn/transport/interfaces/statistics.h new file mode 100644 index 000000000..26831fbf1 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/statistics.h @@ -0,0 +1,121 @@ +/* + * 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 <hicn/transport/portability/c_portability.h> + +#include <cstdint> + +namespace transport { + +namespace interface { + +class IcnObserver { + public: + virtual ~IcnObserver(){}; + + virtual void notifyStats(double throughput) = 0; + virtual void notifyDownloadTime(double downloadTime) = 0; +}; + +class TransportStatistics { + static constexpr double default_alpha = 0.7; + + public: + TransportStatistics(double alpha = default_alpha) + : retx_count_(0), + bytes_received_(0), + average_rtt_(0), + avg_window_size_(0), + interest_tx_(0), + alpha_(alpha), + loss_ratio_(0.0), + queuing_delay_(0.0) {} + + TRANSPORT_ALWAYS_INLINE void updateRetxCount(uint64_t retx) { + retx_count_ += retx; + } + + TRANSPORT_ALWAYS_INLINE void updateBytesRecv(uint64_t bytes) { + bytes_received_ += bytes; + } + + TRANSPORT_ALWAYS_INLINE void updateAverageRtt(uint64_t rtt) { + average_rtt_ = (alpha_ * average_rtt_) + ((1. - alpha_) * double(rtt)); + } + + TRANSPORT_ALWAYS_INLINE void updateAverageWindowSize(double current_window) { + avg_window_size_ = + (alpha_ * avg_window_size_) + ((1. - alpha_) * current_window); + } + + TRANSPORT_ALWAYS_INLINE void updateInterestTx(uint64_t int_tx) { + interest_tx_ += int_tx; + } + + TRANSPORT_ALWAYS_INLINE void updateLossRatio(double loss_ratio) { + loss_ratio_ = loss_ratio; + } + + TRANSPORT_ALWAYS_INLINE void updateQueuingDelay(double queuing_delay) { + queuing_delay_ = queuing_delay; + } + + TRANSPORT_ALWAYS_INLINE uint64_t getRetxCount() const { return retx_count_; } + + TRANSPORT_ALWAYS_INLINE uint64_t getBytesRecv() const { + return bytes_received_; + } + + TRANSPORT_ALWAYS_INLINE double getAverageRtt() const { return average_rtt_; } + + TRANSPORT_ALWAYS_INLINE double getAverageWindowSize() const { + return avg_window_size_; + } + + TRANSPORT_ALWAYS_INLINE uint64_t getInterestTx() const { + return interest_tx_; + } + + TRANSPORT_ALWAYS_INLINE double getLossRatio() const { return loss_ratio_; } + + TRANSPORT_ALWAYS_INLINE double getQueuingDelay() const { + return queuing_delay_; + } + + TRANSPORT_ALWAYS_INLINE void reset() { + retx_count_ = 0; + bytes_received_ = 0; + average_rtt_ = 0; + avg_window_size_ = 0; + interest_tx_ = 0; + loss_ratio_ = 0; + } + + private: + uint64_t retx_count_; + uint64_t bytes_received_; + double average_rtt_; + double avg_window_size_; + uint64_t interest_tx_; + double alpha_; + double loss_ratio_; + double queuing_delay_; +}; + +} // namespace interface + +} // end namespace transport diff --git a/libtransport/includes/hicn/transport/interfaces/verification_policy.h b/libtransport/includes/hicn/transport/interfaces/verification_policy.h new file mode 100644 index 000000000..cb5140ac1 --- /dev/null +++ b/libtransport/includes/hicn/transport/interfaces/verification_policy.h @@ -0,0 +1,33 @@ +/* + * 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 |