aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/io_modules
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/io_modules')
-rw-r--r--libtransport/src/io_modules/CMakeLists.txt7
-rw-r--r--libtransport/src/io_modules/forwarder/CMakeLists.txt5
-rw-r--r--libtransport/src/io_modules/forwarder/forwarder.cc31
-rw-r--r--libtransport/src/io_modules/forwarder/forwarder_module.cc6
-rw-r--r--libtransport/src/io_modules/forwarder/global_id_counter.h23
-rw-r--r--libtransport/src/io_modules/forwarder/udp_tunnel.cc50
-rw-r--r--libtransport/src/io_modules/forwarder/udp_tunnel.h3
-rw-r--r--libtransport/src/io_modules/forwarder/udp_tunnel_listener.cc16
-rw-r--r--libtransport/src/io_modules/forwarder/udp_tunnel_listener.h3
-rw-r--r--libtransport/src/io_modules/loopback/CMakeLists.txt6
-rw-r--r--libtransport/src/io_modules/loopback/local_face.cc7
-rw-r--r--libtransport/src/io_modules/loopback/local_face.h3
-rw-r--r--libtransport/src/io_modules/loopback/loopback_module.cc6
-rw-r--r--libtransport/src/io_modules/memif/CMakeLists.txt4
-rw-r--r--libtransport/src/io_modules/memif/hicn_vapi.c1
-rw-r--r--libtransport/src/io_modules/memif/memif_connector.cc35
-rw-r--r--libtransport/src/io_modules/memif/memif_connector.h4
-rw-r--r--libtransport/src/io_modules/memif/vpp_forwarder_module.cc15
-rw-r--r--libtransport/src/io_modules/raw_socket/raw_socket_connector.cc5
-rw-r--r--libtransport/src/io_modules/raw_socket/raw_socket_connector.h3
-rw-r--r--libtransport/src/io_modules/udp/CMakeLists.txt28
-rw-r--r--libtransport/src/io_modules/udp/udp_socket_connector.cc10
-rw-r--r--libtransport/src/io_modules/udp/udp_socket_connector.h3
23 files changed, 112 insertions, 162 deletions
diff --git a/libtransport/src/io_modules/CMakeLists.txt b/libtransport/src/io_modules/CMakeLists.txt
index cf466721f..29aec236a 100644
--- a/libtransport/src/io_modules/CMakeLists.txt
+++ b/libtransport/src/io_modules/CMakeLists.txt
@@ -11,10 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
-
-if (${CMAKE_SYSTEM_NAME} MATCHES "^(iOS|Android|Windows)$")
-
+if (${CMAKE_SYSTEM_NAME} MATCHES Android)
list(APPEND SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/udp/hicn_forwarder_module.cc
${CMAKE_CURRENT_SOURCE_DIR}/udp/udp_socket_connector.cc
@@ -27,7 +24,7 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "^(iOS|Android|Windows)$")
set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
-else ()
+else()
add_subdirectory(udp)
add_subdirectory(loopback)
add_subdirectory(forwarder)
diff --git a/libtransport/src/io_modules/forwarder/CMakeLists.txt b/libtransport/src/io_modules/forwarder/CMakeLists.txt
index 92662bc4c..a1d0c5db5 100644
--- a/libtransport/src/io_modules/forwarder/CMakeLists.txt
+++ b/libtransport/src/io_modules/forwarder/CMakeLists.txt
@@ -11,9 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
-
-
list(APPEND MODULE_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/connector.h
${CMAKE_CURRENT_SOURCE_DIR}/endpoint.h
@@ -37,7 +34,7 @@ build_module(forwarder_module
SHARED
SOURCES ${MODULE_SOURCE_FILES}
DEPENDS ${DEPENDENCIES}
- COMPONENT lib${LIBTRANSPORT}
+ COMPONENT ${LIBTRANSPORT_COMPONENT}-io-modules
INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS} ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS}
DEFINITIONS ${COMPILER_DEFINITIONS}
COMPILE_OPTIONS ${COMPILE_FLAGS}
diff --git a/libtransport/src/io_modules/forwarder/forwarder.cc b/libtransport/src/io_modules/forwarder/forwarder.cc
index 7e89e2f9f..0546cb8b3 100644
--- a/libtransport/src/io_modules/forwarder/forwarder.cc
+++ b/libtransport/src/io_modules/forwarder/forwarder.cc
@@ -15,6 +15,7 @@
#include <core/global_configuration.h>
#include <core/local_connector.h>
+#include <glog/logging.h>
#include <io_modules/forwarder/forwarder.h>
#include <io_modules/forwarder/global_id_counter.h>
#include <io_modules/forwarder/udp_tunnel.h>
@@ -127,7 +128,7 @@ void Forwarder::onPacketFromListener(Connector *connector,
std::bind(&Forwarder::onPacketReceived, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
- TRANSPORT_LOGD("Packet received from listener.");
+ DLOG_IF(INFO, VLOG_IS_ON(3)) << "Packet received from listener.";
{
utils::SpinLock::Acquire locked(connector_lock_);
@@ -157,10 +158,8 @@ void Forwarder::onPacketReceived(Connector *connector,
if ((is_producer && is_interest) || (!is_producer && !is_interest)) {
c.second->send(*packet);
} else {
- TRANSPORT_LOGD(
- "Error sending packet to local connector. is_interest = %d - "
- "is_producer = %d",
- (int)is_interest, (int)is_producer);
+ LOG(ERROR) << "Error sending packet to local connector. is_interest = "
+ << is_interest << " - is_producer = " << is_producer;
}
}
@@ -178,9 +177,9 @@ void Forwarder::send(Packet &packet) {
auto remote_endpoint =
remote_connectors_.begin()->second->getRemoteEndpoint();
- TRANSPORT_LOGD("Sending packet to: %s:%u",
- remote_endpoint.getAddress().to_string().c_str(),
- remote_endpoint.getPort());
+ DLOG_IF(INFO, VLOG_IS_ON(3))
+ << "Sending packet to: " << remote_endpoint.getAddress() << ":"
+ << remote_endpoint.getPort();
remote_connectors_.begin()->second->send(packet);
}
@@ -199,7 +198,7 @@ void Forwarder::parseForwarderConfiguration(
// Get number of threads
int n_threads = 1;
forwarder_config.lookupValue("n_threads", n_threads);
- TRANSPORT_LOGD("Forwarder threads from config file: %u", n_threads);
+ VLOG(1) << "Forwarder threads from config file: " << n_threads;
config_.setThreadNumber(n_threads);
}
@@ -219,8 +218,8 @@ void Forwarder::parseForwarderConfiguration(
listener.lookupValue("local_port", port);
list.port = (uint16_t)(port);
- TRANSPORT_LOGD("Adding listener %s, (%s:%u)", list.name.c_str(),
- list.address.c_str(), list.port);
+ VLOG(1) << "Adding listener " << list.name << ", ( " << list.address
+ << ":" << list.port << ")";
config_.addListener(std::move(list));
}
}
@@ -262,9 +261,9 @@ void Forwarder::parseForwarderConfiguration(
conn.remote_port = (uint16_t)(port);
- TRANSPORT_LOGD("Adding connector %s, (%s:%u %s:%u)", conn.name.c_str(),
- conn.local_address.c_str(), conn.local_port,
- conn.remote_address.c_str(), conn.remote_port);
+ VLOG(1) << "Adding connector " << conn.name << ", (" << conn.local_address
+ << ":" << conn.local_port << " " << conn.remote_address << ":"
+ << conn.remote_port << ")";
config_.addConnector(std::move(conn));
}
}
@@ -285,8 +284,8 @@ void Forwarder::parseForwarderConfiguration(
route.lookupValue("connector", r.connector);
r.weight = (uint16_t)(weight);
- TRANSPORT_LOGD("Adding route %s %s (%s %u)", r.name.c_str(),
- r.prefix.c_str(), r.connector.c_str(), r.weight);
+ VLOG(1) << "Adding route " << r.name << " " << r.prefix << " ("
+ << r.connector << " " << r.weight << ")";
config_.addRoute(std::move(r));
}
}
diff --git a/libtransport/src/io_modules/forwarder/forwarder_module.cc b/libtransport/src/io_modules/forwarder/forwarder_module.cc
index 356b42d3b..4f95b9ca0 100644
--- a/libtransport/src/io_modules/forwarder/forwarder_module.cc
+++ b/libtransport/src/io_modules/forwarder/forwarder_module.cc
@@ -13,8 +13,8 @@
* limitations under the License.
*/
+#include <glog/logging.h>
#include <hicn/transport/errors/not_implemented_exception.h>
-#include <hicn/transport/utils/log.h>
#include <io_modules/forwarder/forwarder_module.h>
namespace transport {
@@ -36,8 +36,8 @@ bool ForwarderModule::isConnected() { return true; }
void ForwarderModule::send(Packet &packet) {
IoModule::send(packet);
forwarder_.send(packet);
- // TRANSPORT_LOGD("ForwarderModule: sending from %u to %d", local_id_,
- // 1 - local_id_);
+ DLOG_IF(INFO, VLOG_IS_ON(3))
+ << "Sending from " << connector_id_ << " to " << 1 - connector_id_;
// local_faces_.at(1 - local_id_).onPacket(packet);
}
diff --git a/libtransport/src/io_modules/forwarder/global_id_counter.h b/libtransport/src/io_modules/forwarder/global_id_counter.h
index fe8d76730..0a67b76d5 100644
--- a/libtransport/src/io_modules/forwarder/global_id_counter.h
+++ b/libtransport/src/io_modules/forwarder/global_id_counter.h
@@ -15,6 +15,8 @@
#pragma once
+#include <hicn/transport/utils/singleton.h>
+
#include <atomic>
#include <mutex>
@@ -23,32 +25,15 @@ namespace transport {
namespace core {
template <typename T = uint64_t>
-class GlobalCounter {
+class GlobalCounter : public utils::Singleton<GlobalCounter<T>> {
public:
- static GlobalCounter& getInstance() {
- std::lock_guard<std::mutex> lock(global_mutex_);
-
- if (!instance_) {
- instance_.reset(new GlobalCounter());
- }
-
- return *instance_;
- }
-
+ friend class utils::Singleton<GlobalCounter>;
T getNext() { return counter_++; }
private:
GlobalCounter() : counter_(0) {}
- static std::unique_ptr<GlobalCounter<T>> instance_;
- static std::mutex global_mutex_;
std::atomic<T> counter_;
};
-template <typename T>
-std::unique_ptr<GlobalCounter<T>> GlobalCounter<T>::instance_ = nullptr;
-
-template <typename T>
-std::mutex GlobalCounter<T>::global_mutex_;
-
} // namespace core
} // namespace transport \ No newline at end of file
diff --git a/libtransport/src/io_modules/forwarder/udp_tunnel.cc b/libtransport/src/io_modules/forwarder/udp_tunnel.cc
index dc725fc4e..bf6a69b92 100644
--- a/libtransport/src/io_modules/forwarder/udp_tunnel.cc
+++ b/libtransport/src/io_modules/forwarder/udp_tunnel.cc
@@ -2,6 +2,7 @@
* Copyright (c) 2017-2019 Cisco and/or its affiliates.
*/
+#include <glog/logging.h>
#include <hicn/transport/utils/branch_prediction.h>
#include <io_modules/forwarder/errors.h>
#include <io_modules/forwarder/udp_tunnel.h>
@@ -62,7 +63,7 @@ void UdpTunnelConnector::send(Packet &packet) {
void UdpTunnelConnector::send(const uint8_t *packet, std::size_t len) {}
void UdpTunnelConnector::close() {
- TRANSPORT_LOGD("UDPTunnelConnector::close");
+ DLOG_IF(INFO, VLOG_IS_ON(2)) << "UDPTunnelConnector::close";
state_ = State::CLOSED;
bool is_socket_owned = socket_.use_count() == 1;
if (is_socket_owned) {
@@ -150,8 +151,8 @@ void UdpTunnelConnector::writeHandler(std::error_code ec) {
output_buffer_.pop_front();
}
} else if (retval != EWOULDBLOCK && retval != EAGAIN) {
- TRANSPORT_LOGE("Error sending messages! %s %d\n", strerror(errno),
- retval);
+ LOG(ERROR) << "Error sending messages! " << strerror(errno)
+ << " << retval";
return;
}
}
@@ -164,9 +165,8 @@ void UdpTunnelConnector::writeHandler(std::error_code ec) {
}
void UdpTunnelConnector::readHandler(std::error_code ec) {
- TRANSPORT_LOGD("UdpTunnelConnector receive packet");
+ DLOG_IF(INFO, VLOG_IS_ON(3)) << "UdpTunnelConnector receive packet";
- // TRANSPORT_LOGD("UdpTunnelConnector received packet length=%lu", length);
if (TRANSPORT_EXPECT_TRUE(!ec)) {
if (TRANSPORT_EXPECT_TRUE(state_ == State::CONNECTED)) {
if (current_position_ == 0) {
@@ -182,8 +182,8 @@ void UdpTunnelConnector::readHandler(std::error_code ec) {
int res = recvmmsg(socket_->native_handle(), rx_msgs_ + current_position_,
max_burst - current_position_, MSG_DONTWAIT, nullptr);
if (res < 0) {
- TRANSPORT_LOGE("Error receiving messages! %s %d\n", strerror(errno),
- res);
+ LOG(ERROR) << "Error receiving messages! " << strerror(errno) << " "
+ << res;
return;
}
@@ -200,19 +200,20 @@ void UdpTunnelConnector::readHandler(std::error_code ec) {
doRecvPacket();
} else {
- TRANSPORT_LOGE(
- "Error in UDP: Receiving packets from a not connected socket.");
+ LOG(ERROR)
+ << "Error in UDP: Receiving packets from a not connected socket.";
}
} else if (ec.value() == static_cast<int>(std::errc::operation_canceled)) {
- TRANSPORT_LOGE("The connection has been closed by the application.");
+ LOG(ERROR) << "The connection has been closed by the application.";
return;
} else {
if (TRANSPORT_EXPECT_TRUE(state_ == State::CONNECTED)) {
// receive_callback_(this, *read_msg_, ec);
- TRANSPORT_LOGE("Error in UDP connector: %d %s", ec.value(),
- ec.message().c_str());
+ LOG(ERROR) << "Error in UDP connector: " << ec.value() << " "
+ << ec.message();
} else {
- TRANSPORT_LOGE("Error while not connector");
+ LOG(ERROR) << "Error in connector while not connected. " << ec.value()
+ << " " << ec.message();
}
}
}
@@ -226,16 +227,17 @@ void UdpTunnelConnector::doRecvPacket() {
#else
socket_->async_wait(asio::ip::tcp::socket::wait_read,
#endif
- std::bind(&UdpTunnelConnector::readHandler, this,
- std::placeholders::_1));
+ std::bind(&UdpTunnelConnector::readHandler, this,
+ std::placeholders::_1));
}
#else
- TRANSPORT_LOGD("UdpTunnelConnector receive packet");
+ DLOG_IF(INFO, VLOG_IS_ON(3)) << "UdpTunnelConnector receive packet";
read_msg_ = getRawBuffer();
socket_->async_receive_from(
asio::buffer(read_msg_.first, read_msg_.second), remote_endpoint_recv_,
[this](std::error_code ec, std::size_t length) {
- TRANSPORT_LOGD("UdpTunnelConnector received packet length=%lu", length);
+ DLOG_IF(INFO, VLOG_IS_ON(3))
+ << "UdpTunnelConnector received packet length=" << length;
if (TRANSPORT_EXPECT_TRUE(!ec)) {
if (TRANSPORT_EXPECT_TRUE(state_ == State::CONNECTED)) {
auto packet = getPacketFromBuffer(read_msg_.first, length);
@@ -244,19 +246,19 @@ void UdpTunnelConnector::doRecvPacket() {
make_error_code(forwarder_error::success));
doRecvPacket();
} else {
- TRANSPORT_LOGE(
- "Error in UDP: Receiving packets from a not connected socket.");
+ LOG(ERROR) << "Error in UDP: Receiving packets from a not "
+ "connected socket.";
}
} else if (ec.value() ==
static_cast<int>(std::errc::operation_canceled)) {
- TRANSPORT_LOGE("The connection has been closed by the application.");
+ LOG(ERROR) << "The connection has been closed by the application.";
return;
} else {
if (TRANSPORT_EXPECT_TRUE(state_ == State::CONNECTED)) {
- TRANSPORT_LOGE("Error in UDP connector: %d %s", ec.value(),
- ec.message().c_str());
+ LOG(ERROR) << "Error in UDP connector: " << ec.value()
+ << ec.message();
} else {
- TRANSPORT_LOGE("Error while not connector");
+ LOG(ERROR) << "Error while not connected";
}
}
});
@@ -276,7 +278,7 @@ void UdpTunnelConnector::doConnect() {
doSendPacket();
}
} else {
- TRANSPORT_LOGE("[Hproxy] - UDP Connection failed!!!");
+ LOG(ERROR) << "UDP Connection failed!!!";
timer_.expires_from_now(std::chrono::milliseconds(500));
timer_.async_wait(std::bind(&UdpTunnelConnector::doConnect, this));
}
diff --git a/libtransport/src/io_modules/forwarder/udp_tunnel.h b/libtransport/src/io_modules/forwarder/udp_tunnel.h
index df472af91..4f044f93f 100644
--- a/libtransport/src/io_modules/forwarder/udp_tunnel.h
+++ b/libtransport/src/io_modules/forwarder/udp_tunnel.h
@@ -4,12 +4,11 @@
#pragma once
+#include <hicn/transport/core/asio_wrapper.h>
#include <hicn/transport/core/connector.h>
#include <hicn/transport/portability/platform.h>
#include <io_modules/forwarder/errors.h>
-#include <asio.hpp>
-#include <asio/steady_timer.hpp>
#include <iostream>
#include <memory>
diff --git a/libtransport/src/io_modules/forwarder/udp_tunnel_listener.cc b/libtransport/src/io_modules/forwarder/udp_tunnel_listener.cc
index 12246c3cf..d047cc568 100644
--- a/libtransport/src/io_modules/forwarder/udp_tunnel_listener.cc
+++ b/libtransport/src/io_modules/forwarder/udp_tunnel_listener.cc
@@ -2,8 +2,8 @@
* Copyright (c) 2017-2019 Cisco and/or its affiliates.
*/
+#include <glog/logging.h>
#include <hicn/transport/utils/hash.h>
-#include <hicn/transport/utils/log.h>
#include <io_modules/forwarder/udp_tunnel.h>
#include <io_modules/forwarder/udp_tunnel_listener.h>
@@ -36,9 +36,8 @@ void UdpTunnelListener::close() {
#ifdef LINUX
void UdpTunnelListener::readHandler(std::error_code ec) {
- TRANSPORT_LOGD("UdpTunnelConnector receive packet");
+ DLOG_IF(INFO, VLOG_IS_ON(3)) << "UdpTunnelConnector receive packet";
- // TRANSPORT_LOGD("UdpTunnelConnector received packet length=%lu", length);
if (TRANSPORT_EXPECT_TRUE(!ec)) {
if (current_position_ == 0) {
for (int i = 0; i < Connector::max_burst; i++) {
@@ -56,7 +55,8 @@ void UdpTunnelListener::readHandler(std::error_code ec) {
Connector::max_burst - current_position_, MSG_DONTWAIT,
nullptr);
if (res < 0) {
- TRANSPORT_LOGE("Error in recvmmsg.");
+ LOG(ERROR) << "Error in recvmmsg.";
+ return;
}
for (int i = 0; i < res; i++) {
@@ -119,10 +119,10 @@ void UdpTunnelListener::readHandler(std::error_code ec) {
doRecvPacket();
} else if (ec.value() == static_cast<int>(std::errc::operation_canceled)) {
- TRANSPORT_LOGE("The connection has been closed by the application.");
+ LOG(ERROR) << "The connection has been closed by the application.";
return;
} else {
- TRANSPORT_LOGE("%d %s", ec.value(), ec.message().c_str());
+ LOG(ERROR) << ec.value() << " " << ec.message();
}
}
#endif
@@ -165,10 +165,10 @@ void UdpTunnelListener::doRecvPacket() {
doRecvPacket();
} else if (ec.value() ==
static_cast<int>(std::errc::operation_canceled)) {
- TRANSPORT_LOGE("The connection has been closed by the application.");
+ LOG(ERROR) << "The connection has been closed by the application.";
return;
} else {
- TRANSPORT_LOGE("%d %s", ec.value(), ec.message().c_str());
+ LOG(ERROR) << ec.value() << " " << ec.message();
}
});
#endif
diff --git a/libtransport/src/io_modules/forwarder/udp_tunnel_listener.h b/libtransport/src/io_modules/forwarder/udp_tunnel_listener.h
index 0ee40a400..5d197dcb0 100644
--- a/libtransport/src/io_modules/forwarder/udp_tunnel_listener.h
+++ b/libtransport/src/io_modules/forwarder/udp_tunnel_listener.h
@@ -4,11 +4,10 @@
#pragma once
+#include <hicn/transport/core/asio_wrapper.h>
#include <hicn/transport/core/connector.h>
#include <hicn/transport/portability/platform.h>
-#include <asio.hpp>
-#include <asio/steady_timer.hpp>
#include <unordered_map>
namespace std {
diff --git a/libtransport/src/io_modules/loopback/CMakeLists.txt b/libtransport/src/io_modules/loopback/CMakeLists.txt
index ac6dc8068..b5ae0b7f7 100644
--- a/libtransport/src/io_modules/loopback/CMakeLists.txt
+++ b/libtransport/src/io_modules/loopback/CMakeLists.txt
@@ -11,9 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
-
-
list(APPEND MODULE_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/loopback_module.h
)
@@ -26,9 +23,8 @@ build_module(loopback_module
SHARED
SOURCES ${MODULE_SOURCE_FILES}
DEPENDS ${DEPENDENCIES}
- COMPONENT lib${LIBTRANSPORT}
+ COMPONENT ${LIBTRANSPORT_COMPONENT}
INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS} ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS}
- # LIBRARY_ROOT_DIR "vpp_plugins"
DEFINITIONS ${COMPILER_DEFINITIONS}
COMPILE_OPTIONS ${COMPILE_FLAGS}
)
diff --git a/libtransport/src/io_modules/loopback/local_face.cc b/libtransport/src/io_modules/loopback/local_face.cc
index a59dab235..b73444330 100644
--- a/libtransport/src/io_modules/loopback/local_face.cc
+++ b/libtransport/src/io_modules/loopback/local_face.cc
@@ -13,13 +13,12 @@
* limitations under the License.
*/
+#include <glog/logging.h>
+#include <hicn/transport/core/asio_wrapper.h>
#include <hicn/transport/core/content_object.h>
#include <hicn/transport/core/interest.h>
-#include <hicn/transport/utils/log.h>
#include <io_modules/loopback/local_face.h>
-#include <asio/io_service.hpp>
-
namespace transport {
namespace core {
@@ -56,7 +55,7 @@ Face &Face::operator=(Face &&other) {
}
void Face::onPacket(const Packet &packet) {
- TRANSPORT_LOGD("Sending content to local socket.");
+ DLOG_IF(INFO, VLOG_IS_ON(3)) << "Sending content to local socket.";
if (Packet::isInterest(packet.data())) {
rescheduleOnIoService<Interest>(packet);
diff --git a/libtransport/src/io_modules/loopback/local_face.h b/libtransport/src/io_modules/loopback/local_face.h
index 1cbcc2c72..1f4101447 100644
--- a/libtransport/src/io_modules/loopback/local_face.h
+++ b/libtransport/src/io_modules/loopback/local_face.h
@@ -15,12 +15,11 @@
#pragma once
+#include <hicn/transport/core/asio_wrapper.h>
#include <hicn/transport/core/connector.h>
#include <hicn/transport/core/global_object_pool.h>
#include <hicn/transport/utils/move_wrapper.h>
-#include <asio/io_service.hpp>
-
namespace transport {
namespace core {
diff --git a/libtransport/src/io_modules/loopback/loopback_module.cc b/libtransport/src/io_modules/loopback/loopback_module.cc
index 0bdbf8c8e..f7dd5e7b0 100644
--- a/libtransport/src/io_modules/loopback/loopback_module.cc
+++ b/libtransport/src/io_modules/loopback/loopback_module.cc
@@ -13,8 +13,8 @@
* limitations under the License.
*/
+#include <glog/logging.h>
#include <hicn/transport/errors/not_implemented_exception.h>
-#include <hicn/transport/utils/log.h>
#include <io_modules/loopback/loopback_module.h>
namespace transport {
@@ -35,8 +35,8 @@ bool LoopbackModule::isConnected() { return true; }
void LoopbackModule::send(Packet &packet) {
IoModule::send(packet);
- TRANSPORT_LOGD("LoopbackModule: sending from %u to %d", local_id_,
- 1 - local_id_);
+ DLOG_IF(INFO, VLOG_IS_ON(3)) << "LoopbackModule: sending from " << local_id_
+ << " to " << 1 - local_id_;
local_faces_.at(1 - local_id_)->send(packet);
}
diff --git a/libtransport/src/io_modules/memif/CMakeLists.txt b/libtransport/src/io_modules/memif/CMakeLists.txt
index c8a930e7b..fc1c1f135 100644
--- a/libtransport/src/io_modules/memif/CMakeLists.txt
+++ b/libtransport/src/io_modules/memif/CMakeLists.txt
@@ -11,8 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
-
find_package(Vpp REQUIRED)
find_package(Libmemif REQUIRED)
@@ -43,7 +41,7 @@ build_module(memif_module
SHARED
SOURCES ${MODULE_SOURCE_FILES}
DEPENDS ${DEPENDENCIES}
- COMPONENT lib${LIBTRANSPORT}
+ COMPONENT ${LIBTRANSPORT_COMPONENT}-io-modules
LINK_LIBRARIES ${LIBMEMIF_LIBRARIES} ${SAFE_VAPI_LIBRARIES}
INCLUDE_DIRS
${LIBTRANSPORT_INCLUDE_DIRS}
diff --git a/libtransport/src/io_modules/memif/hicn_vapi.c b/libtransport/src/io_modules/memif/hicn_vapi.c
index b83a36b47..6d78026ab 100644
--- a/libtransport/src/io_modules/memif/hicn_vapi.c
+++ b/libtransport/src/io_modules/memif/hicn_vapi.c
@@ -14,7 +14,6 @@
*/
#include <hicn/transport/config.h>
-#include <hicn/transport/utils/log.h>
#include <io_modules/memif/hicn_vapi.h>
#define HICN_VPP_PLUGIN
diff --git a/libtransport/src/io_modules/memif/memif_connector.cc b/libtransport/src/io_modules/memif/memif_connector.cc
index 4a688d68f..68ad52b63 100644
--- a/libtransport/src/io_modules/memif/memif_connector.cc
+++ b/libtransport/src/io_modules/memif/memif_connector.cc
@@ -13,6 +13,7 @@
* limitations under the License.
*/
+#include <glog/logging.h>
#include <hicn/transport/errors/not_implemented_exception.h>
#include <io_modules/memif/memif_connector.h>
#include <sys/epoll.h>
@@ -66,6 +67,7 @@ MemifConnector::MemifConnector(PacketReceivedCallback &&receive_callback,
disconnect_timer_(
std::make_unique<utils::FdDeadlineTimer>(event_reactor_)),
io_service_(io_service),
+ work_(asio::make_work_guard(io_service_)),
memif_connection_(std::make_unique<memif_connection_t>()),
tx_buf_counter_(0),
is_reconnection_(false),
@@ -83,7 +85,7 @@ void MemifConnector::init() {
nullptr, nullptr, nullptr);
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_init: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_init: " << memif_strerror(err);
}
}
@@ -95,8 +97,6 @@ void MemifConnector::connect(uint32_t memif_id, long memif_mode) {
createMemif(memif_id, memif_mode, nullptr);
- work_ = std::make_unique<asio::io_service::work>(io_service_);
-
while (state_ != State::CONNECTED) {
MemifConnector::main_event_reactor_.runOneEvent();
}
@@ -107,7 +107,7 @@ void MemifConnector::connect(uint32_t memif_id, long memif_mode) {
int fd = -1;
err = memif_get_queue_efd(memif_connection_->conn, 0, &fd);
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_get_queue_efd: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_get_queue_efd: " << memif_strerror(err);
return;
}
@@ -198,11 +198,11 @@ int MemifConnector::deleteMemif() {
err = memif_delete(&c->conn);
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_delete: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_delete: " << memif_strerror(err);
}
if (TRANSPORT_EXPECT_FALSE(c->conn != nullptr)) {
- TRANSPORT_LOGE("memif delete fail");
+ LOG(ERROR) << "memif delete fail";
}
return 0;
@@ -248,8 +248,8 @@ int MemifConnector::controlFdUpdate(int fd, uint8_t events, void *private_ctx) {
memif_err = memif_control_fd_handler(evt.data.fd, event);
if (TRANSPORT_EXPECT_FALSE(memif_err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_control_fd_handler: %s",
- memif_strerror(memif_err));
+ LOG(ERROR) << "memif_control_fd_handler: "
+ << memif_strerror(memif_err);
}
return 0;
@@ -265,7 +265,7 @@ int MemifConnector::bufferAlloc(long n, uint16_t qid) {
err = memif_buffer_alloc(c->conn, qid, c->tx_bufs, n, &r, 2000);
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_buffer_alloc: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_buffer_alloc: " << memif_strerror(err);
return -1;
}
@@ -282,13 +282,13 @@ int MemifConnector::txBurst(uint16_t qid) {
err = memif_tx_burst(c->conn, qid, c->tx_bufs, c->tx_buf_num, &r);
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_tx_burst: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_tx_burst: " << memif_strerror(err);
}
// err = memif_refill_queue(c->conn, qid, r, 0);
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_tx_burst: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_tx_burst: " << memif_strerror(err);
c->tx_buf_num -= r;
return -1;
}
@@ -350,14 +350,14 @@ int MemifConnector::onInterrupt(memif_conn_handle_t conn, void *private_ctx,
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS &&
err != MEMIF_ERR_NOBUF)) {
- TRANSPORT_LOGE("memif_rx_burst: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_rx_burst: " << memif_strerror(err);
goto error;
}
c->rx_buf_num += rx;
if (TRANSPORT_EXPECT_FALSE(connector->io_service_.stopped())) {
- TRANSPORT_LOGE("socket stopped: ignoring %u packets", rx);
+ LOG(ERROR) << "socket stopped: ignoring " << rx << " packets";
goto error;
}
@@ -369,7 +369,7 @@ int MemifConnector::onInterrupt(memif_conn_handle_t conn, void *private_ctx,
auto packet = connector->getPacketFromBuffer(buffer.first, packet_length);
if (!connector->input_buffer_.push(std::move(packet))) {
- TRANSPORT_LOGE("Error pushing packet. Ring buffer full.");
+ LOG(ERROR) << "Error pushing packet. Ring buffer full.";
// TODO Here we should consider the possibility to signal the congestion
// to the application, that would react properly (e.g. slow down
@@ -383,7 +383,7 @@ int MemifConnector::onInterrupt(memif_conn_handle_t conn, void *private_ctx,
err = memif_refill_queue(conn, qid, rx, 0);
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_buffer_free: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_buffer_free: " << memif_strerror(err);
}
c->rx_buf_num -= rx;
@@ -400,7 +400,7 @@ error:
err = memif_refill_queue(c->conn, qid, rx, 0);
if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) {
- TRANSPORT_LOGE("memif_buffer_free: %s", memif_strerror(err));
+ LOG(ERROR) << "memif_buffer_free: " << memif_strerror(err);
}
c->rx_buf_num -= rx;
@@ -413,7 +413,6 @@ void MemifConnector::close() {
disconnect_timer_->asyncWait([this](const std::error_code &ec) {
deleteMemif();
event_reactor_.stop();
- work_.reset();
});
if (memif_worker_ && memif_worker_->joinable()) {
@@ -452,7 +451,7 @@ int MemifConnector::doSend() {
n = bufferAlloc(max, memif_connection_->tx_qid);
if (TRANSPORT_EXPECT_FALSE(n < 0)) {
- TRANSPORT_LOGE("Error allocating buffers.");
+ LOG(ERROR) << "Error allocating buffers.";
return -1;
}
diff --git a/libtransport/src/io_modules/memif/memif_connector.h b/libtransport/src/io_modules/memif/memif_connector.h
index bed3516dc..0a189f893 100644
--- a/libtransport/src/io_modules/memif/memif_connector.h
+++ b/libtransport/src/io_modules/memif/memif_connector.h
@@ -20,10 +20,10 @@
#include <hicn/transport/portability/portability.h>
#include <hicn/transport/utils/ring_buffer.h>
//#include <hicn/transport/core/hicn_vapi.h>
+#include <hicn/transport/core/asio_wrapper.h>
#include <utils/epoll_event_reactor.h>
#include <utils/fd_deadline_timer.h>
-#include <asio.hpp>
#include <deque>
#include <mutex>
#include <thread>
@@ -108,7 +108,7 @@ class MemifConnector : public Connector {
std::unique_ptr<utils::FdDeadlineTimer> send_timer_;
std::unique_ptr<utils::FdDeadlineTimer> disconnect_timer_;
asio::io_service &io_service_;
- std::unique_ptr<asio::io_service::work> work_;
+ asio::executor_work_guard<asio::io_context::executor_type> work_;
std::unique_ptr<memif_connection_t> memif_connection_;
uint16_t tx_buf_counter_;
diff --git a/libtransport/src/io_modules/memif/vpp_forwarder_module.cc b/libtransport/src/io_modules/memif/vpp_forwarder_module.cc
index dcbcd7ed0..44c8376df 100644
--- a/libtransport/src/io_modules/memif/vpp_forwarder_module.cc
+++ b/libtransport/src/io_modules/memif/vpp_forwarder_module.cc
@@ -13,6 +13,7 @@
* limitations under the License.
*/
+#include <glog/logging.h>
#include <hicn/transport/config.h>
#include <hicn/transport/errors/not_implemented_exception.h>
#include <io_modules/memif/hicn_vapi.h>
@@ -148,21 +149,19 @@ void VPPForwarderModule::producerConnection() {
void VPPForwarderModule::connect(bool is_consumer) {
int retry = 20;
- TRANSPORT_LOGI("Connecting to VPP through vapi.");
+ LOG(INFO) << "Connecting to VPP through vapi.";
vapi_error_e ret = vapi_connect_safe(&sock_, 0);
while (ret != VAPI_OK && retry > 0) {
- TRANSPORT_LOGE("Error connecting to VPP through vapi. Retrying..");
+ LOG(ERROR) << "Error connecting to VPP through vapi. Retrying..";
--retry;
ret = vapi_connect_safe(&sock_, 0);
}
- if (ret != VAPI_OK) {
- throw std::runtime_error(
- "Impossible to connect to forwarder. Is VPP running?");
- }
+ CHECK_EQ(ret, VAPI_OK)
+ << "Impossible to connect to forwarder. Is VPP running?";
- TRANSPORT_LOGI("Connected to VPP through vapi.");
+ LOG(INFO) << "Connected to VPP through vapi.";
sw_if_index_ = getMemifConfiguration();
@@ -247,7 +246,7 @@ void VPPForwarderModule::closeConnection() {
int ret =
memif_vapi_delete_memif(VPPForwarderModule::sock_, sw_if_index_);
if (ret < 0) {
- TRANSPORT_LOGE("Error deleting memif with sw idx %u.", sw_if_index_);
+ LOG(ERROR) << "Error deleting memif with sw idx " << sw_if_index_;
}
}
diff --git a/libtransport/src/io_modules/raw_socket/raw_socket_connector.cc b/libtransport/src/io_modules/raw_socket/raw_socket_connector.cc
index 0bfcc2a58..62efdc3a5 100644
--- a/libtransport/src/io_modules/raw_socket/raw_socket_connector.cc
+++ b/libtransport/src/io_modules/raw_socket/raw_socket_connector.cc
@@ -15,7 +15,6 @@
#include <core/raw_socket_connector.h>
#include <hicn/transport/utils/conversions.h>
-#include <hicn/transport/utils/log.h>
#include <net/if.h>
#include <netdb.h>
#include <stdio.h>
@@ -165,7 +164,7 @@ void RawSocketConnector::doSendPacket() {
doSendPacket();
}
} else {
- TRANSPORT_LOGE("%d %s", ec.value(), ec.message().c_str());
+ LOG(ERROR) << ec.value() << " " << ec.message();
}
});
}
@@ -185,7 +184,7 @@ void RawSocketConnector::doRecvPacket() {
receive_callback_(std::move(read_msg_));
}
} else {
- TRANSPORT_LOGE("%d %s", ec.value(), ec.message().c_str());
+ LOG(ERROR) << ec.value() << " " << ec.message();
}
doRecvPacket();
});
diff --git a/libtransport/src/io_modules/raw_socket/raw_socket_connector.h b/libtransport/src/io_modules/raw_socket/raw_socket_connector.h
index aba4b1105..06892b3d8 100644
--- a/libtransport/src/io_modules/raw_socket/raw_socket_connector.h
+++ b/libtransport/src/io_modules/raw_socket/raw_socket_connector.h
@@ -17,13 +17,12 @@
#include <core/connector.h>
#include <hicn/transport/config.h>
+#include <hicn/transport/core/asio_wrapper.h>
#include <hicn/transport/core/name.h>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <sys/socket.h>
-#include <asio.hpp>
-#include <asio/steady_timer.hpp>
#include <deque>
namespace transport {
diff --git a/libtransport/src/io_modules/udp/CMakeLists.txt b/libtransport/src/io_modules/udp/CMakeLists.txt
index 93518d0a2..b9c19d063 100644
--- a/libtransport/src/io_modules/udp/CMakeLists.txt
+++ b/libtransport/src/io_modules/udp/CMakeLists.txt
@@ -11,9 +11,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
-
-
list(APPEND MODULE_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/hicn_forwarder_module.h
${CMAKE_CURRENT_SOURCE_DIR}/udp_socket_connector.h
@@ -24,23 +21,12 @@ list(APPEND MODULE_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/udp_socket_connector.cc
)
-# add_executable(hicnlight_module MACOSX_BUNDLE ${MODULE_SOURCE_FILES})
-# target_include_directories(hicnlight_module PRIVATE ${LIBTRANSPORT_INCLUDE_DIRS} ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS})
-# set_target_properties(hicnlight_module PROPERTIES
-# BUNDLE True
-# MACOSX_BUNDLE_GUI_IDENTIFIER my.domain.style.identifier.hicnlight_module
-# MACOSX_BUNDLE_BUNDLE_NAME hicnlight_module
-# MACOSX_BUNDLE_BUNDLE_VERSION "0.1"
-# MACOSX_BUNDLE_SHORT_VERSION_STRING "0.1"
-# # MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/cmake/customtemplate.plist.in
-# )
build_module(hicnlight_module
- SHARED
- SOURCES ${MODULE_SOURCE_FILES}
- DEPENDS ${DEPENDENCIES}
- COMPONENT lib${LIBTRANSPORT}
- INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS} ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS}
- # LIBRARY_ROOT_DIR "vpp_plugins"
- DEFINITIONS ${COMPILER_DEFINITIONS}
- COMPILE_OPTIONS ${COMPILE_FLAGS}
+ SHARED
+ SOURCES ${MODULE_SOURCE_FILES}
+ DEPENDS ${DEPENDENCIES}
+ COMPONENT ${LIBTRANSPORT_COMPONENT}
+ INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS} ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS}
+ DEFINITIONS ${COMPILER_DEFINITIONS}
+ COMPILE_OPTIONS ${COMPILE_FLAGS}
)
diff --git a/libtransport/src/io_modules/udp/udp_socket_connector.cc b/libtransport/src/io_modules/udp/udp_socket_connector.cc
index 456886a54..1412d8c07 100644
--- a/libtransport/src/io_modules/udp/udp_socket_connector.cc
+++ b/libtransport/src/io_modules/udp/udp_socket_connector.cc
@@ -17,8 +17,8 @@
#include <hicn/transport/portability/win_portability.h>
#endif
+#include <glog/logging.h>
#include <hicn/transport/errors/errors.h>
-#include <hicn/transport/utils/log.h>
#include <hicn/transport/utils/object_pool.h>
#include <io_modules/udp/udp_socket_connector.h>
@@ -117,7 +117,7 @@ void UdpSocketConnector::doWrite() {
// The connection has been closed by the application.
return;
} else {
- TRANSPORT_LOGE("%d %s", ec.value(), ec.message().c_str());
+ LOG(ERROR) << ec.value() << " " << ec.message();
tryReconnect();
}
});
@@ -137,7 +137,7 @@ void UdpSocketConnector::doRead() {
// The connection has been closed by the application.
return;
} else {
- TRANSPORT_LOGE("%d %s", ec.value(), ec.message().c_str());
+ LOG(ERROR) << ec.value() << " " << ec.message();
tryReconnect();
}
});
@@ -145,7 +145,7 @@ void UdpSocketConnector::doRead() {
void UdpSocketConnector::tryReconnect() {
if (state_ == Connector::State::CONNECTED) {
- TRANSPORT_LOGE("Connection lost. Trying to reconnect...\n");
+ LOG(ERROR) << "Connection lost. Trying to reconnect...";
state_ = Connector::State::CONNECTING;
is_reconnection_ = true;
io_service_.post([this]() {
@@ -201,7 +201,7 @@ void UdpSocketConnector::handleDeadline(const std::error_code &ec) {
if (!ec) {
io_service_.post([this]() {
socket_.close();
- TRANSPORT_LOGE("Error connecting. Is the forwarder running?\n");
+ LOG(ERROR) << "Error connecting. Is the forwarder running?";
});
}
}
diff --git a/libtransport/src/io_modules/udp/udp_socket_connector.h b/libtransport/src/io_modules/udp/udp_socket_connector.h
index 8ab08e17a..c483e14aa 100644
--- a/libtransport/src/io_modules/udp/udp_socket_connector.h
+++ b/libtransport/src/io_modules/udp/udp_socket_connector.h
@@ -16,6 +16,7 @@
#pragma once
#include <hicn/transport/config.h>
+#include <hicn/transport/core/asio_wrapper.h>
#include <hicn/transport/core/connector.h>
#include <hicn/transport/core/content_object.h>
#include <hicn/transport/core/global_object_pool.h>
@@ -24,8 +25,6 @@
#include <hicn/transport/core/packet.h>
#include <hicn/transport/utils/branch_prediction.h>
-#include <asio.hpp>
-#include <asio/steady_timer.hpp>
#include <deque>
namespace transport {