From e8fabe3f6313a3b9050fe16458e4714d9dce426e Mon Sep 17 00:00:00 2001 From: Mauro Sardara Date: Fri, 1 Feb 2019 17:12:38 +0100 Subject: [HICN-10] Compile libtransport with libmemif support Change-Id: I81d1cb4d5f16a61c35f66fe347985f05d8c97383 Signed-off-by: Mauro Sardara --- libtransport/src/hicn/transport/CMakeLists.txt | 2 +- .../src/hicn/transport/core/CMakeLists.txt | 2 +- .../src/hicn/transport/core/memif_connector.cc | 50 ++++++++++++++++------ .../src/hicn/transport/core/memif_connector.h | 27 ++---------- .../hicn/transport/core/vpp_forwarder_interface.cc | 4 ++ 5 files changed, 46 insertions(+), 39 deletions(-) (limited to 'libtransport/src/hicn/transport') diff --git a/libtransport/src/hicn/transport/CMakeLists.txt b/libtransport/src/hicn/transport/CMakeLists.txt index fd5721273..92330c10b 100644 --- a/libtransport/src/hicn/transport/CMakeLists.txt +++ b/libtransport/src/hicn/transport/CMakeLists.txt @@ -17,7 +17,7 @@ configure_file("config.h.in" "config.h" @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h DESTINATION include/hicn/transport - COMPONENT lib${LIBTRANSPORT} + COMPONENT lib${LIBTRANSPORT}-dev ) add_subdirectory(core) diff --git a/libtransport/src/hicn/transport/core/CMakeLists.txt b/libtransport/src/hicn/transport/core/CMakeLists.txt index a97e74b2a..dff93adeb 100644 --- a/libtransport/src/hicn/transport/core/CMakeLists.txt +++ b/libtransport/src/hicn/transport/core/CMakeLists.txt @@ -51,7 +51,7 @@ list(APPEND SOURCE_FILES ) if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") - if (BUILD_WITH_VPP OR BUILD_VPP_PLUGIN) + if (BUILD_WITH_VPP OR BUILD_HICNPLUGIN) list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vpp_forwarder_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/memif_connector.h diff --git a/libtransport/src/hicn/transport/core/memif_connector.cc b/libtransport/src/hicn/transport/core/memif_connector.cc index 6c5f2ff5f..a650c3681 100644 --- a/libtransport/src/hicn/transport/core/memif_connector.cc +++ b/libtransport/src/hicn/transport/core/memif_connector.cc @@ -20,12 +20,36 @@ #include #include +extern "C" { +#include +}; + #define CANCEL_TIMER 1 namespace transport { namespace core { +struct memif_connection { + uint16_t index; + /* memif conenction handle */ + memif_conn_handle_t conn; + /* transmit queue id */ + uint16_t tx_qid; + /* tx buffers */ + memif_buffer_t *tx_bufs; + /* allocated tx buffers counter */ + /* number of tx buffers pointing to shared memory */ + uint16_t tx_buf_num; + /* rx buffers */ + memif_buffer_t *rx_bufs; + /* allcoated rx buffers counter */ + /* number of rx buffers pointing to shared memory */ + uint16_t rx_buf_num; + /* interface ip address */ + uint8_t ip_addr[4]; +}; + std::once_flag MemifConnector::flag_; utils::EpollEventReactor MemifConnector::main_event_reactor_; @@ -39,7 +63,7 @@ MemifConnector::MemifConnector(PacketReceivedCallback &&receive_callback, send_timer_(std::make_unique(event_reactor_)), io_service_(io_service), packet_counter_(0), - memif_connection_({}), + memif_connection_(std::make_unique()), tx_buf_counter_(0), is_connecting_(true), is_reconnection_(false), @@ -83,7 +107,7 @@ void MemifConnector::connect(uint32_t memif_id, long memif_mode) { /* get interrupt queue id */ int fd = -1; - err = memif_get_queue_efd(memif_connection_.conn, 0, &fd); + err = memif_get_queue_efd(memif_connection_->conn, 0, &fd); if (TRANSPORT_EXPECT_FALSE(err != MEMIF_ERR_SUCCESS)) { TRANSPORT_LOGI("memif_get_queue_efd: %s", memif_strerror(err)); return; @@ -95,7 +119,7 @@ void MemifConnector::connect(uint32_t memif_id, long memif_mode) { // Add fd to epoll of instance event_reactor_.addFileDescriptor( fd, EPOLLIN, [this](const utils::Event &evt) -> int { - return onInterrupt(memif_connection_.conn, this, 0); + return onInterrupt(memif_connection_->conn, this, 0); }); memif_worker_ = std::make_unique( @@ -103,7 +127,7 @@ void MemifConnector::connect(uint32_t memif_id, long memif_mode) { } int MemifConnector::createMemif(uint32_t index, uint8_t mode, char *s) { - memif_connection_t *c = &memif_connection_; + memif_connection_t *c = memif_connection_.get(); /* setting memif connection arguments */ memif_conn_args_t args; @@ -151,7 +175,7 @@ int MemifConnector::createMemif(uint32_t index, uint8_t mode, char *s) { } int MemifConnector::deleteMemif() { - memif_connection_t *c = &memif_connection_; + memif_connection_t *c = memif_connection_.get(); if (c->rx_bufs) { free(c->rx_bufs); @@ -231,7 +255,7 @@ int MemifConnector::controlFdUpdate(int fd, uint8_t events) { } int MemifConnector::bufferAlloc(long n, uint16_t qid) { - memif_connection_t *c = &memif_connection_; + memif_connection_t *c = memif_connection_.get(); int err; uint16_t r; /* set data pointer to shared memory and set buffer_len to shared mmeory @@ -249,7 +273,7 @@ int MemifConnector::bufferAlloc(long n, uint16_t qid) { } int MemifConnector::txBurst(uint16_t qid) { - memif_connection_t *c = &memif_connection_; + memif_connection_t *c = memif_connection_.get(); int err; uint16_t r; /* inform peer memif interface about data in shared memory buffers */ @@ -313,7 +337,7 @@ int MemifConnector::onDisconnect(memif_conn_handle_t conn, void *private_ctx) { MemifConnector *connector = (MemifConnector *)private_ctx; // TRANSPORT_LOGI ("Packet received: %u", connector->packet_counter_); TRANSPORT_LOGI("Packet to process: %u", - connector->memif_connection_.tx_buf_num); + connector->memif_connection_->tx_buf_num); return 0; } @@ -323,7 +347,7 @@ int MemifConnector::onInterrupt(memif_conn_handle_t conn, void *private_ctx, uint16_t qid) { MemifConnector *connector = (MemifConnector *)private_ctx; - memif_connection_t *c = &connector->memif_connection_; + memif_connection_t *c = connector->memif_connection_.get(); int err = MEMIF_ERR_SUCCESS, ret_val; uint16_t rx; @@ -447,7 +471,7 @@ int MemifConnector::doSend() { max = size < MAX_MEMIF_BUFS ? size : MAX_MEMIF_BUFS; if (TRANSPORT_EXPECT_FALSE( - (n = bufferAlloc(max, memif_connection_.tx_qid)) < 0)) { + (n = bufferAlloc(max, memif_connection_->tx_qid)) < 0)) { TRANSPORT_LOGI("Error allocating buffers."); return -1; } @@ -459,21 +483,21 @@ int MemifConnector::doSend() { const utils::MemBuf *current = packet; std::size_t offset = 0; uint8_t *shared_buffer = - reinterpret_cast(memif_connection_.tx_bufs[i].data); + reinterpret_cast(memif_connection_->tx_bufs[i].data); do { std::memcpy(shared_buffer + offset, current->data(), current->length()); offset += current->length(); current = current->next(); } while (current != packet); - memif_connection_.tx_bufs[i].len = uint32_t(offset); + memif_connection_->tx_bufs[i].len = uint32_t(offset); TRANSPORT_LOGD("Packet size : %zu", offset); output_buffer_.pop_front(); } - txBurst(memif_connection_.tx_qid); + txBurst(memif_connection_->tx_qid); utils::SpinLock::Acquire locked(write_msgs_lock_); size = output_buffer_.size(); diff --git a/libtransport/src/hicn/transport/core/memif_connector.h b/libtransport/src/hicn/transport/core/memif_connector.h index 4667ec0b2..ff838930f 100644 --- a/libtransport/src/hicn/transport/core/memif_connector.h +++ b/libtransport/src/hicn/transport/core/memif_connector.h @@ -32,33 +32,11 @@ #define _Static_assert static_assert -extern "C" { -#include -}; - namespace transport { namespace core { -typedef struct { - uint16_t index; - /* memif conenction handle */ - memif_conn_handle_t conn; - /* transmit queue id */ - uint16_t tx_qid; - /* tx buffers */ - memif_buffer_t *tx_bufs; - /* allocated tx buffers counter */ - /* number of tx buffers pointing to shared memory */ - uint16_t tx_buf_num; - /* rx buffers */ - memif_buffer_t *rx_bufs; - /* allcoated rx buffers counter */ - /* number of rx buffers pointing to shared memory */ - uint16_t rx_buf_num; - /* interface ip address */ - uint8_t ip_addr[4]; -} memif_connection_t; +typedef struct memif_connection memif_connection_t; #define APP_NAME "libtransport" #define IF_NAME "vpp_connection" @@ -68,6 +46,7 @@ typedef struct { #define MEMIF_LOG2_RING_SIZE 11 class MemifConnector : public Connector { + typedef void *memif_conn_handle_t; public: MemifConnector(PacketReceivedCallback &&receive_callback, OnReconnect &&on_reconnect_callback, @@ -135,7 +114,7 @@ class MemifConnector : public Connector { asio::io_service &io_service_; std::unique_ptr work_; uint32_t packet_counter_; - memif_connection_t memif_connection_; + std::unique_ptr memif_connection_; uint16_t tx_buf_counter_; PacketRing input_buffer_; diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc index 828e31a0a..69b18c0d9 100644 --- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc +++ b/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc @@ -22,6 +22,10 @@ #include #include +extern "C" { +#include +}; + typedef enum { MASTER = 0, SLAVE = 1 } memif_role_t; #define MEMIF_DEFAULT_RING_SIZE 2048 -- cgit 1.2.3-korg