diff options
author | Mauro Sardara <msardara@cisco.com> | 2019-02-01 17:12:38 +0100 |
---|---|---|
committer | Mauro Sardara <msardara@cisco.com> | 2019-02-01 18:41:39 +0100 |
commit | e8fabe3f6313a3b9050fe16458e4714d9dce426e (patch) | |
tree | b379acde21e48a0f2e047d47f79ea30e8d43bd80 /libtransport | |
parent | c00bc6fc2af9a54fe339f8d6a3ec1ab889c2931e (diff) |
[HICN-10] Compile libtransport with libmemif support
Change-Id: I81d1cb4d5f16a61c35f66fe347985f05d8c97383
Signed-off-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'libtransport')
-rw-r--r-- | libtransport/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libtransport/cmake/Modules/Packaging.cmake | 18 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/core/CMakeLists.txt | 2 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/core/memif_connector.cc | 50 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/core/memif_connector.h | 27 | ||||
-rw-r--r-- | libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc | 4 |
7 files changed, 56 insertions, 49 deletions
diff --git a/libtransport/CMakeLists.txt b/libtransport/CMakeLists.txt index 4df87b056..d2567ed77 100644 --- a/libtransport/CMakeLists.txt +++ b/libtransport/CMakeLists.txt @@ -44,7 +44,7 @@ set(raaqm_config_path ${CMAKE_INSTALL_PREFIX}/etc/hicn-consumer.conf) # Install includes set(INSTALL_INCLUDE_DIR include/hicn/transport) -if (BUILD_VPP_PLUGIN AND BUILD_MEMIF_CONNECTOR AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") +if ((BUILD_HICNPLUGIN OR BUILD_MEMIF_CONNECTOR) AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") set(__vpp__ 1) find_package(Vpp REQUIRED) find_package(Libmemif REQUIRED) diff --git a/libtransport/cmake/Modules/Packaging.cmake b/libtransport/cmake/Modules/Packaging.cmake index 64d1dd325..4112d3844 100644 --- a/libtransport/cmake/Modules/Packaging.cmake +++ b/libtransport/cmake/Modules/Packaging.cmake @@ -29,47 +29,47 @@ set(lib${LIBTRANSPORT}-dev_DESCRIPTION ${lib${LIBTRANSPORT}_DESCRIPTION} set(lib${LIBTRANSPORT}-devel_DESCRIPTION ${lib${LIBTRANSPORT}_DESCRIPTION} CACHE STRING "Description for deb/rpm package.") -if ((BUILD_MEMIF_CONNECTOR OR BUILD_VPP_PLUGIN) AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") +if ((BUILD_MEMIF_CONNECTOR OR BUILD_HICNPLUGIN) AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") set(lib${LIBTRANSPORT}_DEB_DEPENDENCIES - "libhicn (>= stable_version), libparc (>= 1.0), vpp-lib (== stable_version-release)" + "lib${LIBHICN} (>= stable_version), libparc (>= 1.0), vpp-lib (= stable_version-release)" CACHE STRING "Dependencies for deb/rpm package." ) set(lib${LIBTRANSPORT}_RPM_DEPENDENCIES - "libhicn >= stable_version, libparc >= 1.0, vpp-lib = stable_version-release" + "lib${LIBHICN} >= stable_version, libparc >= 1.0, vpp-lib = stable_version-release" CACHE STRING "Dependencies for deb/rpm package." ) set(lib${LIBTRANSPORT}-dev_DEB_DEPENDENCIES - "lib${LIBTRANSPORT} (>= stable_version), libasio-dev (>= 1.10), libhicn-dev (>= stable_version), libparc-dev (>= 1.0), vpp-dev (== stable_version-release)" + "lib${LIBTRANSPORT} (>= stable_version), libasio-dev (>= 1.10), libhicn-dev (>= stable_version), libparc-dev (>= 1.0), vpp-dev (= stable_version-release)" CACHE STRING "Dependencies for deb/rpm package." ) set(lib${LIBTRANSPORT}-dev_RPM_DEPENDENCIES - "lib${LIBTRANSPORT} >= stable_version, asio-devel >= 1.10, libhicn-devel >= stable_version, libparc-devel >= 1.0, vpp-devel = stable_version-release" + "lib${LIBTRANSPORT} >= stable_version, asio-devel >= 1.10, lib${LIBHICN}-devel >= stable_version, libparc-devel >= 1.0, vpp-devel = stable_version-release" CACHE STRING "Dependencies for deb/rpm package." ) else() set(lib${LIBTRANSPORT}_DEB_DEPENDENCIES - "libhicn (>= stable_version), libparc (>= 1.0)" + "lib${LIBHICN} (>= stable_version), libparc (>= 1.0)" CACHE STRING "Dependencies for deb/rpm package." ) set(lib${LIBTRANSPORT}_RPM_DEPENDENCIES - "libhicn >= stable_version, libparc >= 1.0" + "lib${LIBHICN} >= stable_version, libparc >= 1.0" CACHE STRING "Dependencies for deb/rpm package." ) set(lib${LIBTRANSPORT}-dev_DEB_DEPENDENCIES - "lib${LIBTRANSPORT} (>= stable_version), libasio-dev (>= 1.10), libhicn-dev (>= stable_version), libparc-dev (>= 1.0)" + "lib${LIBTRANSPORT} (>= stable_version), libasio-dev (>= 1.10), lib${LIBHICN}-dev (>= stable_version), libparc-dev (>= 1.0)" CACHE STRING "Dependencies for deb/rpm package." ) set(lib${LIBTRANSPORT}-dev_RPM_DEPENDENCIES - "lib${LIBTRANSPORT} >= stable_version, asio-devel >= 1.10, libhicn-devel >= stable_version, libparc-devel >= 1.0" + "lib${LIBTRANSPORT} >= stable_version, asio-devel >= 1.10, lib${LIBHICN}-devel >= stable_version, libparc-devel >= 1.0" CACHE STRING "Dependencies for deb/rpm package." ) 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 <sys/epoll.h> #include <cstdlib> +extern "C" { +#include <memif/libmemif.h> +}; + #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<utils::FdDeadlineTimer>(event_reactor_)), io_service_(io_service), packet_counter_(0), - memif_connection_({}), + memif_connection_(std::make_unique<memif_connection_t>()), 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<std::thread>( @@ -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<uint8_t *>(memif_connection_.tx_bufs[i].data); + reinterpret_cast<uint8_t *>(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 <memif/libmemif.h> -}; - 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<asio::io_service::work> work_; uint32_t packet_counter_; - memif_connection_t memif_connection_; + std::unique_ptr<memif_connection_t> 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 <hicn/transport/core/prefix.h> #include <hicn/transport/core/vpp_forwarder_interface.h> +extern "C" { +#include <memif/libmemif.h> +}; + typedef enum { MASTER = 0, SLAVE = 1 } memif_role_t; #define MEMIF_DEFAULT_RING_SIZE 2048 |