diff options
Diffstat (limited to 'libtransport/src/io_modules')
13 files changed, 29 insertions, 83 deletions
diff --git a/libtransport/src/io_modules/CMakeLists.txt b/libtransport/src/io_modules/CMakeLists.txt index f4143de04..f1a27d3cb 100644 --- a/libtransport/src/io_modules/CMakeLists.txt +++ b/libtransport/src/io_modules/CMakeLists.txt @@ -15,7 +15,7 @@ ############################################################## # Android case: no submodules ############################################################## -if (${CMAKE_SYSTEM_NAME} MATCHES Android) +if (${CMAKE_SYSTEM_NAME} MATCHES Android OR ${CMAKE_SYSTEM_NAME} MATCHES iOS) list(APPEND SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/hicn-light-ng/hicn_forwarder_module.cc ) diff --git a/libtransport/src/io_modules/forwarder/CMakeLists.txt b/libtransport/src/io_modules/forwarder/CMakeLists.txt index 3922316d3..2235d842e 100644 --- a/libtransport/src/io_modules/forwarder/CMakeLists.txt +++ b/libtransport/src/io_modules/forwarder/CMakeLists.txt @@ -17,7 +17,6 @@ list(APPEND MODULE_HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/errors.h ${CMAKE_CURRENT_SOURCE_DIR}/forwarder_module.h ${CMAKE_CURRENT_SOURCE_DIR}/forwarder.h - ${CMAKE_CURRENT_SOURCE_DIR}/global_counter.h ) list(APPEND MODULE_SOURCE_FILES diff --git a/libtransport/src/io_modules/forwarder/forwarder.cc b/libtransport/src/io_modules/forwarder/forwarder.cc index 3ae5bf397..bfe4dd5de 100644 --- a/libtransport/src/io_modules/forwarder/forwarder.cc +++ b/libtransport/src/io_modules/forwarder/forwarder.cc @@ -14,12 +14,12 @@ */ #include <core/global_configuration.h> +#include <core/global_id_counter.h> #include <core/local_connector.h> #include <core/udp_connector.h> #include <core/udp_listener.h> #include <glog/logging.h> #include <io_modules/forwarder/forwarder.h> -#include <io_modules/forwarder/global_id_counter.h> namespace transport { @@ -90,11 +90,13 @@ Connector::Id Forwarder::registerLocalConnector( asio::io_service &io_service, Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback) { utils::SpinLock::Acquire locked(connector_lock_); auto id = GlobalCounter<Connector::Id>::getInstance().getNext(); auto connector = std::make_shared<LocalConnector>( - io_service, receive_callback, sent_callback, nullptr, reconnect_callback); + io_service, std::move(receive_callback), std::move(sent_callback), + std::move(close_callback), std::move(reconnect_callback)); connector->setConnectorId(id); local_connectors_.emplace(id, std::move(connector)); return id; @@ -150,34 +152,13 @@ void Forwarder::onPacketReceived(Connector *connector, return; } - for (auto &packet_buffer_ptr : packets) { - auto &packet_buffer = *packet_buffer_ptr; - - // Figure out the type of packet we received - bool is_interest = Packet::isInterest(packet_buffer.data()); - - Packet *packet = nullptr; - if (is_interest) { - packet = static_cast<Interest *>(&packet_buffer); - } else { - packet = static_cast<ContentObject *>(&packet_buffer); - } - - for (auto &c : local_connectors_) { - auto role = c.second->getRole(); - auto is_producer = role == Connector::Role::PRODUCER; - if ((is_producer && is_interest) || (!is_producer && !is_interest)) { - c.second->send(*packet); - } else { - LOG(ERROR) << "Error sending packet to local connector. is_interest = " - << is_interest << " - is_producer = " << is_producer; - } - } + for (auto &c : local_connectors_) { + c.second->receive(packets); + } - // PCS Lookup + FIB lookup. Skip for now + // PCS Lookup + FIB lookup. Skip for now - // Forward packet to local connectors - } + // Forward packet to local connectors } void Forwarder::send(Packet &packet) { @@ -304,4 +285,4 @@ void Forwarder::parseForwarderConfiguration( } } // namespace core -} // namespace transport
\ No newline at end of file +} // namespace transport diff --git a/libtransport/src/io_modules/forwarder/forwarder.h b/libtransport/src/io_modules/forwarder/forwarder.h index 38b4260b3..9ad989fcd 100644 --- a/libtransport/src/io_modules/forwarder/forwarder.h +++ b/libtransport/src/io_modules/forwarder/forwarder.h @@ -47,6 +47,7 @@ class Forwarder { asio::io_service &io_service, Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback); Forwarder &deleteConnector(Connector::Id id); diff --git a/libtransport/src/io_modules/forwarder/forwarder_module.cc b/libtransport/src/io_modules/forwarder/forwarder_module.cc index 0ced84ab4..77d2b5e6a 100644 --- a/libtransport/src/io_modules/forwarder/forwarder_module.cc +++ b/libtransport/src/io_modules/forwarder/forwarder_module.cc @@ -37,8 +37,6 @@ void ForwarderModule::send(Packet &packet) { forwarder_.send(packet); DLOG_IF(INFO, VLOG_IS_ON(3)) << "Sending from " << connector_id_ << " to " << 1 - connector_id_; - - // local_faces_.at(1 - local_id_).onPacket(packet); } void ForwarderModule::send(const utils::MemBuf::Ptr &buffer) { @@ -58,12 +56,13 @@ void ForwarderModule::closeConnection() { void ForwarderModule::init(Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback, asio::io_service &io_service, const std::string &app_name) { connector_id_ = forwarder_.registerLocalConnector( io_service, std::move(receive_callback), std::move(sent_callback), - std::move(reconnect_callback)); + std::move(close_callback), std::move(reconnect_callback)); name_ = app_name; } diff --git a/libtransport/src/io_modules/forwarder/forwarder_module.h b/libtransport/src/io_modules/forwarder/forwarder_module.h index 52a12b67e..a48701161 100644 --- a/libtransport/src/io_modules/forwarder/forwarder_module.h +++ b/libtransport/src/io_modules/forwarder/forwarder_module.h @@ -44,6 +44,7 @@ class ForwarderModule : public IoModule { void init(Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback, asio::io_service &io_service, const std::string &app_name = "Libtransport") override; diff --git a/libtransport/src/io_modules/forwarder/global_id_counter.h b/libtransport/src/io_modules/forwarder/global_id_counter.h deleted file mode 100644 index 0a67b76d5..000000000 --- a/libtransport/src/io_modules/forwarder/global_id_counter.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 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/utils/singleton.h> - -#include <atomic> -#include <mutex> - -namespace transport { - -namespace core { - -template <typename T = uint64_t> -class GlobalCounter : public utils::Singleton<GlobalCounter<T>> { - public: - friend class utils::Singleton<GlobalCounter>; - T getNext() { return counter_++; } - - private: - GlobalCounter() : counter_(0) {} - std::atomic<T> counter_; -}; - -} // namespace core -} // namespace transport
\ No newline at end of file diff --git a/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.cc b/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.cc index f67bd9447..95f04822f 100644 --- a/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.cc +++ b/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.cc @@ -100,12 +100,13 @@ void HicnForwarderModule::closeConnection() { void HicnForwarderModule::init( Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback, asio::io_service &io_service, const std::string &app_name) { if (!connector_) { connector_.reset(new UdpTunnelConnector( io_service, std::move(receive_callback), std::move(sent_callback), - nullptr, std::move(reconnect_callback))); + std::move(close_callback), std::move(reconnect_callback))); } } @@ -130,7 +131,7 @@ bool HicnForwarderModule::isControlMessage(utils::MemBuf &packet_buffer) { */ utils::MemBuf::Ptr HicnForwarderModule::createCommandRoute( std::unique_ptr<sockaddr> &&addr, uint8_t prefix_length) { - utils::MemBuf::Ptr ret = utils::MemBuf::create(sizeof(msg_route_add_t)); + auto ret = PacketManager<>::getInstance().getMemBuf(); auto command = reinterpret_cast<msg_route_add_t *>(ret->writableData()); ret->append(sizeof(msg_route_add_t)); std::memset(command, 0, sizeof(*command)); @@ -170,8 +171,7 @@ utils::MemBuf::Ptr HicnForwarderModule::createCommandRoute( } utils::MemBuf::Ptr HicnForwarderModule::createCommandDeleteConnection() { - utils::MemBuf::Ptr ret = - utils::MemBuf::create(sizeof(msg_connection_remove_t)); + auto ret = PacketManager<>::getInstance().getMemBuf(); auto command = reinterpret_cast<msg_connection_remove_t *>(ret->writableData()); ret->append(sizeof(msg_connection_remove_t)); @@ -194,8 +194,7 @@ utils::MemBuf::Ptr HicnForwarderModule::createCommandDeleteConnection() { } utils::MemBuf::Ptr HicnForwarderModule::createCommandMapmeSendUpdate() { - utils::MemBuf::Ptr ret = - utils::MemBuf::create(sizeof(msg_mapme_send_update_t)); + auto ret = PacketManager<>::getInstance().getMemBuf(); auto command = reinterpret_cast<msg_mapme_send_update_t *>(ret->writableData()); ret->append(sizeof(msg_mapme_send_update_t)); @@ -217,7 +216,7 @@ utils::MemBuf::Ptr HicnForwarderModule::createCommandMapmeSendUpdate() { utils::MemBuf::Ptr HicnForwarderModule::createCommandSetForwardingStrategy( std::unique_ptr<sockaddr> &&addr, uint32_t prefix_len, std::string strategy) { - utils::MemBuf::Ptr ret = utils::MemBuf::create(sizeof(msg_strategy_set_t)); + auto ret = PacketManager<>::getInstance().getMemBuf(); auto command = reinterpret_cast<msg_strategy_set_t *>(ret->writableData()); ret->append(sizeof(msg_strategy_set_t)); std::memset(command, 0, sizeof(*command)); diff --git a/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.h b/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.h index 0bf82757d..7f0e7aca8 100644 --- a/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.h +++ b/libtransport/src/io_modules/hicn-light-ng/hicn_forwarder_module.h @@ -64,6 +64,7 @@ class HicnForwarderModule : public IoModule { void init(Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback, asio::io_service &io_service, const std::string &app_name = "Libtransport") override; diff --git a/libtransport/src/io_modules/loopback/loopback_module.cc b/libtransport/src/io_modules/loopback/loopback_module.cc index 5b7ed5f61..a7f30eb26 100644 --- a/libtransport/src/io_modules/loopback/loopback_module.cc +++ b/libtransport/src/io_modules/loopback/loopback_module.cc @@ -58,6 +58,7 @@ void LoopbackModule::closeConnection() { void LoopbackModule::init(Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback, asio::io_service &io_service, const std::string &app_name) { @@ -66,7 +67,7 @@ void LoopbackModule::init(Connector::PacketReceivedCallback &&receive_callback, local_faces_.emplace( local_faces_.begin() + local_id_, new LocalConnector(io_service, std::move(receive_callback), - std::move(sent_callback), nullptr, + std::move(sent_callback), std::move(close_callback), std::move(reconnect_callback))); } } diff --git a/libtransport/src/io_modules/loopback/loopback_module.h b/libtransport/src/io_modules/loopback/loopback_module.h index 2779ae7e3..d51f237f4 100644 --- a/libtransport/src/io_modules/loopback/loopback_module.h +++ b/libtransport/src/io_modules/loopback/loopback_module.h @@ -42,6 +42,7 @@ class LoopbackModule : public IoModule { void init(Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback, asio::io_service &io_service, const std::string &app_name = "Libtransport") override; diff --git a/libtransport/src/io_modules/memif/vpp_forwarder_module.cc b/libtransport/src/io_modules/memif/vpp_forwarder_module.cc index 65260077a..c096a71b8 100644 --- a/libtransport/src/io_modules/memif/vpp_forwarder_module.cc +++ b/libtransport/src/io_modules/memif/vpp_forwarder_module.cc @@ -50,13 +50,14 @@ VPPForwarderModule::~VPPForwarderModule() {} void VPPForwarderModule::init( Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback, asio::io_service &io_service, const std::string &app_name) { if (!connector_) { connector_ = std::make_unique<MemifConnector>( std::move(receive_callback), std::move(sent_callback), - Connector::OnCloseCallback(0), std::move(reconnect_callback), - io_service, app_name); + std::move(close_callback), std::move(reconnect_callback), io_service, + app_name); } } diff --git a/libtransport/src/io_modules/memif/vpp_forwarder_module.h b/libtransport/src/io_modules/memif/vpp_forwarder_module.h index 162ee0ca5..5a5358078 100644 --- a/libtransport/src/io_modules/memif/vpp_forwarder_module.h +++ b/libtransport/src/io_modules/memif/vpp_forwarder_module.h @@ -48,6 +48,7 @@ class VPPForwarderModule : public IoModule { void init(Connector::PacketReceivedCallback &&receive_callback, Connector::PacketSentCallback &&sent_callback, + Connector::OnCloseCallback &&close_callback, Connector::OnReconnectCallback &&reconnect_callback, asio::io_service &io_service, const std::string &app_name = "Libtransport") override; |