--- /dev/null
+# Copyright (c) 2019 Cisco and/or its affiliates.\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at:\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+########################################\r
+#\r
+# Find the PThread libraries and includes\r
+# This module sets:\r
+# PTHREAD_FOUND: True if pthread was found\r
+# PTHREADR_LIBRARY: The pthread library\r
+# PTHREAD_LIBRARIES: The pthread library and dependencies\r
+# PTHREAD_INCLUDE_DIR: The pthread include dir\r
+#\r
+\r
+\r
+set(PTHREAD_SEARCH_PATH_LIST\r
+ ${PTHREAD_HOME}\r
+ $ENV{PTHREAD_HOME}\r
+ /usr/local\r
+ /opt\r
+ /usr\r
+)\r
+\r
+find_path(PTHREAD_INCLUDE_DIR pthread.h\r
+ HINTS ${PTHREAD_SEARCH_PATH_LIST}\r
+ PATH_SUFFIXES include\r
+ DOC "Find the pthreadincludes"\r
+)\r
+\r
+if(CMAKE_SIZEOF_VOID_P EQUAL 8)\r
+ find_library(PTHREAD_LIBRARY NAMES pthreadVC2.lib\r
+ HINTS ${PTHREAD_SEARCH_PATH_LIST}\r
+ PATH_SUFFIXES lib/x64\r
+ DOC "Find the pthread libraries"\r
+ )\r
+elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)\r
+ find_library(PTHREAD_LIBRARY NAMES pthreadVC2.lib\r
+ HINTS ${PTHREAD_SEARCH_PATH_LIST}\r
+ PATH_SUFFIXES lib/x32\r
+ DOC "Find the pthread libraries"\r
+ )\r
+endif()\r
+\r
+\r
+set(PTHREAD_LIBRARIES ${PTHREAD_LIBRARY})\r
+set(PTHREAD_INCLUDE_DIRS ${PTHREAD_INCLUDE_DIR})\r
+\r
+include(FindPackageHandleStandardArgs)\r
+find_package_handle_standard_args(Pthread DEFAULT_MSG PTHREAD_LIBRARIES PTHREAD_INCLUDE_DIRS)
\ No newline at end of file
--- /dev/null
+# 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.
+
+if(WIN32)
+ find_package_wrapper(LibEvent REQUIRED)
+ find_package_wrapper(OpenSSL REQUIRED)
+ find_package_wrapper(PThread REQUIRED)
+ find_library(WSOCK32_LIBRARY wsock32 required)
+ find_library(WS2_32_LIBRARY ws2_32 required)
+ list(APPEND WINDOWS_LIBRARIES
+ ${LIBEVENT_LIBRARIES}
+ ${OPENSSL_LIBRARIES}
+ ${PTHREAD_LIBRARIES}
+ ${WSOCK32_LIBRARY}
+ ${WS2_32_LIBRARY}
+ )
+
+ list(APPEND WINDOWS_INCLUDE_DIRS
+ ${LIBEVENT_INCLUDE_DIRS}
+ ${OPENSSL_INCLUDE_DIR}
+ ${PTHREAD_INCLUDE_DIRS}
+ )
+endif()
\ No newline at end of file
)
endif ()
+include(WindowsMacros)
include(IosMacros)
find_package_wrapper(Libparc REQUIRED)
find_package_wrapper(Asio REQUIRED)
${VPP_LIBRARIES}
${ANDROID_LIBRARIES}
${OPENSSL_LIBRARIES}
+ ${WINDOWS_LIBRARIES}
)
# Include dirs -- Order does matter!
${LIBPARC_INCLUDE_DIRS}
${CMAKE_THREADS_INCLUDE_DIRS}
${ASIO_INCLUDE_DIRS}
+ ${WINDOWS_INCLUDE_DIRS}
)
add_subdirectory(${TRANSPORT_ROOT_PATH})
\ No newline at end of file
#include <hicn/transport/utils/branch_prediction.h>
extern "C" {
+#ifndef _WIN32
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
+#endif
#include <hicn/hicn.h>
}
#include <hicn/transport/core/hicn_forwarder_interface.h>
-
#define ADDR_INET 1
#define ADDR_INET6 2
#define ADD_ROUTE 3
#include <hicn/transport/utils/hash.h>
extern "C" {
+#ifndef _WIN32
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
+#endif
#include <hicn/hicn.h>
}
#include <unordered_map>
extern "C" {
+#ifndef _WIN32
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
+#endif
#include <hicn/hicn.h>
};
#include <hicn/transport/utils/log.h>
extern "C" {
+#ifndef _WIN32
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
+#endif
#include <hicn/error.h>
}
on_interest_timeout_callback_(),
received_(false) {}
-PendingInterest::PendingInterest(Interest::Ptr &&interest,
- const OnContentObjectCallback &&on_content_object,
- const OnInterestTimeoutCallback &&on_interest_timeout,
- std::unique_ptr<asio::steady_timer> &&timer)
+PendingInterest::PendingInterest(
+ Interest::Ptr &&interest, const OnContentObjectCallback &&on_content_object,
+ const OnInterestTimeoutCallback &&on_interest_timeout,
+ std::unique_ptr<asio::steady_timer> &&timer)
: interest_(std::move(interest)),
timer_(std::move(timer)),
on_content_object_callback_(std::move(on_content_object)),
return on_content_object_callback_;
}
-void PendingInterest::setOnDataCallback(const OnContentObjectCallback &on_content_object) {
+void PendingInterest::setOnDataCallback(
+ const OnContentObjectCallback &on_content_object) {
PendingInterest::on_content_object_callback_ = on_content_object;
}
return on_interest_timeout_callback_;
}
-void PendingInterest::setOnTimeoutCallback(const OnInterestTimeoutCallback &on_interest_timeout) {
+void PendingInterest::setOnTimeoutCallback(
+ const OnInterestTimeoutCallback &on_interest_timeout) {
PendingInterest::on_interest_timeout_callback_ = on_interest_timeout;
}
template <typename ForwarderInt>
class Portal;
-typedef std::function<void(Interest::Ptr&&, ContentObject::Ptr&&)> OnContentObjectCallback;
-typedef std::function<void(Interest::Ptr&&)> OnInterestTimeoutCallback;
+typedef std::function<void(Interest::Ptr &&, ContentObject::Ptr &&)>
+ OnContentObjectCallback;
+typedef std::function<void(Interest::Ptr &&)> OnInterestTimeoutCallback;
typedef std::function<void(const std::error_code &)> TimerCallback;
class PendingInterest {
const OnInterestTimeoutCallback &getOnTimeoutCallback() const;
- void setOnTimeoutCallback(const OnInterestTimeoutCallback &on_interest_timeout);
+ void setOnTimeoutCallback(
+ const OnInterestTimeoutCallback &on_interest_timeout);
private:
Interest::Ptr interest_;
forwarder_interface_.connect(is_consumer);
}
- ~Portal() {
- stopEventsLoop(true);
- }
+ ~Portal() { stopEventsLoop(true); }
TRANSPORT_ALWAYS_INLINE bool interestIsPending(const Name &name) {
auto it = pending_interest_hash_table_.find(name);
std::placeholders::_1, name));
}
- TRANSPORT_ALWAYS_INLINE void sendInterest(Interest::Ptr &&interest,
- const OnContentObjectCallback &&on_content_object_callback,
- const OnInterestTimeoutCallback &&on_interest_timeout_callback) {
-
+ TRANSPORT_ALWAYS_INLINE void sendInterest(
+ Interest::Ptr &&interest,
+ const OnContentObjectCallback &&on_content_object_callback,
+ const OnInterestTimeoutCallback &&on_interest_timeout_callback) {
const Name name(interest->getName(), true);
// Send it
std::make_unique<asio::steady_timer>(io_service_));
pending_interest_hash_table_[name]->startCountdown(
- std::bind(&Portal<ForwarderInt>::timerHandler,
- this, std::placeholders::_1, name));
-
+ std::bind(&Portal<ForwarderInt>::timerHandler, this,
+ std::placeholders::_1, name));
}
TRANSPORT_ALWAYS_INLINE void timerHandler(const std::error_code &ec,
std::unique_ptr<PendingInterest> ptr = std::move(it->second);
pending_interest_hash_table_.erase(it);
- if(ptr->getOnTimeoutCallback() != UNSET_CALLBACK){
- ptr->on_interest_timeout_callback_(std::move(ptr->getInterest()));
- }else if (consumer_callback_) {
+ if (ptr->getOnTimeoutCallback() != UNSET_CALLBACK) {
+ ptr->on_interest_timeout_callback_(std::move(ptr->getInterest()));
+ } else if (consumer_callback_) {
consumer_callback_->onTimeout(std::move(ptr->getInterest()));
}
}
clear();
- if(kill_connection) {
+ if (kill_connection) {
connector_.close();
}
interest_ptr->setReceived();
pending_interest_hash_table_.erase(content_object->getName());
- if(interest_ptr->getOnDataCallback() != UNSET_CALLBACK){
- interest_ptr->on_content_object_callback_(
- std::move(interest_ptr->getInterest()),
- std::move(content_object));
- }else if (consumer_callback_) {
+ if (interest_ptr->getOnDataCallback() != UNSET_CALLBACK) {
+ interest_ptr->on_content_object_callback_(
+ std::move(interest_ptr->getInterest()),
+ std::move(content_object));
+ } else if (consumer_callback_) {
consumer_callback_->onContentObject(
std::move(interest_ptr->getInterest()),
std::move(content_object));
#include <hicn/transport/errors/errors.h>
#include <hicn/transport/utils/string_tokenizer.h>
+#ifndef _WIN32
extern "C" {
#include <arpa/inet.h>
}
+#else
+#include <hicn/transport/portability/win_portability.h>
+#endif
#include <cstring>
#include <memory>
* limitations under the License.
*/
+#ifdef _WIN32
+#include <hicn/transport/portability/win_portability.h>
+#endif
#include <hicn/transport/core/socket_connector.h>
#include <hicn/transport/errors/errors.h>
#include <hicn/transport/utils/log.h>
if (!output_buffer_.empty()) {
doWrite();
}
- } else if (ec.value() == static_cast<int>(std::errc::operation_canceled)) {
+ } else if (ec.value() ==
+ static_cast<int>(std::errc::operation_canceled)) {
// The connection has been closed by the application.
return;
} else {
if (TRANSPORT_EXPECT_TRUE(!ec)) {
receive_callback_(std::move(read_msg_));
doReadHeader();
- } else if (ec.value() == static_cast<int>(std::errc::operation_canceled)) {
+ } else if (ec.value() ==
+ static_cast<int>(std::errc::operation_canceled)) {
// The connection has been closed by the application.
return;
} else {
} else {
TRANSPORT_LOGE("Decoding error. Ignoring packet.");
}
- } else if (ec.value() == static_cast<int>(std::errc::operation_canceled)) {
+ } else if (ec.value() ==
+ static_cast<int>(std::errc::operation_canceled)) {
// The connection has been closed by the application.
return;
} else {
#include <hicn/transport/core/name.h>
#include <hicn/transport/utils/branch_prediction.h>
-#include <asio/steady_timer.hpp>
#include <asio.hpp>
+#include <asio/steady_timer.hpp>
#include <deque>
namespace transport {
VPPForwarderInterface::~VPPForwarderInterface() {
if (sw_if_index_ != uint32_t(~0) && VPPForwarderInterface::memif_api_) {
- int ret = memif_binary_api_delete_memif(VPPForwarderInterface::memif_api_, sw_if_index_);
+ int ret = memif_binary_api_delete_memif(VPPForwarderInterface::memif_api_,
+ sw_if_index_);
if (ret < 0) {
TRANSPORT_LOGE("Error deleting memif with sw idx %u.", sw_if_index_);
memif_output_params_t output_params = {0};
ret = memif_binary_api_create_memif(VPPForwarderInterface::memif_api_,
- &input_params, &output_params);
+ &input_params, &output_params);
if (ret < 0) {
throw errors::RuntimeException(
input.swif = sw_if_index_;
- int ret = hicn_binary_api_register_cons_app(
- VPPForwarderInterface::hicn_api_, &input, &output);
+ int ret = hicn_binary_api_register_cons_app(VPPForwarderInterface::hicn_api_,
+ &input, &output);
if (ret < 0) {
throw errors::RuntimeException(hicn_binary_api_get_error_string(ret));
input.cs_reserved = content_store_reserved_;
int ret = hicn_binary_api_register_prod_app(
- VPPForwarderInterface::hicn_api_, &input, &output);
+ VPPForwarderInterface::hicn_api_, &input, &output);
if (ret < 0) {
throw errors::RuntimeException(hicn_binary_api_get_error_string(ret));
params.prefix->prefix_len = addr.prefix_len;
params.face_id = face_id_;
- int ret = hicn_binary_api_register_route(
- VPPForwarderInterface::hicn_api_, ¶ms);
+ int ret = hicn_binary_api_register_route(VPPForwarderInterface::hicn_api_,
+ ¶ms);
if (ret < 0) {
throw errors::RuntimeException(hicn_binary_api_get_error_string(ret));
#pragma once
+#ifdef _WIN32
+#include <hicn/transport/portability/win_portability.h>
+#endif
+
#include <hicn/transport/utils/sharable_vector.h>
#include <map>
#include <hicn/transport/portability/portability.h>
#include <hicn/transport/utils/sharable_vector.h>
+#ifndef _WIN32
#include <sys/uio.h>
+#endif
+
#include <memory>
namespace transport {
producer_->setSocketOption(GeneralTransportOptions::OUTPUT_BUFFER_SIZE,
uint32_t{150000});
- producer_->setSocketOption(
- ProducerCallbacksOptions::CONTENT_PRODUCED,
- std::bind(&AsyncFullDuplexSocket::onContentProduced, this, _1, _2, _3));
+ ProducerContentCallback producer_callback =
+ std::bind(&AsyncFullDuplexSocket::onContentProduced, this, _1, _2, _3);
+ producer_->setSocketOption(ProducerCallbacksOptions::CONTENT_PRODUCED,
+ producer_callback);
producer_->connect();
- consumer_->setSocketOption(ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY,
- (ConsumerContentObjectVerificationCallback)[](
- ConsumerSocket & s, const ContentObject &c)
- ->bool { return true; });
+ consumer_->setSocketOption(
+ ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY,
+ (ConsumerContentObjectVerificationCallback)[](ConsumerSocket & s,
+ const ContentObject &c)
+ ->bool { return true; });
- ConsumerContentCallback callback =
+ ConsumerContentCallback consumer_callback =
std::bind(&AsyncFullDuplexSocket::onContentRetrieved, this, _1, _2, _3);
consumer_->setSocketOption(ConsumerCallbacksOptions::CONTENT_RETRIEVED,
- callback);
+ consumer_callback);
consumer_->setSocketOption(GeneralTransportOptions::MAX_INTEREST_RETX,
uint32_t{4});
RTCConsumerSocket::RTCConsumerSocket(int protocol, asio::io_service &io_service)
: ConsumerSocket(protocol, io_service) {}
-RTCConsumerSocket::RTCConsumerSocket(int protocol)
- : ConsumerSocket(protocol) {}
+RTCConsumerSocket::RTCConsumerSocket(int protocol) : ConsumerSocket(protocol) {}
RTCConsumerSocket::~RTCConsumerSocket() {}
prodLabel_ = ((rand() % 255) << 24UL);
}
-
RTCProducerSocket::~RTCProducerSocket() {}
void RTCProducerSocket::registerName(Prefix &producer_namespace) {
}
ProducerSocket::~ProducerSocket() {
-
processing_thread_stop_ = true;
portal_->stopEventsLoop(true);
}
}
-void ProducerSocket::stop() {
- portal_->stopEventsLoop();
-}
+void ProducerSocket::stop() { portal_->stopEventsLoop(); }
void ProducerSocket::registerPrefix(const Prefix &producer_namespace) {
served_namespaces_.push_back(producer_namespace);
""
)
+if(WIN32)
+ list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/win_portability.h
+ )
+endif()
+
set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
\ No newline at end of file
#pragma once
+#ifdef _WIN32
+#include <hicn/transport/portability/win_portability.h>
+#endif
+
#include <hicn/transport/portability/c_portability.h>
#include <string.h>
--- /dev/null
+/*\r
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.\r
+ * Copyright 2017 Facebook, Inc.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#pragma once\r
+#define WIN32_LEAN_AND_MEAN\r
+#define NOMINMAX\r
+#include <parc/windows/parc_Utils.h>\r
+#include <stdint.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <time.h>\r
+#include <windows.h>\r
+#include <winsock2.h>\r
+#include <ws2ipdef.h>\r
+#include <ws2tcpip.h>\r
+#include <algorithm>\r
+\r
+#define __ORDER_LITTLE_ENDIAN__ 0x41424344UL\r
+#define __ORDER_BIG_ENDIAN__ 0x44434241UL\r
+#define __BYTE_ORDER__ ('ABCD')\r
+#undef DELETE\r
+\r
+#define HAVE_STRUCT_TIMESPEC\r
+#include <pthread.h>
\ No newline at end of file
raw_data_bytes_received_(0),
last_raw_data_bytes_received_(0),
rtt_samples_(samples_),
+ last_received_pkt_(std::chrono::steady_clock::now()),
average_rtt_(0),
- alpha_(ALPHA) {
- gettimeofday(&m_last_received_pkt_, 0);
-}
+ alpha_(ALPHA) {}
RaaqmDataPath &RaaqmDataPath::insertNewRtt(uint64_t new_rtt) {
rtt_ = new_rtt;
prop_delay_ = rtt_min_;
}
- gettimeofday(&m_last_received_pkt_, 0);
+ last_received_pkt_ = std::chrono::steady_clock::now();
return *this;
}
unsigned int RaaqmDataPath::getPropagationDelay() { return prop_delay_; }
bool RaaqmDataPath::isStale() {
- struct timeval now;
- gettimeofday(&now, 0);
- double time = getMicroSeconds(now) - getMicroSeconds(m_last_received_pkt_);
+ TimePoint now = std::chrono::steady_clock::now();
+ auto time = std::chrono::duration_cast<Microseconds>(now - last_received_pkt_)
+ .count();
if (time > 2000000) {
return true;
}
#include <hicn/transport/utils/min_filter.h>
-#include <sys/time.h>
+#include <chrono>
#include <climits>
#include <iostream>
namespace protocol {
class RaaqmDataPath {
+ using TimePoint = std::chrono::steady_clock::time_point;
+ using Microseconds = std::chrono::microseconds;
+
public:
RaaqmDataPath(double drop_factor, double minimum_drop_probability,
unsigned new_timer, unsigned int samples,
/**
* Time of the last call to the path reporter method
*/
- struct timeval m_last_received_pkt_;
+ TimePoint last_received_pkt_;
double average_rtt_;
double alpha_;
#include <hicn/transport/protocols/rate_estimation.h>
#include <hicn/transport/utils/log.h>
+#include <thread>
+
namespace transport {
namespace protocol {
pthread_mutex_unlock(&(estimator->mutex_));
while (estimator->is_running_) {
- usleep(KV * dat_rtt);
+ std::this_thread::sleep_for(
+ std::chrono::microseconds((uint64_t)(KV * dat_rtt)));
pthread_mutex_lock(&(estimator->mutex_));
this->win_current_ = 1.0;
pthread_mutex_init(&(this->mutex_), NULL);
- gettimeofday(&(this->start_time_), 0);
- gettimeofday(&(this->begin_batch_), 0);
+ this->start_time_ = std::chrono::steady_clock::now();
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
InterRttEstimator::~InterRttEstimator() {
}
void InterRttEstimator::onWindowIncrease(double win_current) {
- timeval end;
- gettimeofday(&end, 0);
- double delay = RaaqmDataPath::getMicroSeconds(end) -
- RaaqmDataPath::getMicroSeconds(this->begin_batch_);
+ TimePoint end = std::chrono::steady_clock::now();
+ auto delay =
+ std::chrono::duration_cast<Microseconds>(end - this->begin_batch_)
+ .count();
pthread_mutex_lock(&(this->mutex_));
this->avg_win_ += this->win_current_ * delay;
this->win_change_ += delay;
pthread_mutex_unlock(&(this->mutex_));
- gettimeofday(&(this->begin_batch_), 0);
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
void InterRttEstimator::onWindowDecrease(double win_current) {
- timeval end;
- gettimeofday(&end, 0);
- double delay = RaaqmDataPath::getMicroSeconds(end) -
- RaaqmDataPath::getMicroSeconds(this->begin_batch_);
+ TimePoint end = std::chrono::steady_clock::now();
+ auto delay =
+ std::chrono::duration_cast<Microseconds>(end - this->begin_batch_)
+ .count();
pthread_mutex_lock(&(this->mutex_));
this->avg_win_ += this->win_current_ * delay;
this->win_change_ += delay;
pthread_mutex_unlock(&(this->mutex_));
- gettimeofday(&(this->begin_batch_), 0);
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
ALaTcpEstimator::ALaTcpEstimator() {
this->estimation_ = 0.0;
this->observer_ = NULL;
- gettimeofday(&(this->start_time_), 0);
+ this->start_time_ = std::chrono::steady_clock::now();
this->totalSize_ = 0.0;
}
void ALaTcpEstimator::onStart() {
this->totalSize_ = 0.0;
- gettimeofday(&(this->start_time_), 0);
+ this->start_time_ = std::chrono::steady_clock::now();
}
void ALaTcpEstimator::onDownloadFinished() {
- timeval end;
- gettimeofday(&end, 0);
- double delay = RaaqmDataPath::getMicroSeconds(end) -
- RaaqmDataPath::getMicroSeconds(this->start_time_);
+ TimePoint end = std::chrono::steady_clock::now();
+ auto delay =
+ std::chrono::duration_cast<Microseconds>(end - this->start_time_).count();
this->estimation_ = this->totalSize_ * 8 * 1000000 / delay;
if (observer_) {
observer_->notifyStats(this->estimation_);
this->number_of_packets_ = 0;
this->base_alpha_ = alphaArg;
this->alpha_ = alphaArg;
- gettimeofday(&(this->start_time_), 0);
- gettimeofday(&(this->begin_batch_), 0);
+ this->start_time_ = std::chrono::steady_clock::now();
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
void SimpleEstimator::onStart() {
this->estimated_ = false;
this->number_of_packets_ = 0;
this->total_size_ = 0.0;
- gettimeofday(&(this->begin_batch_), 0);
- gettimeofday(&(this->start_time_), 0);
+ this->start_time_ = std::chrono::steady_clock::now();
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
void SimpleEstimator::onDownloadFinished() {
- timeval end;
- gettimeofday(&end, 0);
- double delay = RaaqmDataPath::getMicroSeconds(end) -
- RaaqmDataPath::getMicroSeconds(this->start_time_);
+ TimePoint end = std::chrono::steady_clock::now();
+ auto delay =
+ std::chrono::duration_cast<Microseconds>(end - this->start_time_).count();
if (observer_) {
observer_->notifyDownloadTime(delay);
}
} else {
if (this->number_of_packets_ >=
(int)(75.0 * (double)this->batching_param_ / 100.0)) {
- delay = RaaqmDataPath::getMicroSeconds(end) -
- RaaqmDataPath::getMicroSeconds(this->begin_batch_);
+ delay = std::chrono::duration_cast<Microseconds>(end - this->begin_batch_)
+ .count();
// Assuming all packets carry max_packet_size_ bytes of data
// (8*max_packet_size_ bits); 1000000 factor to convert us to seconds
if (this->estimation_) {
}
this->number_of_packets_ = 0;
this->total_size_ = 0.0;
- gettimeofday(&(this->begin_batch_), 0);
- gettimeofday(&(this->start_time_), 0);
+ this->start_time_ = std::chrono::steady_clock::now();
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
void SimpleEstimator::onDataReceived(int packet_size) {
this->number_of_packets_++;
if (number_of_packets_ == this->batching_param_) {
- timeval end;
- gettimeofday(&end, 0);
- double delay = RaaqmDataPath::getMicroSeconds(end) -
- RaaqmDataPath::getMicroSeconds(this->begin_batch_);
+ TimePoint end = std::chrono::steady_clock::now();
+ auto delay =
+ std::chrono::duration_cast<Microseconds>(end - this->begin_batch_)
+ .count();
// Assuming all packets carry max_packet_size_ bytes of data
// (8*max_packet_size_ bits); 1000000 factor to convert us to seconds
if (this->estimation_) {
this->alpha_ = this->base_alpha_;
this->number_of_packets_ = 0;
this->total_size_ = 0.0;
- gettimeofday(&(this->begin_batch_), 0);
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
}
this->max_packet_size_ = 0;
this->estimation_ = 0.0;
this->win_current_ = 1.0;
- gettimeofday(&(this->begin_batch_), 0);
- gettimeofday(&(this->start_time_), 0);
+ this->begin_batch_ = std::chrono::steady_clock::now();
+ this->start_time_ = std::chrono::steady_clock::now();
}
void BatchingPacketsEstimator::onRttUpdate(double rtt) {
}
void BatchingPacketsEstimator::onWindowIncrease(double win_current) {
- timeval end;
- gettimeofday(&end, 0);
- double delay = RaaqmDataPath::getMicroSeconds(end) -
- RaaqmDataPath::getMicroSeconds(this->begin_batch_);
+ TimePoint end = std::chrono::steady_clock::now();
+ auto delay =
+ std::chrono::duration_cast<Microseconds>(end - this->begin_batch_)
+ .count();
this->avg_win_ += this->win_current_ * delay;
this->win_current_ = win_current;
this->win_change_ += delay;
- gettimeofday(&(this->begin_batch_), 0);
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
void BatchingPacketsEstimator::onWindowDecrease(double win_current) {
- timeval end;
- gettimeofday(&end, 0);
- double delay = RaaqmDataPath::getMicroSeconds(end) -
- RaaqmDataPath::getMicroSeconds(this->begin_batch_);
+ TimePoint end = std::chrono::steady_clock::now();
+ auto delay =
+ std::chrono::duration_cast<Microseconds>(end - this->begin_batch_)
+ .count();
this->avg_win_ += this->win_current_ * delay;
this->win_current_ = win_current;
this->win_change_ += delay;
- gettimeofday(&(this->begin_batch_), 0);
+ this->begin_batch_ = std::chrono::steady_clock::now();
}
} // end namespace protocol
#pragma once
-#include <unistd.h>
-
#include <hicn/transport/protocols/download_observer.h>
#include <hicn/transport/protocols/raaqm_data_path.h>
+#include <chrono>
+
#define BATCH 50
#define KV 20
#define ALPHA 0.8
class IcnRateEstimator {
public:
+ using TimePoint = std::chrono::steady_clock::time_point;
+ using Microseconds = std::chrono::microseconds;
+
IcnRateEstimator(){};
virtual ~IcnRateEstimator(){};
this->observer_ = observer;
};
IcnObserver *observer_;
- struct timeval start_time_;
- struct timeval begin_batch_;
+ TimePoint start_time_;
+ TimePoint begin_batch_;
double base_alpha_;
double alpha_;
double estimation_;
#undef TRANSPORT_EXPECT_TRUE
#undef TRANSPORT_EXPECT_FALSE
+#ifndef _WIN32
#define TRANSPORT_EXPECT_TRUE(x) __builtin_expect((x), 1)
-#define TRANSPORT_EXPECT_FALSE(x) __builtin_expect((x), 0)
\ No newline at end of file
+#define TRANSPORT_EXPECT_FALSE(x) __builtin_expect((x), 0)
+#else
+#define TRANSPORT_EXPECT_TRUE(x) (x)
+#define TRANSPORT_EXPECT_FALSE(x) (x)
+#endif
\ No newline at end of file
#include <hicn/transport/portability/portability.h>
+#ifndef _WIN32
#include <arpa/inet.h>
+#else
+#include <hicn/transport/portability/win_portability.h>
+#endif
+
#include <cstring>
namespace utils {
* The code in this file if adapated from the IOBuf of folly:
* https://github.com/facebook/folly/blob/master/folly/io/IOBuf.h
*/
+#ifdef _WIN32
+#include <hicn/transport/portability/win_portability.h>
+#endif
#include <hicn/transport/utils/membuf.h>
#include <type_traits>
#include <vector>
-// Ignore shadowing warnings within this file, so includers can use -Wshadow.
+#ifndef _WIN32
TRANSPORT_GNU_DISABLE_WARNING("-Wshadow")
+#endif
namespace utils {
ObjectPool() : destructor_(false) {}
- ~ObjectPool() {
- destructor_ = true;
- }
+ ~ObjectPool() { destructor_ = true; }
std::pair<bool, Ptr> get() {
if (object_pool_.empty()) {
#include <hicn/transport/utils/signer.h>
extern "C" {
+#ifndef _WIN32
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
+#endif
#include <hicn/hicn.h>
#include <parc/security/parc_PublicKeySigner.h>
#include <parc/security/parc_Security.h>
SpinLock& spin_lock_;
};
- SpinLock() : std::atomic_flag(false) {}
+ SpinLock() { clear(); }
void lock() {
// busy-wait
#include <hicn/transport/utils/verifier.h>
extern "C" {
+#ifndef _WIN32
TRANSPORT_CLANG_DISABLE_WARNING("-Wextern-c-compat")
+#endif
#include <hicn/hicn.h>
#include <parc/security/parc_CertificateFactory.h>
#include <parc/security/parc_InMemoryVerifier.h>