aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/io_modules/forwarder
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/io_modules/forwarder')
-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
8 files changed, 59 insertions, 78 deletions
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 {