aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/hicn/transport/core
diff options
context:
space:
mode:
authorMauro Sardara <msardara@cisco.com>2019-03-07 19:11:16 +0100
committerMauro Sardara <msardara@cisco.com>2019-03-08 13:32:22 +0100
commit6aaef596f68a514036d5212fc8697bdaf371e5af (patch)
treed09237bb6810c4aa5eff1a3033633e46bb44e3f6 /libtransport/src/hicn/transport/core
parent3c6c43ef7bc7caa03540b2347e7f180d5b96ec23 (diff)
[HICN-99] Destroy in the correct order and in the correct event loop the attributes of connectors and sockets. Cleanup of prints.
Change-Id: Ie7eef1d186e581aa950f47df20d57681dc33be55 Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport/src/hicn/transport/core')
-rw-r--r--libtransport/src/hicn/transport/core/hicn_binary_api.c2
-rw-r--r--libtransport/src/hicn/transport/core/portal.h98
-rw-r--r--libtransport/src/hicn/transport/core/vpp_binary_api.c6
-rw-r--r--libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc11
4 files changed, 54 insertions, 63 deletions
diff --git a/libtransport/src/hicn/transport/core/hicn_binary_api.c b/libtransport/src/hicn/transport/core/hicn_binary_api.c
index d909578a2..3868c0a14 100644
--- a/libtransport/src/hicn/transport/core/hicn_binary_api.c
+++ b/libtransport/src/hicn/transport/core/hicn_binary_api.c
@@ -134,8 +134,6 @@ int hicn_binary_api_register_cons_app(
CONTEXT_SAVE(context_store, api, mp)
- TRANSPORT_LOGI("Message created");
-
return vpp_binary_api_send_request_wait_reply(api->vpp_api, mp);
}
diff --git a/libtransport/src/hicn/transport/core/portal.h b/libtransport/src/hicn/transport/core/portal.h
index cadf37e8c..d9051c23c 100644
--- a/libtransport/src/hicn/transport/core/portal.h
+++ b/libtransport/src/hicn/transport/core/portal.h
@@ -49,18 +49,19 @@ static constexpr uint32_t pool_size = 2048;
class HandlerMemory {
#ifdef __vpp__
- static constexpr std::size_t memory_size = 1024 * 512;
+ static constexpr std::size_t memory_size = 1024 * 1024;
+
public:
- HandlerMemory() : index_(0) { }
+ HandlerMemory() : index_(0) {}
- HandlerMemory(const HandlerMemory&) = delete;
- HandlerMemory& operator=(const HandlerMemory&) = delete;
+ HandlerMemory(const HandlerMemory &) = delete;
+ HandlerMemory &operator=(const HandlerMemory &) = delete;
- TRANSPORT_ALWAYS_INLINE void* allocate(std::size_t size) {
+ TRANSPORT_ALWAYS_INLINE void *allocate(std::size_t size) {
return &storage_[index_++ % memory_size];
}
- TRANSPORT_ALWAYS_INLINE void deallocate(void* pointer) { }
+ TRANSPORT_ALWAYS_INLINE void deallocate(void *pointer) {}
private:
// Storage space used for handler-based custom memory allocation.
@@ -68,16 +69,16 @@ class HandlerMemory {
uint32_t index_;
#else
public:
- HandlerMemory() { }
+ HandlerMemory() {}
- HandlerMemory(const HandlerMemory&) = delete;
- HandlerMemory& operator=(const HandlerMemory&) = delete;
+ HandlerMemory(const HandlerMemory &) = delete;
+ HandlerMemory &operator=(const HandlerMemory &) = delete;
- TRANSPORT_ALWAYS_INLINE void* allocate(std::size_t size) {
+ TRANSPORT_ALWAYS_INLINE void *allocate(std::size_t size) {
return ::operator new(size);
}
- TRANSPORT_ALWAYS_INLINE void deallocate(void* pointer) {
+ TRANSPORT_ALWAYS_INLINE void deallocate(void *pointer) {
::operator delete(pointer);
}
#endif
@@ -90,34 +91,36 @@ class HandlerAllocator {
public:
using value_type = T;
- explicit HandlerAllocator(HandlerMemory& mem)
- : memory_(mem) {}
+ explicit HandlerAllocator(HandlerMemory &mem) : memory_(mem) {}
template <typename U>
- HandlerAllocator(const HandlerAllocator<U>& other) noexcept
- : memory_(other.memory_) { }
+ HandlerAllocator(const HandlerAllocator<U> &other) noexcept
+ : memory_(other.memory_) {}
- TRANSPORT_ALWAYS_INLINE bool operator==(const HandlerAllocator& other) const noexcept {
+ TRANSPORT_ALWAYS_INLINE bool operator==(const HandlerAllocator &other) const
+ noexcept {
return &memory_ == &other.memory_;
}
- TRANSPORT_ALWAYS_INLINE bool operator!=(const HandlerAllocator& other) const noexcept {
+ TRANSPORT_ALWAYS_INLINE bool operator!=(const HandlerAllocator &other) const
+ noexcept {
return &memory_ != &other.memory_;
}
- TRANSPORT_ALWAYS_INLINE T* allocate(std::size_t n) const {
- return static_cast<T*>(memory_.allocate(sizeof(T) * n));
+ TRANSPORT_ALWAYS_INLINE T *allocate(std::size_t n) const {
+ return static_cast<T *>(memory_.allocate(sizeof(T) * n));
}
- TRANSPORT_ALWAYS_INLINE void deallocate(T* p, std::size_t /*n*/) const {
+ TRANSPORT_ALWAYS_INLINE void deallocate(T *p, std::size_t /*n*/) const {
return memory_.deallocate(p);
}
private:
- template <typename> friend class HandlerAllocator;
+ template <typename>
+ friend class HandlerAllocator;
// The underlying memory.
- HandlerMemory& memory_;
+ HandlerMemory &memory_;
};
// Wrapper class template for handler objects to allow handler memory
@@ -129,35 +132,33 @@ class CustomAllocatorHandler {
public:
using allocator_type = HandlerAllocator<Handler>;
- CustomAllocatorHandler(HandlerMemory& m, Handler h)
- : memory_(m),
- handler_(h) { }
+ CustomAllocatorHandler(HandlerMemory &m, Handler h)
+ : memory_(m), handler_(h) {}
allocator_type get_allocator() const noexcept {
return allocator_type(memory_);
}
- template <typename ...Args>
- void operator()(Args&&... args) {
+ template <typename... Args>
+ void operator()(Args &&... args) {
handler_(std::forward<Args>(args)...);
}
private:
- HandlerMemory& memory_;
+ HandlerMemory &memory_;
Handler handler_;
};
// Helper function to wrap a handler object to add custom allocation.
template <typename Handler>
inline CustomAllocatorHandler<Handler> makeCustomAllocatorHandler(
- HandlerMemory& m, Handler h) {
+ HandlerMemory &m, Handler h) {
return CustomAllocatorHandler<Handler>(m, h);
}
class Pool {
public:
- Pool(asio::io_service &io_service)
- : io_service_(io_service) {
+ Pool(asio::io_service &io_service) : io_service_(io_service) {
increasePendingInterestPool();
increaseInterestPool();
increaseContentObjectPool();
@@ -223,7 +224,7 @@ class Pool {
asio::io_service &io_service_;
};
-}
+} // namespace portal_details
using PendingInterestHashTable =
std::unordered_map<uint32_t, PendingInterest::Ptr>;
@@ -266,6 +267,7 @@ class Portal {
typename ForwarderInt::ConnectorType>,
ForwarderInt>::value,
"ForwarderInt must inherit from ForwarderInterface!");
+
public:
class ConsumerCallback {
public:
@@ -290,7 +292,7 @@ class Portal {
std::bind(&Portal::setLocalRoutes, this), io_service_,
app_name_),
forwarder_interface_(connector_),
- packet_pool_(io_service) { }
+ packet_pool_(io_service) {}
void setConsumerCallback(ConsumerCallback *consumer_callback) {
consumer_callback_ = consumer_callback;
@@ -310,7 +312,7 @@ class Portal {
forwarder_interface_.connect(is_consumer);
}
- ~Portal() { stopEventsLoop(true); }
+ ~Portal() { killConnection(); }
TRANSPORT_ALWAYS_INLINE bool interestIsPending(const Name &name) {
auto it =
@@ -338,11 +340,9 @@ class Portal {
std::move(on_content_object_callback));
pending_interest->setOnTimeoutCallback(
std::move(on_interest_timeout_callback));
- pending_interest->startCountdown(
- portal_details::makeCustomAllocatorHandler(
- async_callback_memory_,
- std::bind(&Portal<ForwarderInt>::timerHandler, this,
- std::placeholders::_1, hash)));
+ pending_interest->startCountdown(portal_details::makeCustomAllocatorHandler(
+ async_callback_memory_, std::bind(&Portal<ForwarderInt>::timerHandler,
+ this, std::placeholders::_1, hash)));
pending_interest_hash_table_.emplace(
std::make_pair(hash, std::move(pending_interest)));
}
@@ -398,15 +398,13 @@ class Portal {
forwarder_interface_.send(content_object);
}
- TRANSPORT_ALWAYS_INLINE void stopEventsLoop(bool kill_connection = false) {
- if (kill_connection) {
- forwarder_interface_.closeConnection();
+ TRANSPORT_ALWAYS_INLINE void stopEventsLoop() {
+ if (!io_service_.stopped()) {
+ io_service_.dispatch([this]() {
+ clear();
+ io_service_.stop();
+ });
}
-
- io_service_.post([this]() {
- clear();
- io_service_.stop();
- });
}
TRANSPORT_ALWAYS_INLINE void killConnection() { connector_.close(); }
@@ -489,12 +487,10 @@ class Portal {
if (interest_ptr->getOnDataCallback() != UNSET_CALLBACK) {
interest_ptr->on_content_object_callback_(
- std::move(interest_ptr->getInterest()),
- std::move(content_object));
+ 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));
+ std::move(interest_ptr->getInterest()), std::move(content_object));
}
} else {
TRANSPORT_LOGW("No pending interests for current content (%s)",
diff --git a/libtransport/src/hicn/transport/core/vpp_binary_api.c b/libtransport/src/hicn/transport/core/vpp_binary_api.c
index 09ffb2ec6..d54ef257e 100644
--- a/libtransport/src/hicn/transport/core/vpp_binary_api.c
+++ b/libtransport/src/hicn/transport/core/vpp_binary_api.c
@@ -173,7 +173,7 @@ void vpp_binary_api_send_receive_ping(vpp_binary_api_t *api) {
CONTEXT_SAVE(context_store, api, mp_ping);
- TRANSPORT_LOGI("Sending ping id %u", mp_ping->_vl_msg_id);
+ TRANSPORT_LOGD("Sending ping id %u", mp_ping->_vl_msg_id);
vpp_binary_api_send_request_wait_reply(api, mp_ping);
}
@@ -202,7 +202,7 @@ int vpp_binary_api_set_int_state(vpp_binary_api_t *api, uint32_t sw_index,
CONTEXT_SAVE(context_store, api, mp);
- TRANSPORT_LOGI("Sending set int flags id %u", mp->_vl_msg_id);
+ TRANSPORT_LOGD("Sending set int flags id %u", mp->_vl_msg_id);
return vpp_binary_api_send_request_wait_reply(api, mp);
}
@@ -211,7 +211,7 @@ void vpp_binary_api_send_request(vpp_binary_api_t *api, void *request) {
vl_generic_request_t *req = NULL;
req = (vl_generic_request_t *)request;
- TRANSPORT_LOGI("Sending a request to VPP (id=%d).\n", ntohs(req->_vl_msg_id));
+ TRANSPORT_LOGD("Sending a request to VPP (id=%d).\n", ntohs(req->_vl_msg_id));
S(api, req);
}
diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
index 0d622f9a3..303b753be 100644
--- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
+++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
@@ -86,12 +86,10 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() {
void VPPForwarderInterface::consumerConnection() {
hicn_consumer_input_params input = {0};
- hicn_consumer_output_params output;
+ hicn_consumer_output_params output = {0};
ip_address_t ip4_address;
ip_address_t ip6_address;
- std::memset(&output, 0, sizeof(hicn_consumer_output_params));
-
output.src4 = &ip4_address;
output.src6 = &ip6_address;
@@ -120,7 +118,7 @@ void VPPForwarderInterface::producerConnection() {
void VPPForwarderInterface::connect(bool is_consumer) {
std::lock_guard<std::mutex> connection_lock(global_lock_);
- srand(time(NULL));
+ srand(time(nullptr));
int secret = rand() % (1 << 10);
std::stringstream app_name;
app_name << "Libtransport_" << secret;
@@ -209,18 +207,17 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
void VPPForwarderInterface::closeConnection() {
if (VPPForwarderInterface::api_) {
+ connector_.close();
+
if (sw_if_index_ != uint32_t(~0)) {
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_);
}
}
vpp_binary_api_destroy(VPPForwarderInterface::api_);
- connector_.close();
-
VPPForwarderInterface::api_ = nullptr;
}
}