summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Grajciar <grajciar.jakub@gmail.com>2017-08-30 10:13:25 +0200
committerDamjan Marion <dmarion.lists@gmail.com>2017-09-13 20:12:54 +0000
commit7c5c40db2a8d71a857ae63b6238cfac6e257da6d (patch)
treef0c01c2087ffd67e770d6f7932849ba13f44f12f
parenta4393be1a03f6a8f8da5d53c22b8dca52fed6f51 (diff)
Shared memory packet interface (memif) library
Change-Id: I5097462ae85acd705f19e92517c01094dba7565f Signed-off-by: Jakub Grajciar <grajciar.jakub@gmail.com>
-rw-r--r--extras/libmemif/Makefile.am80
-rw-r--r--extras/libmemif/README.md72
-rwxr-xr-xextras/libmemif/bootstrap3
-rw-r--r--extras/libmemif/configure.ac13
-rw-r--r--extras/libmemif/dockerfile19
-rw-r--r--extras/libmemif/docs/BuildInstructions.md54
-rw-r--r--extras/libmemif/docs/GettingStarted.md215
-rw-r--r--extras/libmemif/docs/architecture.pngbin0 -> 18805 bytes
-rw-r--r--extras/libmemif/doxygen.conf2427
-rw-r--r--extras/libmemif/examples/ExampleSetup.md206
-rw-r--r--extras/libmemif/examples/README.md16
-rw-r--r--extras/libmemif/examples/icmp_responder-epoll/main.c791
-rw-r--r--extras/libmemif/examples/icmp_responder-mt/main.c921
-rw-r--r--extras/libmemif/examples/icmp_responder/icmp_proto.c246
-rw-r--r--extras/libmemif/examples/icmp_responder/icmp_proto.h26
-rw-r--r--extras/libmemif/examples/icmp_responder/main.c416
-rw-r--r--extras/libmemif/src/libmemif.h442
-rw-r--r--extras/libmemif/src/main.c1810
-rw-r--r--extras/libmemif/src/memif.h185
-rw-r--r--extras/libmemif/src/memif_private.h265
-rw-r--r--extras/libmemif/src/socket.c883
-rw-r--r--extras/libmemif/src/socket.h89
-rw-r--r--extras/libmemif/test/main_test.c1079
-rw-r--r--extras/libmemif/test/main_test.h25
-rw-r--r--extras/libmemif/test/socket_test.c625
-rw-r--r--extras/libmemif/test/socket_test.h25
-rw-r--r--extras/libmemif/test/unit_test.c63
-rw-r--r--extras/libmemif/test/unit_test.h38
28 files changed, 11034 insertions, 0 deletions
diff --git a/extras/libmemif/Makefile.am b/extras/libmemif/Makefile.am
new file mode 100644
index 00000000000..48e4bb89b86
--- /dev/null
+++ b/extras/libmemif/Makefile.am
@@ -0,0 +1,80 @@
+# Copyright (c) 2017 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.
+
+AUTOMAKE_OPTIONS = foreign subdir-objects
+
+ACLOCAL_AMFLAGS = -I m4
+
+AM_CPPFLAGS = -g -DMEMIF_DBG -DICMP_DBG
+
+.PHONY: release
+release:
+ $(MAKE) AM_CPPFLAGS="-O3"
+
+.PHONY: doc
+doc:
+ @echo Building doxygen documentation...
+ doxygen doxygen.conf
+ @echo Doxygen documentation built in docs directory.
+
+#
+# unit_test
+#
+unit_test_SOURCES = test/unit_test.c \
+ test/main_test.c \
+ test/socket_test.c \
+ src/main.c \
+ src/socket.c
+# macro MEMIF_UNIT_TEST -> compile functions without static keyword
+# and declare them in header files, so they can be called from unit tests
+unit_test_CPPFLAGS = $(AM_CPPFLAGS) -Itest -Isrc -DMEMIF_UNIT_TEST -g $(CHECK_CFLAGS)
+unit_test_LDADD = $(CHECK_LIBS)
+
+#
+# main lib
+#
+libmemif_la_SOURCES = src/main.c src/socket.c
+libmemif_la_CPPFLAGS = $(AM_CPPFLAGS) -Isrc
+
+#
+# ICMP responder example
+#
+icmpr_SOURCES = examples/icmp_responder/main.c examples/icmp_responder/icmp_proto.c
+icmpr_LDADD = libmemif.la
+icmpr_CPPFLAGS = $(AM_CPPFLAGS) -Isrc -Iexamples/icmp_responder
+
+#
+# ICMP responder libmemif event polling example
+#
+icmpr_epoll_SOURCES = examples/icmp_responder-epoll/main.c \
+ examples/icmp_responder/icmp_proto.c
+icmpr_epoll_LDADD = libmemif.la
+icmpr_epoll_CPPFLAGS = $(AM_CPPFLAGS) -Isrc -Iexamples/icmp_responder
+
+#
+# ICMP responder multi-thread example
+#
+icmpr_mt_SOURCES = examples/icmp_responder-mt/main.c \
+ examples/icmp_responder/icmp_proto.c
+icmpr_mt_LDADD = libmemif.la -lpthread
+icmpr_mt_CPPFLAGS = $(AM_CPPFLAGS) -Isrc -Iexamples/icmp_responder
+
+noinst_PROGRAMS = icmpr icmpr-epoll icmpr-mt
+
+check_PROGRAMS = unit_test
+
+include_HEADERS = src/libmemif.h
+
+lib_LTLIBRARIES = libmemif.la
+
+TESTS = $(check_PROGRAMS)
diff --git a/extras/libmemif/README.md b/extras/libmemif/README.md
new file mode 100644
index 00000000000..0cccfb373b5
--- /dev/null
+++ b/extras/libmemif/README.md
@@ -0,0 +1,72 @@
+Shared Memory Packet Interface (memif) Library
+==============================================
+## Introduction
+
+Shared memory packet interface (memif) provides high performance packet transmit and receive between user application and Vector Packet Processing (VPP) or multiple user applications. Using libmemif, user application can create shared memory interface in master or slave mode and connect to VPP or another application using libmemif. Once the connection is established, user application can receive or transmit packets using libmemif API.
+
+![Architecture](docs/architecture.png)
+
+## Features
+
+- [x] Slave mode
+ - [x] Connect to VPP over memif
+ - [x] ICMP responder example app
+- [x] Transmit/receive packets
+- [x] Interrupt mode support
+- [x] File descriptor event polling in libmemif (optional)
+ - [x] Simplify file descriptor event polling (one handler for control and interrupt channel)
+- [x] Multiple connections
+- [x] Multiple queues
+ - [x] Multi-thread support
+- [x] Master mode
+ - [ ] Multiple regions (TODO)
+- [ ] Performance testing (TODO)
+
+## Quickstart
+
+This setup will run libmemif ICMP responder example app in container. Install [docker](https://docs.docker.com/engine/installation) engine.
+Useful link: [Docker documentation](https://docs.docker.com/get-started).
+
+Pull image:
+```
+# docker pull ligato/libmemif-sample-service
+```
+
+Now you should be able to see ligato/libmemif-sample-service image on your local machine (IMAGE ID in this README may be outdated):
+```
+# docker images
+REPOSITORY TAG IMAGE ID CREATED SIZE
+ligato/libmemif-sample-service latest 32ecc2f9d013 About a minute ago 468MB
+...
+```
+
+Run container:
+```
+# docker run -it --rm --name icmp-responder --hostname icmp-responder --privileged -v "/run/vpp/:/run/vpp/" ligato/libmemif-sample-service
+```
+Example application will start in debug mode. Output should look like this:
+```
+ICMP_Responder:add_epoll_fd:204: fd 0 added to epoll
+MEMIF_DEBUG:src/main.c:memif_init:383: app name: ICMP_Responder
+ICMP_Responder:add_epoll_fd:204: fd 4 added to epoll
+LIBMEMIF EXAMPLE APP: ICMP_Responder (debug)
+==============================
+libmemif version: 1.0 (debug)
+memif version: 256
+commands:
+ help - prints this help
+ exit - exit app
+ conn <index> - create memif (slave-mode)
+ del <index> - delete memif
+ show - show connection details
+ ip-set <index> <ip-addr> - set interface ip address
+ rx-mode <index> <qid> <polling|interrupt> - set queue rx mode
+```
+
+Continue with [Example setup](examples/ExampleSetup.md) which contains instructions on how to set up conenction between icmpr-epoll example app and VPP-memif.
+
+#### Next steps
+
+- [Build instructions](docs/BuildInstructions.md) Instructions on how to build/install libmemif.
+- [Examples](examples/README.md) More example apps presenting different features.
+- [Getting started](docs/GettingStarted.md) Introduction to libmemif API. Explaining library usage in custom app.
diff --git a/extras/libmemif/bootstrap b/extras/libmemif/bootstrap
new file mode 100755
index 00000000000..5613c2b4bdb
--- /dev/null
+++ b/extras/libmemif/bootstrap
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+autoreconf -fis
diff --git a/extras/libmemif/configure.ac b/extras/libmemif/configure.ac
new file mode 100644
index 00000000000..30fd3ddacdc
--- /dev/null
+++ b/extras/libmemif/configure.ac
@@ -0,0 +1,13 @@
+AC_INIT(libmemif, 1.0)
+LT_INIT
+AM_INIT_AUTOMAKE
+AM_SILENT_RULES([yes])
+AC_PREFIX_DEFAULT([/usr])
+
+PKG_CHECK_MODULES([CHECK], [check])
+
+AC_PROG_CC
+
+AC_OUTPUT([Makefile])
+
+AC_CONFIG_MACRO_DIR([m4])
diff --git a/extras/libmemif/dockerfile b/extras/libmemif/dockerfile
new file mode 100644
index 00000000000..92b2d2a11e5
--- /dev/null
+++ b/extras/libmemif/dockerfile
@@ -0,0 +1,19 @@
+FROM ubuntu:xenial
+
+RUN apt-get update && \
+ apt-get install -y git build-essential autoconf pkg-config libtool sudo check
+RUN rm -rf /var/lib/apt/lists/*
+
+RUN git clone https://github.com/JakubGrajciar/libmemif.git /libmemif
+WORKDIR /libmemif
+RUN git checkout dev
+RUN ./bootstrap
+RUN ./configure
+RUN make
+RUN make install
+
+RUN mkdir /var/vpp
+
+RUN ulimit -c unlimited
+
+CMD ./.libs/icmpr-epoll
diff --git a/extras/libmemif/docs/BuildInstructions.md b/extras/libmemif/docs/BuildInstructions.md
new file mode 100644
index 00000000000..9bb59b94c11
--- /dev/null
+++ b/extras/libmemif/docs/BuildInstructions.md
@@ -0,0 +1,54 @@
+## Build Instructions
+
+Install dependencies
+```
+# sudo apt-get install -y git autoconf pkg_config libtool check
+```
+
+Clone repository to your local machine.
+```
+# git clone https://github.com/JakubGrajciar/libmemif.git
+```
+
+From root directory execute:
+For debug build:
+```
+# ./bootstrap
+# ./configure
+# make
+# make install
+```
+
+For release build:
+```
+# ./bootstrap
+# ./configure
+# make release
+# make install
+```
+Verify installation:
+```
+# ./.libs/icmpr-epoll
+```
+> Make sure to run the binary file from ./.libs. File ./icmp\_responder in libmemif root directory is script that links the library, so it only verifies successful build. Default install path is /usr/lib.
+Use _help_ command to display build information and commands:
+```
+ICMP_Responder:add_epoll_fd:204: fd 0 added to epoll
+MEMIF_DEBUG:src/main.c:memif_init:383: app name: ICMP_Responder
+ICMP_Responder:add_epoll_fd:204: fd 4 added to epoll
+LIBMEMIF EXAMPLE APP: ICMP_Responder (debug)
+==============================
+libmemif version: 1.0 (debug)
+memif version: 256
+commands:
+ help - prints this help
+ exit - exit app
+ conn <index> - create memif (slave-mode)
+ del <index> - delete memif
+ show - show connection details
+ ip-set <index> <ip-addr> - set interface ip address
+ rx-mode <index> <qid> <polling|interrupt> - set queue rx mode
+```
+#### Examples
+
+Once the library is build/installed, refer to [Examples](../examples/README.md) and [Getting started](GettingStarted.md) for additional information on basic use cases and API usage.
diff --git a/extras/libmemif/docs/GettingStarted.md b/extras/libmemif/docs/GettingStarted.md
new file mode 100644
index 00000000000..3cc0ceb0db1
--- /dev/null
+++ b/extras/libmemif/docs/GettingStarted.md
@@ -0,0 +1,215 @@
+## Getting started
+
+#### Concept (Connecting to VPP)
+
+For detailed information on api calls and structures please refer to [libmemif.h](../src/libmemif.h)
+
+1. Initialize memif
+ - Declare callback function handling file descriptor event polling.
+```C
+int
+control_fd_update (int fd, uint8_t events)
+{
+...
+}
+```
+ - Call memif initialization function. memif\_init
+```C
+err = memif_init (control_fd_update, APP_NAME);
+```
+
+> If event occurres on any file descriptor returned by this callback, call memif\_control\_fd\_handler function.
+```C
+memif_err = memif_control_fd_handler (evt.data.fd, events);
+```
+> If callback function parameter for memif\_init function is set to NULL, libmemif will handle file descriptor event polling.
+ Api call memif\_poll\_event will call epoll\_pwait with user defined timeout to poll event on file descriptors opened by libmemif.
+```C
+/* main loop */
+ while (1)
+ {
+ if (memif_poll_event (-1) < 0)
+ {
+ DBG ("poll_event error!");
+ }
+ }
+```
+
+> Memif initialization function will initialize internal structures and create timer file descriptor, which will be used for sending periodic connection requests. Timer is disarmed if no memif interface is created.
+
+2. Creating interface
+ - Declare memif connction handle.
+```C
+memif_conn_handle_t c;
+```
+> example app uses struct that contains connection handle, rx/tx buffers and other connection specific information.
+
+ - Specify connection arguments.
+```C
+memif_conn_args_t args;
+memset (&args, 0, sizeof (args));
+args.is_master = is_master;
+args.log2_ring_size = 10;
+args.buffer_size = 2048;
+args.num_s2m_rings = 2;
+args.num_m2s_rings = 2;
+strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
+strncpy ((char *) args.instance_name, APP_NAME, strlen (APP_NAME));
+args.mode = 0;
+args.interface_id = 0;
+```
+ - Declare callback functions called on connected/disconnected/interrupted status changed.
+```C
+int
+on_connect (memif_conn_handle_t conn, void *private_ctx)
+{
+...
+}
+
+int
+on_disconnect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif connected!");
+ return 0;
+}
+```
+ - Call memif interface create function. memif\_create
+```C
+err = memif_create (&c->conn,
+ &args, on_connect, on_disconnect, on_interrupt, &ctx[index]);
+```
+> If connection is in slave mode, arms timer file descriptor.
+> If on interrupt callback is set to NULL, user will not be notified about interrupt. Use memif\_get\_queue\_efd call to get interrupt file descriptor for specific queue.
+```C
+int fd = -1;
+err = memif_get_queue_efd (c->conn, data->qid, &fd);
+```
+
+3. Connection establishment
+ - User application will poll events on all file descriptors returned in memif\_control\_fd\_update\_t callback.
+ - On event call memif\_control\_fd\_handler.
+ - Everything else regarding connection establishment will be done internally.
+ - Once connection has been established, a callback will inform the user about connection status change.
+
+4. Interrupt packet receive
+ - If event is polled on interrupt file descriptor, libmemif will call memif\_interrupt\_t callback specified for every connection instance.
+```C
+int
+on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
+{
+...
+}
+```
+
+6. Memif buffers
+ - Packet data are stored in memif\_buffer\_t. Pointer _data_ points to shared memory buffer, and unsigned integer *data\_len* contains packet data length.
+```C
+typedef struct
+{
+ uint16_t desc_index;
+ uint32_t buffer_len;
+ uint32_t data_len;
+ void *data;
+} memif_buffer_t;
+```
+
+5. Packet receive
+ - Api call memif\_rx\_burst will set all required fields in memif buffers provided by user application.
+```C
+err = memif_rx_burst (c->conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &rx);
+```
+ - User application can then process packets.
+ - Api call memif\_buffer\_free will make supplied memif buffers ready for next receive and mark shared memory buffers as free.
+```C
+err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+```
+
+6. Packet transmit
+ - Api call memif\_buffer\_alloc will set all required fields in memif buffers provided by user application.
+```C
+err = memif_buffer_alloc (c->conn, qid, c->tx_bufs, n, &r);
+```
+ - User application can populate shared memory buffers with packets.
+ - Api call memif\_tx\_burst will inform peer interface (master memif on VPP) that there are packets ready to receive and mark memif buffers as free.
+```C
+err = memif_tx_burst (c->conn, qid, c->tx_bufs, c->tx_buf_num, &r);
+```
+
+7. Helper functions
+ - Memif details
+ - Api call memif\_get\_details will return details about connection.
+```C
+err = memif_get_details (c->conn, &md, buf, buflen);
+```
+ - Memif error messages
+ - Every api call returns error code (integer value) mapped to error string.
+ - Call memif\_strerror will return error message assigned to specific error code.
+```C
+if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_get_details: %s", memif_strerror (err));
+```
+ - Not all syscall errors are translated to memif error codes. If error code 1 (MEMIF\_ERR\_SYSCALL) is returned then libmemif needs to be compiled with -DMEMIF_DBG flag to print error message. Use _make -B_ to rebuild libmemif in debug mode.
+
+#### Example app (libmemif fd event polling):
+
+- [ICMP Responder](../examples/icmp_responder/main.c)
+> Optional argument: transmit queue id.
+```
+icmpr 1
+```
+> Set transmit queue id to 1. Default is 0.
+> Application will create memif interface in slave mode and try to connect to VPP. Exit using Ctrl+C. Application will handle SIGINT signal, free allocated memory and exit with EXIT_SUCCESS.
+
+#### Example app:
+
+- [ICMP Responder custom fd event polling](../examples/icmp_responder-epoll/main.c)
+
+#### Example app (multi-thread queue polling)
+
+- [ICMP Responder multi-thread](../examples/icmp_responder-mt/main.c)
+
+> Simple example of libmemif multi-thread usage. Connection establishment is handled by main thread. There are two rx queues in this example. One in polling mode and second in interrupt mode.
+
+VPP config:
+```
+# create memif id 0 master
+# set int state memif0 up
+# set int ip address memif0 192.168.1.1/24
+# ping 192.168.1.2
+```
+For multiple rings (queues) support run VPP with worker threads:
+example startup.conf:
+```
+unix {
+ interactive
+ nodaemon
+ full-coredump
+}
+
+cpu {
+ workers 2
+}
+```
+VPP config:
+```
+# create memif id 0 master
+# set int state memif0 up
+# set int ip address memif0 192.168.1.1/24
+# ping 192.168.1.2
+```
+> Master mode queue number is limited by worker threads. Slave mode interface needs to specify number of queues.
+```
+# create memif id 0 slave rx-queues 2 tx-queues 2
+```
+> Example applications use VPP default socket file for memif: /run/vpp/memif.sock
+> For master mode, socket directory must exist prior to memif\_create call.
+
+#### Unit tests
+
+Unit tests use [Check](https://libcheck.github.io/check/index.html) framework. This framework must be installed in order to build *unit\_test* binary.
+Ubuntu/Debian:
+```
+sudo apt-get install check
+```
+[More platforms](https://libcheck.github.io/check/web/install.html)
+
diff --git a/extras/libmemif/docs/architecture.png b/extras/libmemif/docs/architecture.png
new file mode 100644
index 00000000000..b196c25c5aa
--- /dev/null
+++ b/extras/libmemif/docs/architecture.png
Binary files differ
diff --git a/extras/libmemif/doxygen.conf b/extras/libmemif/doxygen.conf
new file mode 100644
index 00000000000..503eef50d68
--- /dev/null
+++ b/extras/libmemif/doxygen.conf
@@ -0,0 +1,2427 @@
+# Doxyfile 1.8.11
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project.
+#
+# All text after a double hash (##) is considered a comment and is placed in
+# front of the TAG it is preceding.
+#
+# All text after a single hash (#) is considered a comment and will be ignored.
+# The format is:
+# TAG = value [value, ...]
+# For lists, items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (\" \").
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all text
+# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv
+# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv
+# for the list of possible encodings.
+# The default value is: UTF-8.
+
+DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
+# double-quotes, unless you are using Doxywizard) that should identify the
+# project for which the documentation is generated. This name is used in the
+# title of most generated pages and in a few other places.
+# The default value is: My Project.
+
+PROJECT_NAME = "Libmemif"
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
+# could be handy for archiving the generated documentation or if some version
+# control system is used.
+
+PROJECT_NUMBER = 1.0
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer a
+# quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF = Shared memory packet interface library
+
+# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
+# in the documentation. The maximum height of the logo should not exceed 55
+# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
+# the logo to the output directory.
+
+PROJECT_LOGO =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
+# into which the generated documentation will be written. If a relative path is
+# entered, it will be relative to the location where doxygen was started. If
+# left blank the current directory will be used.
+
+OUTPUT_DIRECTORY = ./docs
+
+# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub-
+# directories (in 2 levels) under the output directory of each output format and
+# will distribute the generated files over these directories. Enabling this
+# option can be useful when feeding doxygen a huge amount of source files, where
+# putting all generated files in the same directory would otherwise causes
+# performance problems for the file system.
+# The default value is: NO.
+
+CREATE_SUBDIRS = NO
+
+# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
+# characters to appear in the names of generated files. If set to NO, non-ASCII
+# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode
+# U+3044.
+# The default value is: NO.
+
+ALLOW_UNICODE_NAMES = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese,
+# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States),
+# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian,
+# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages),
+# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian,
+# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian,
+# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish,
+# Ukrainian and Vietnamese.
+# The default value is: English.
+
+OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
+# descriptions after the members that are listed in the file and class
+# documentation (similar to Javadoc). Set to NO to disable this.
+# The default value is: YES.
+
+BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief
+# description of a member or function before the detailed description
+#
+# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+# The default value is: YES.
+
+REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator that is
+# used to form the text in various listings. Each string in this list, if found
+# as the leading text of the brief description, will be stripped from the text
+# and the result, after processing the whole list, is used as the annotated
+# text. Otherwise, the brief description is used as-is. If left blank, the
+# following values are used ($name is automatically replaced with the name of
+# the entity):The $name class, The $name widget, The $name file, is, provides,
+# specifies, contains, represents, a, an and the.
+
+ABBREVIATE_BRIEF =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# doxygen will generate a detailed section even if there is only a brief
+# description.
+# The default value is: NO.
+
+ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+# The default value is: NO.
+
+INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
+# before files name in the file list and in the header files. If set to NO the
+# shortest path that makes the file name unique will be used
+# The default value is: YES.
+
+FULL_PATH_NAMES = YES
+
+# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
+# Stripping is only done if one of the specified strings matches the left-hand
+# part of the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the path to
+# strip.
+#
+# Note that you can specify absolute paths here, but also relative paths, which
+# will be relative from the directory where doxygen is started.
+# This tag requires that the tag FULL_PATH_NAMES is set to YES.
+
+STRIP_FROM_PATH =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
+# path mentioned in the documentation of a class, which tells the reader which
+# header file to include in order to use a class. If left blank only the name of
+# the header file containing the class definition is used. Otherwise one should
+# specify the list of include paths that are normally passed to the compiler
+# using the -I flag.
+
+STRIP_FROM_INC_PATH =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
+# less readable) file names. This can be useful is your file systems doesn't
+# support long names like on DOS, Mac, or CD-ROM.
+# The default value is: NO.
+
+SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the
+# first line (until the first dot) of a Javadoc-style comment as the brief
+# description. If set to NO, the Javadoc-style will behave just like regular Qt-
+# style comments (thus requiring an explicit @brief command for a brief
+# description.)
+# The default value is: NO.
+
+JAVADOC_AUTOBRIEF = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
+# line (until the first dot) of a Qt-style comment as the brief description. If
+# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
+# requiring an explicit \brief command for a brief description.)
+# The default value is: NO.
+
+QT_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
+# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
+# a brief description. This used to be the default behavior. The new default is
+# to treat a multi-line C++ comment block as a detailed description. Set this
+# tag to YES if you prefer the old behavior instead.
+#
+# Note that setting this tag to YES also means that rational rose comments are
+# not recognized any more.
+# The default value is: NO.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
+# documentation from any documented member that it re-implements.
+# The default value is: YES.
+
+INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new
+# page for each member. If set to NO, the documentation of a member will be part
+# of the file/class/namespace that contains it.
+# The default value is: NO.
+
+SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen
+# uses this value to replace tabs by spaces in code fragments.
+# Minimum value: 1, maximum value: 16, default value: 4.
+
+TAB_SIZE = 4
+
+# This tag can be used to specify a number of aliases that act as commands in
+# the documentation. An alias has the form:
+# name=value
+# For example adding
+# "sideeffect=@par Side Effects:\n"
+# will allow you to put the command \sideeffect (or @sideeffect) in the
+# documentation, which will result in a user-defined paragraph with heading
+# "Side Effects:". You can put \n's in the value part of an alias to insert
+# newlines.
+
+ALIASES =
+
+# This tag can be used to specify a number of word-keyword mappings (TCL only).
+# A mapping has the form "name=value". For example adding "class=itcl::class"
+# will allow you to use the command class in the itcl::class meaning.
+
+TCL_SUBST =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
+# only. Doxygen will then generate output that is more tailored for C. For
+# instance, some of the names that are used will be different. The list of all
+# members will be omitted, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
+# Python sources only. Doxygen will then generate output that is more tailored
+# for that language. For instance, namespaces will be presented as packages,
+# qualified scopes will look different, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources. Doxygen will then generate output that is tailored for Fortran.
+# The default value is: NO.
+
+OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for VHDL.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_VHDL = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given
+# extension. Doxygen has a built-in mapping, but you can override or extend it
+# using this tag. The format is ext=language, where ext is a file extension, and
+# language is one of the parsers supported by doxygen: IDL, Java, Javascript,
+# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran:
+# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran:
+# Fortran. In the later case the parser tries to guess whether the code is fixed
+# or free formatted code, this is the default for Fortran type files), VHDL. For
+# instance to make doxygen treat .inc files as Fortran files (default is PHP),
+# and .f files as C (default is Fortran), use: inc=Fortran f=C.
+#
+# Note: For files without extension you can use no_extension as a placeholder.
+#
+# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
+# the files are not read by doxygen.
+
+EXTENSION_MAPPING =
+
+# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
+# according to the Markdown format, which allows for more readable
+# documentation. See http://daringfireball.net/projects/markdown/ for details.
+# The output of markdown processing is further processed by doxygen, so you can
+# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
+# case of backward compatibilities issues.
+# The default value is: YES.
+
+MARKDOWN_SUPPORT = YES
+
+# When enabled doxygen tries to link words that correspond to documented
+# classes, or namespaces to their corresponding documentation. Such a link can
+# be prevented in individual cases by putting a % sign in front of the word or
+# globally by setting AUTOLINK_SUPPORT to NO.
+# The default value is: YES.
+
+AUTOLINK_SUPPORT = YES
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should set this
+# tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string);
+# versus func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+# The default value is: NO.
+
+BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+# The default value is: NO.
+
+CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:
+# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen
+# will parse them like normal C++ but will assume all classes use public instead
+# of private inheritance when no explicit protection keyword is present.
+# The default value is: NO.
+
+SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate
+# getter and setter methods for a property. Setting this option to YES will make
+# doxygen to replace the get and set methods by a property in the documentation.
+# This will only work if the methods are indeed getting or setting a simple
+# type. If this is not the case, or you want to show the methods anyway, you
+# should set this option to NO.
+# The default value is: YES.
+
+IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+# The default value is: NO.
+
+DISTRIBUTE_GROUP_DOC = NO
+
+# If one adds a struct or class to a group and this option is enabled, then also
+# any nested class or struct is added to the same group. By default this option
+# is disabled and one has to add nested compounds explicitly via \ingroup.
+# The default value is: NO.
+
+GROUP_NESTED_COMPOUNDS = NO
+
+# Set the SUBGROUPING tag to YES to allow class member groups of the same type
+# (for instance a group of public functions) to be put as a subgroup of that
+# type (e.g. under the Public Functions section). Set it to NO to prevent
+# subgrouping. Alternatively, this can be done per class using the
+# \nosubgrouping command.
+# The default value is: YES.
+
+SUBGROUPING = YES
+
+# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions
+# are shown inside the group in which they are included (e.g. using \ingroup)
+# instead of on a separate page (for HTML and Man pages) or section (for LaTeX
+# and RTF).
+#
+# Note that this feature does not work in combination with
+# SEPARATE_MEMBER_PAGES.
+# The default value is: NO.
+
+INLINE_GROUPED_CLASSES = NO
+
+# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
+# with only public data fields or simple typedef fields will be shown inline in
+# the documentation of the scope in which they are defined (i.e. file,
+# namespace, or group documentation), provided this scope is documented. If set
+# to NO, structs, classes, and unions are shown on a separate page (for HTML and
+# Man pages) or section (for LaTeX and RTF).
+# The default value is: NO.
+
+INLINE_SIMPLE_STRUCTS = NO
+
+# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
+# enum is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically be
+# useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+# The default value is: NO.
+
+TYPEDEF_HIDES_STRUCT = NO
+
+# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
+# cache is used to resolve symbols given their name and scope. Since this can be
+# an expensive process and often the same symbol appears multiple times in the
+# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small
+# doxygen will become slower. If the cache is too large, memory is wasted. The
+# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range
+# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536
+# symbols. At the end of a run doxygen will report the cache usage and suggest
+# the optimal cache size from a speed point of view.
+# Minimum value: 0, maximum value: 9, default value: 0.
+
+LOOKUP_CACHE_SIZE = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
+# documentation are documented, even if no documentation was available. Private
+# class members and static file members will be hidden unless the
+# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
+# Note: This will also disable the warnings about undocumented members that are
+# normally produced when WARNINGS is set to YES.
+# The default value is: NO.
+
+EXTRACT_ALL = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
+# be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
+# scope will be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PACKAGE = NO
+
+# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
+# included in the documentation.
+# The default value is: NO.
+
+EXTRACT_STATIC = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
+# locally in source files will be included in the documentation. If set to NO,
+# only classes defined in header files are included. Does not have any effect
+# for Java sources.
+# The default value is: YES.
+
+EXTRACT_LOCAL_CLASSES = YES
+
+# This flag is only useful for Objective-C code. If set to YES, local methods,
+# which are defined in the implementation section but not in the interface are
+# included in the documentation. If set to NO, only methods in the interface are
+# included.
+# The default value is: NO.
+
+EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base name of
+# the file that contains the anonymous namespace. By default anonymous namespace
+# are hidden.
+# The default value is: NO.
+
+EXTRACT_ANON_NSPACES = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
+# undocumented members inside documented classes or files. If set to NO these
+# members will be included in the various overviews, but no documentation
+# section is generated. This option has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
+HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy. If set
+# to NO, these classes will be included in the various overviews. This option
+# has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
+HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
+# (class|struct|union) declarations. If set to NO, these declarations will be
+# included in the documentation.
+# The default value is: NO.
+
+HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
+# documentation blocks found inside the body of a function. If set to NO, these
+# blocks will be appended to the function's detailed documentation block.
+# The default value is: NO.
+
+HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation that is typed after a
+# \internal command is included. If the tag is set to NO then the documentation
+# will be excluded. Set it to YES to include the internal documentation.
+# The default value is: NO.
+
+INTERNAL_DOCS = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file
+# names in lower-case letters. If set to YES, upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+# The default value is: system dependent.
+
+CASE_SENSE_NAMES = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
+# their full class and namespace scopes in the documentation. If set to YES, the
+# scope will be hidden.
+# The default value is: NO.
+
+HIDE_SCOPE_NAMES = NO
+
+# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
+# append additional text to a page's title, such as Class Reference. If set to
+# YES the compound reference will be hidden.
+# The default value is: NO.
+
+HIDE_COMPOUND_REFERENCE= NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
+# the files that are included by a file in the documentation of that file.
+# The default value is: YES.
+
+SHOW_INCLUDE_FILES = YES
+
+# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
+# grouped member an include statement to the documentation, telling the reader
+# which file to include in order to use the member.
+# The default value is: NO.
+
+SHOW_GROUPED_MEMB_INC = NO
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
+# files with double quotes in the documentation rather than with sharp brackets.
+# The default value is: NO.
+
+FORCE_LOCAL_INCLUDES = NO
+
+# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
+# documentation for inline members.
+# The default value is: YES.
+
+INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
+# (detailed) documentation of file and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order.
+# The default value is: YES.
+
+SORT_MEMBER_DOCS = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
+# descriptions of file, namespace and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order. Note that
+# this will also influence the order of the classes in the class list.
+# The default value is: NO.
+
+SORT_BRIEF_DOCS = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the
+# (brief and detailed) documentation of class members so that constructors and
+# destructors are listed first. If set to NO the constructors will appear in the
+# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
+# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
+# member documentation.
+# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
+# detailed member documentation.
+# The default value is: NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy
+# of group names into alphabetical order. If set to NO the group names will
+# appear in their defined order.
+# The default value is: NO.
+
+SORT_GROUP_NAMES = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
+# fully-qualified names, including namespaces. If set to NO, the class list will
+# be sorted only by class name, not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the alphabetical
+# list.
+# The default value is: NO.
+
+SORT_BY_SCOPE_NAME = NO
+
+# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
+# type resolution of all parameters of a function it will reject a match between
+# the prototype and the implementation of a member function even if there is
+# only one candidate or it is obvious which candidate to choose by doing a
+# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still
+# accept a match between prototype and implementation in such cases.
+# The default value is: NO.
+
+STRICT_PROTO_MATCHING = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo
+# list. This list is created by putting \todo commands in the documentation.
+# The default value is: YES.
+
+GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test
+# list. This list is created by putting \test commands in the documentation.
+# The default value is: YES.
+
+GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug
+# list. This list is created by putting \bug commands in the documentation.
+# The default value is: YES.
+
+GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)
+# the deprecated list. This list is created by putting \deprecated commands in
+# the documentation.
+# The default value is: YES.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional documentation
+# sections, marked by \if <section_label> ... \endif and \cond <section_label>
+# ... \endcond blocks.
+
+ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
+# initial value of a variable or macro / define can have for it to appear in the
+# documentation. If the initializer consists of more lines than specified here
+# it will be hidden. Use a value of 0 to hide initializers completely. The
+# appearance of the value of individual variables and macros / defines can be
+# controlled using \showinitializer or \hideinitializer command in the
+# documentation regardless of this setting.
+# Minimum value: 0, maximum value: 10000, default value: 30.
+
+MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
+# the bottom of the documentation of classes and structs. If set to YES, the
+# list will mention the files that were used to generate the documentation.
+# The default value is: YES.
+
+SHOW_USED_FILES = YES
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
+# will remove the Files entry from the Quick Index and from the Folder Tree View
+# (if specified).
+# The default value is: YES.
+
+SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
+# page. This will remove the Namespaces entry from the Quick Index and from the
+# Folder Tree View (if specified).
+# The default value is: YES.
+
+SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command command input-file, where command is the value of the
+# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
+# by doxygen. Whatever the program writes to standard output is used as the file
+# version. For an example see the documentation.
+
+FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. To create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option. You can
+# optionally specify a file name after the option, if omitted DoxygenLayout.xml
+# will be used as the name of the layout file.
+#
+# Note that if you run doxygen from a directory containing a file called
+# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
+# tag is left empty.
+
+LAYOUT_FILE =
+
+# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
+# the reference definitions. This must be a list of .bib files. The .bib
+# extension is automatically appended if omitted. This requires the bibtex tool
+# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info.
+# For LaTeX the style of the bibliography can be controlled using
+# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
+# search path. See also \cite for info how to create references.
+
+CITE_BIB_FILES =
+
+#---------------------------------------------------------------------------
+# Configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated to
+# standard output by doxygen. If QUIET is set to YES this implies that the
+# messages are off.
+# The default value is: NO.
+
+QUIET = NO
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
+# this implies that the warnings are on.
+#
+# Tip: Turn warnings on while writing the documentation.
+# The default value is: YES.
+
+WARNINGS = YES
+
+# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate
+# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
+# will automatically be disabled.
+# The default value is: YES.
+
+WARN_IF_UNDOCUMENTED = YES
+
+# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some parameters
+# in a documented function, or documenting parameters that don't exist or using
+# markup commands wrongly.
+# The default value is: YES.
+
+WARN_IF_DOC_ERROR = YES
+
+# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
+# are documented, but have no documentation for their parameters or return
+# value. If set to NO, doxygen will only warn about wrong or incomplete
+# parameter documentation, but not about the absence of documentation.
+# The default value is: NO.
+
+WARN_NO_PARAMDOC = NO
+
+# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
+# a warning is encountered.
+# The default value is: NO.
+
+WARN_AS_ERROR = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that doxygen
+# can produce. The string should contain the $file, $line, and $text tags, which
+# will be replaced by the file and line number from which the warning originated
+# and the warning text. Optionally the format may contain $version, which will
+# be replaced by the version of the file (if it could be obtained via
+# FILE_VERSION_FILTER)
+# The default value is: $file:$line: $text.
+
+WARN_FORMAT = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning and error
+# messages should be written. If left blank the output is written to standard
+# error (stderr).
+
+WARN_LOGFILE =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag is used to specify the files and/or directories that contain
+# documented source files. You may enter file names like myfile.cpp or
+# directories like /usr/src/myproject. Separate the files or directories with
+# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
+# Note: If this tag is empty the current directory is searched.
+
+INPUT = ./src/libmemif.h
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
+# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
+# documentation (see: http://www.gnu.org/software/libiconv) for the list of
+# possible encodings.
+# The default value is: UTF-8.
+
+INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
+# *.h) to filter out the source-files in the directories.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# read by doxygen.
+#
+# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
+# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
+# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc,
+# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.pyw, *.f90, *.f, *.for, *.tcl,
+# *.vhd, *.vhdl, *.ucf, *.qsf, *.as and *.js.
+
+FILE_PATTERNS =
+
+# The RECURSIVE tag can be used to specify whether or not subdirectories should
+# be searched for input files as well.
+# The default value is: NO.
+
+RECURSIVE = NO
+
+# The EXCLUDE tag can be used to specify files and/or directories that should be
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+#
+# Note that relative paths are relative to the directory from which doxygen is
+# run.
+
+EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
+# directories that are symbolic links (a Unix file system feature) are excluded
+# from the input.
+# The default value is: NO.
+
+EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories.
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories for example use the pattern */test/*
+
+EXCLUDE_PATTERNS =
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories use the pattern */test/*
+
+EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or directories
+# that contain example code fragments that are included (see the \include
+# command).
+
+EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
+# *.h) to filter out the source-files in the directories. If left blank all
+# files are included.
+
+EXAMPLE_PATTERNS =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude commands
+# irrespective of the value of the RECURSIVE tag.
+# The default value is: NO.
+
+EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or directories
+# that contain images that are to be included in the documentation (see the
+# \image command).
+
+IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command:
+#
+# <filter> <input-file>
+#
+# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the
+# name of an input file. Doxygen will then use the output that the filter
+# program writes to standard output. If FILTER_PATTERNS is specified, this tag
+# will be ignored.
+#
+# Note that the filter must not add or remove lines; it is applied before the
+# code is scanned, but not when the output code is generated. If lines are added
+# or removed, the anchors will not be placed correctly.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
+
+INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form: pattern=filter
+# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
+# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
+# patterns match the file name, INPUT_FILTER is applied.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
+
+FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will also be used to filter the input files that are used for
+# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
+# The default value is: NO.
+
+FILTER_SOURCE_FILES = NO
+
+# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
+# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
+# it is also possible to disable source filtering for a specific pattern using
+# *.ext= (so without naming a filter).
+# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.
+
+FILTER_SOURCE_PATTERNS =
+
+# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
+# is part of the input, its contents will be placed on the main page
+# (index.html). This can be useful if you have a project on for instance GitHub
+# and want to reuse the introduction page also for the doxygen output.
+
+USE_MDFILE_AS_MAINPAGE =
+
+#---------------------------------------------------------------------------
+# Configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will be
+# generated. Documented entities will be cross-referenced with these sources.
+#
+# Note: To get rid of all source code in the generated output, make sure that
+# also VERBATIM_HEADERS is set to NO.
+# The default value is: NO.
+
+SOURCE_BROWSER = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body of functions,
+# classes and enums directly into the documentation.
+# The default value is: NO.
+
+INLINE_SOURCES = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
+# special comment blocks from generated source code fragments. Normal C, C++ and
+# Fortran comments will always remain visible.
+# The default value is: YES.
+
+STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
+# function all documented functions referencing it will be listed.
+# The default value is: NO.
+
+REFERENCED_BY_RELATION = NO
+
+# If the REFERENCES_RELATION tag is set to YES then for each documented function
+# all documented entities called/used by that function will be listed.
+# The default value is: NO.
+
+REFERENCES_RELATION = NO
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
+# to YES then the hyperlinks from functions in REFERENCES_RELATION and
+# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
+# link to the documentation.
+# The default value is: YES.
+
+REFERENCES_LINK_SOURCE = YES
+
+# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the
+# source code will show a tooltip with additional information such as prototype,
+# brief description and links to the definition and documentation. Since this
+# will make the HTML file larger and loading of large files a bit slower, you
+# can opt to disable this feature.
+# The default value is: YES.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+SOURCE_TOOLTIPS = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code will
+# point to the HTML generated by the htags(1) tool instead of doxygen built-in
+# source browser. The htags tool is part of GNU's global source tagging system
+# (see http://www.gnu.org/software/global/global.html). You will need version
+# 4.8.6 or higher.
+#
+# To use it do the following:
+# - Install the latest version of global
+# - Enable SOURCE_BROWSER and USE_HTAGS in the config file
+# - Make sure the INPUT points to the root of the source tree
+# - Run doxygen as normal
+#
+# Doxygen will invoke htags (and that will in turn invoke gtags), so these
+# tools must be available from the command line (i.e. in the search path).
+#
+# The result: instead of the source browser generated by doxygen, the links to
+# source code will now point to the output of htags.
+# The default value is: NO.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a
+# verbatim copy of the header file for each class for which an include is
+# specified. Set to NO to disable this.
+# See also: Section \class.
+# The default value is: YES.
+
+VERBATIM_HEADERS = YES
+
+# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
+# clang parser (see: http://clang.llvm.org/) for more accurate parsing at the
+# cost of reduced performance. This can be particularly helpful with template
+# rich C++ code for which doxygen's built-in parser lacks the necessary type
+# information.
+# Note: The availability of this option depends on whether or not doxygen was
+# generated with the -Duse-libclang=ON option for CMake.
+# The default value is: NO.
+
+CLANG_ASSISTED_PARSING = NO
+
+# If clang assisted parsing is enabled you can provide the compiler with command
+# line options that you would normally use when invoking the compiler. Note that
+# the include paths will already be set by doxygen for the files and directories
+# specified with INPUT and INCLUDE_PATH.
+# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
+
+CLANG_OPTIONS =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all
+# compounds will be generated. Enable this if the project contains a lot of
+# classes, structs, unions or interfaces.
+# The default value is: YES.
+
+ALPHABETICAL_INDEX = YES
+
+# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in
+# which the alphabetical index list will be split.
+# Minimum value: 1, maximum value: 20, default value: 5.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
+COLS_IN_ALPHA_INDEX = 5
+
+# In case all classes in a project start with a common prefix, all classes will
+# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
+# can be used to specify a prefix (or a list of prefixes) that should be ignored
+# while generating the index headers.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
+IGNORE_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
+# The default value is: YES.
+
+GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
+# generated HTML page (for example: .htm, .php, .asp).
+# The default value is: .html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a user-defined HTML header file for
+# each generated HTML page. If the tag is left blank doxygen will generate a
+# standard header.
+#
+# To get valid HTML the header file that includes any scripts and style sheets
+# that doxygen needs, which is dependent on the configuration options used (e.g.
+# the setting GENERATE_TREEVIEW). It is highly recommended to start with a
+# default header using
+# doxygen -w html new_header.html new_footer.html new_stylesheet.css
+# YourConfigFile
+# and then modify the file new_header.html. See also section "Doxygen usage"
+# for information on how to generate the default header that doxygen normally
+# uses.
+# Note: The header is subject to change so you typically have to regenerate the
+# default header when upgrading to a newer version of doxygen. For a description
+# of the possible markers and block names see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
+# generated HTML page. If the tag is left blank doxygen will generate a standard
+# footer. See HTML_HEADER for more information on how to generate a default
+# footer and what special commands can be used inside the footer. See also
+# section "Doxygen usage" for information on how to generate the default footer
+# that doxygen normally uses.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
+# sheet that is used by each HTML page. It can be used to fine-tune the look of
+# the HTML output. If left blank doxygen will generate a default style sheet.
+# See also section "Doxygen usage" for information on how to generate the style
+# sheet that doxygen normally uses.
+# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as
+# it is more robust and this tag (HTML_STYLESHEET) will in the future become
+# obsolete.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_STYLESHEET =
+
+# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# cascading style sheets that are included after the standard style sheets
+# created by doxygen. Using this option one can overrule certain style aspects.
+# This is preferred over using HTML_STYLESHEET since it does not replace the
+# standard style sheet and is therefore more robust against future updates.
+# Doxygen will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list). For an example see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_STYLESHEET =
+
+# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the HTML output directory. Note
+# that these files will be copied to the base HTML output directory. Use the
+# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
+# files. In the HTML_STYLESHEET file, use the file name only. Also note that the
+# files will be copied as-is; there are no commands or markers available.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_FILES =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
+# will adjust the colors in the style sheet and background images according to
+# this color. Hue is specified as an angle on a colorwheel, see
+# http://en.wikipedia.org/wiki/Hue for more information. For instance the value
+# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
+# purple, and 360 is red again.
+# Minimum value: 0, maximum value: 359, default value: 220.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_HUE = 220
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
+# in the HTML output. For a value of 0 the output will use grayscales only. A
+# value of 255 will produce the most vivid colors.
+# Minimum value: 0, maximum value: 255, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_SAT = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
+# luminance component of the colors in the HTML output. Values below 100
+# gradually make the output lighter, whereas values above 100 make the output
+# darker. The value divided by 100 is the actual gamma applied, so 80 represents
+# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not
+# change the gamma.
+# Minimum value: 40, maximum value: 240, default value: 80.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_GAMMA = 80
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting this
+# to YES can help to show when doxygen was last run and thus if the
+# documentation is up to date.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_TIMESTAMP = NO
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
+# shown in the various tree structured indices initially; the user can expand
+# and collapse entries dynamically later on. Doxygen will expand the tree to
+# such a level that at most the specified number of entries are visible (unless
+# a fully collapsed tree already exceeds this amount). So setting the number of
+# entries 1 will produce a full collapsed tree by default. 0 is a special value
+# representing an infinite number of entries and will result in a full expanded
+# tree by default.
+# Minimum value: 0, maximum value: 9999, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_INDEX_NUM_ENTRIES = 100
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files will be
+# generated that can be used as input for Apple's Xcode 3 integrated development
+# environment (see: http://developer.apple.com/tools/xcode/), introduced with
+# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a
+# Makefile in the HTML output directory. Running make will produce the docset in
+# that directory and running make install will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
+# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
+# for more information.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_DOCSET = NO
+
+# This tag determines the name of the docset feed. A documentation feed provides
+# an umbrella under which multiple documentation sets from a single provider
+# (such as a company or product suite) can be grouped.
+# The default value is: Doxygen generated docs.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_FEEDNAME = "Doxygen generated docs"
+
+# This tag specifies a string that should uniquely identify the documentation
+# set bundle. This should be a reverse domain-name style string, e.g.
+# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_BUNDLE_ID = org.doxygen.Project
+
+# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify
+# the documentation publisher. This should be a reverse domain-name style
+# string, e.g. com.mycompany.MyDocSet.documentation.
+# The default value is: org.doxygen.Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_ID = org.doxygen.Publisher
+
+# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
+# The default value is: Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_NAME = Publisher
+
+# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
+# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
+# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
+# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on
+# Windows.
+#
+# The HTML Help Workshop contains a compiler that can convert all HTML output
+# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
+# files are now used as the Windows 98 help format, and will replace the old
+# Windows help format (.hlp) on all Windows platforms in the future. Compressed
+# HTML files also contain an index, a table of contents, and you can search for
+# words in the documentation. The HTML workshop also contains a viewer for
+# compressed HTML files.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_HTMLHELP = NO
+
+# The CHM_FILE tag can be used to specify the file name of the resulting .chm
+# file. You can add a path in front of the file if the result should not be
+# written to the html output directory.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+CHM_FILE =
+
+# The HHC_LOCATION tag can be used to specify the location (absolute path
+# including file name) of the HTML help compiler (hhc.exe). If non-empty,
+# doxygen will try to run the HTML help compiler on the generated index.hhp.
+# The file has to be specified with full path.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+HHC_LOCATION =
+
+# The GENERATE_CHI flag controls if a separate .chi index file is generated
+# (YES) or that it should be included in the master .chm file (NO).
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+GENERATE_CHI = NO
+
+# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)
+# and project file content.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+CHM_INDEX_ENCODING =
+
+# The BINARY_TOC flag controls whether a binary table of contents is generated
+# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it
+# enables the Previous and Next buttons.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members to
+# the table of contents of the HTML help documentation and to the tree view.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
+TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
+# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
+# (.qch) of the generated HTML documentation.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify
+# the file name of the resulting .qch file. The path specified is relative to
+# the HTML output folder.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
+# Project output. For more information please see Qt Help Project / Namespace
+# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace).
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_NAMESPACE = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
+# Help Project output. For more information please see Qt Help Project / Virtual
+# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual-
+# folders).
+# The default value is: doc.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
+# filter to add. For more information please see Qt Help Project / Custom
+# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
+# filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see Qt Help Project / Custom
+# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom-
+# filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's filter section matches. Qt Help Project / Filter Attributes (see:
+# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_SECT_FILTER_ATTRS =
+
+# The QHG_LOCATION tag can be used to specify the location of Qt's
+# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the
+# generated .qhp file.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHG_LOCATION =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be
+# generated, together with the HTML files, they form an Eclipse help plugin. To
+# install this plugin and make it available under the help contents menu in
+# Eclipse, the contents of the directory containing the HTML and XML files needs
+# to be copied into the plugins directory of eclipse. The name of the directory
+# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.
+# After copying Eclipse needs to be restarted before the help appears.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_ECLIPSEHELP = NO
+
+# A unique identifier for the Eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have this
+# name. Each documentation set should have its own identifier.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
+
+ECLIPSE_DOC_ID = org.doxygen.Project
+
+# If you want full control over the layout of the generated HTML pages it might
+# be necessary to disable the index and replace it with your own. The
+# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
+# of each HTML page. A value of NO enables the index and the value YES disables
+# it. Since the tabs in the index contain the same information as the navigation
+# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+DISABLE_INDEX = NO
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information. If the tag
+# value is set to YES, a side panel will be generated containing a tree-like
+# index structure (just like the one that is generated for HTML Help). For this
+# to work a browser that supports JavaScript, DHTML, CSS and frames is required
+# (i.e. any modern browser). Windows users are probably better off using the
+# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can
+# further fine-tune the look of the index. As an example, the default style
+# sheet generated by doxygen has an example that shows how to put an image at
+# the root of the tree instead of the PROJECT_NAME. Since the tree basically has
+# the same information as the tab index, you could consider setting
+# DISABLE_INDEX to YES when enabling this option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_TREEVIEW = NO
+
+# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
+# doxygen will group on one line in the generated HTML documentation.
+#
+# Note that a value of 0 will completely suppress the enum values from appearing
+# in the overview section.
+# Minimum value: 0, maximum value: 20, default value: 4.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
+# to set the initial width (in pixels) of the frame in which the tree is shown.
+# Minimum value: 0, maximum value: 1500, default value: 250.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+TREEVIEW_WIDTH = 250
+
+# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
+# external symbols imported via tag files in a separate window.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+EXT_LINKS_IN_WINDOW = NO
+
+# Use this tag to change the font size of LaTeX formulas included as images in
+# the HTML documentation. When you change the font size after a successful
+# doxygen run you need to manually remove any form_*.png images from the HTML
+# output directory to force them to be regenerated.
+# Minimum value: 8, maximum value: 50, default value: 10.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_FONTSIZE = 10
+
+# Use the FORMULA_TRANPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are not
+# supported properly for IE 6.0, but are supported on all modern browsers.
+#
+# Note that when changing this option you need to delete any form_*.png files in
+# the HTML output directory before the changes have effect.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_TRANSPARENT = YES
+
+# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
+# http://www.mathjax.org) which uses client side Javascript for the rendering
+# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
+# installed or if you want to formulas look prettier in the HTML output. When
+# enabled you may also need to install MathJax separately and configure the path
+# to it using the MATHJAX_RELPATH option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+USE_MATHJAX = NO
+
+# When MathJax is enabled you can set the default output format to be used for
+# the MathJax output. See the MathJax site (see:
+# http://docs.mathjax.org/en/latest/output.html) for more details.
+# Possible values are: HTML-CSS (which is slower, but has the best
+# compatibility), NativeMML (i.e. MathML) and SVG.
+# The default value is: HTML-CSS.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_FORMAT = HTML-CSS
+
+# When MathJax is enabled you need to specify the location relative to the HTML
+# output directory using the MATHJAX_RELPATH option. The destination directory
+# should contain the MathJax.js script. For instance, if the mathjax directory
+# is located at the same level as the HTML output directory, then
+# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
+# Content Delivery Network so you can quickly see the result without installing
+# MathJax. However, it is strongly recommended to install a local copy of
+# MathJax from http://www.mathjax.org before deployment.
+# The default value is: http://cdn.mathjax.org/mathjax/latest.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
+
+# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
+# extension names that should be enabled during MathJax rendering. For example
+# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_EXTENSIONS =
+
+# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
+# of code that will be used on startup of the MathJax code. See the MathJax site
+# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an
+# example see the documentation.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_CODEFILE =
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
+# the HTML output. The underlying search engine uses javascript and DHTML and
+# should work on any modern browser. Note that when using HTML help
+# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
+# there is already a search function so this one should typically be disabled.
+# For large projects the javascript based search engine can be slow, then
+# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
+# search using the keyboard; to jump to the search box use <access key> + S
+# (what the <access key> is depends on the OS and browser, but it is typically
+# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down
+# key> to jump into the search results window, the results can be navigated
+# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel
+# the search. The filter options can be selected when the cursor is inside the
+# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>
+# to select a filter and <Enter> or <escape> to activate or cancel the filter
+# option.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+SEARCHENGINE = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a web server instead of a web client using Javascript. There
+# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
+# setting. When disabled, doxygen will generate a PHP script for searching and
+# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
+# and searching needs to be provided by external tools. See the section
+# "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SERVER_BASED_SEARCH = NO
+
+# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
+# script for searching. Instead the search results are written to an XML file
+# which needs to be processed by an external indexer. Doxygen will invoke an
+# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
+# search results.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see: http://xapian.org/).
+#
+# See the section "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH = NO
+
+# The SEARCHENGINE_URL should point to a search engine hosted by a web server
+# which will return the search results when EXTERNAL_SEARCH is enabled.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see: http://xapian.org/). See the section "External Indexing and
+# Searching" for details.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHENGINE_URL =
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
+# search data is written to a file for indexing by an external tool. With the
+# SEARCHDATA_FILE tag the name of this file can be specified.
+# The default file is: searchdata.xml.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHDATA_FILE = searchdata.xml
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the
+# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
+# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
+# projects and redirect the results back to the right project.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH_ID =
+
+# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
+# projects other than the one defined by this configuration file, but that are
+# all added to the same external search index. Each project needs to have a
+# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of
+# to a relative location where the documentation can be found. The format is:
+# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTRA_SEARCH_MAPPINGS =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
+# The default value is: YES.
+
+GENERATE_LATEX = YES
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: latex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked.
+#
+# Note that when enabling USE_PDFLATEX this option is only used for generating
+# bitmaps for formulas in the HTML output, but not in the Makefile that is
+# written to the output directory.
+# The default file is: latex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate
+# index for LaTeX.
+# The default file is: makeindex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+MAKEINDEX_CMD_NAME = makeindex
+
+# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+COMPACT_LATEX = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used by the
+# printer.
+# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x
+# 14 inches) and executive (7.25 x 10.5 inches).
+# The default value is: a4.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+PAPER_TYPE = a4
+
+# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
+# that should be included in the LaTeX output. The package can be specified just
+# by its name or with the correct syntax as to be used with the LaTeX
+# \usepackage command. To get the times font for instance you can specify :
+# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
+# To use the option intlimits with the amsmath package you can specify:
+# EXTRA_PACKAGES=[intlimits]{amsmath}
+# If left blank no extra packages will be included.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for the
+# generated LaTeX document. The header should contain everything until the first
+# chapter. If it is left blank doxygen will generate a standard header. See
+# section "Doxygen usage" for information on how to let doxygen write the
+# default header to a separate file.
+#
+# Note: Only use a user-defined header if you know what you are doing! The
+# following commands have a special meaning inside the header: $title,
+# $datetime, $date, $doxygenversion, $projectname, $projectnumber,
+# $projectbrief, $projectlogo. Doxygen will replace $title with the empty
+# string, for the replacement values of the other commands the user is referred
+# to HTML_HEADER.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_HEADER =
+
+# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for the
+# generated LaTeX document. The footer should contain everything after the last
+# chapter. If it is left blank doxygen will generate a standard footer. See
+# LATEX_HEADER for more information on how to generate a default footer and what
+# special commands can be used inside the footer.
+#
+# Note: Only use a user-defined footer if you know what you are doing!
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_FOOTER =
+
+# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# LaTeX style sheets that are included after the standard style sheets created
+# by doxygen. Using this option one can overrule certain style aspects. Doxygen
+# will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list).
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_STYLESHEET =
+
+# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the LATEX_OUTPUT output
+# directory. Note that the files will be copied as-is; there are no commands or
+# markers available.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_FILES =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is
+# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will
+# contain links (just like the HTML output) instead of page references. This
+# makes the output suitable for online browsing using a PDF viewer.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+PDF_HYPERLINKS = YES
+
+# If the USE_PDFLATEX tag is set to YES, doxygen will use pdflatex to generate
+# the PDF file directly from the LaTeX files. Set this option to YES, to get a
+# higher quality PDF documentation.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+USE_PDFLATEX = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
+# command to the generated LaTeX files. This will instruct LaTeX to keep running
+# if errors occur, instead of asking the user for help. This option is also used
+# when generating formulas in HTML.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BATCHMODE = NO
+
+# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the
+# index chapters (such as File Index, Compound Index, etc.) in the output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_HIDE_INDICES = NO
+
+# If the LATEX_SOURCE_CODE tag is set to YES then doxygen will include source
+# code with syntax highlighting in the LaTeX output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_SOURCE_CODE = NO
+
+# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
+# bibliography, e.g. plainnat, or ieeetr. See
+# http://en.wikipedia.org/wiki/BibTeX and \cite for more info.
+# The default value is: plain.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BIB_STYLE = plain
+
+# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
+# page will contain the date and time when the page was generated. Setting this
+# to NO can help when comparing the output of multiple runs.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_TIMESTAMP = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The
+# RTF output is optimized for Word 97 and may not look too pretty with other RTF
+# readers/editors.
+# The default value is: NO.
+
+GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: rtf.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will
+# contain hyperlink fields. The RTF file will contain links (just like the HTML
+# output) instead of page references. This makes the output suitable for online
+# browsing using Word or some other Word compatible readers that support those
+# fields.
+#
+# Note: WordPad (write) and others do not support links.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's config
+# file, i.e. a series of assignments. You only have to provide replacements,
+# missing definitions are set to their default value.
+#
+# See also section "Doxygen usage" for information on how to generate the
+# default style sheet that doxygen normally uses.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an RTF document. Syntax is
+# similar to doxygen's config file. A template extensions file can be generated
+# using doxygen -e rtf extensionFile.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_EXTENSIONS_FILE =
+
+# If the RTF_SOURCE_CODE tag is set to YES then doxygen will include source code
+# with syntax highlighting in the RTF output.
+#
+# Note that which sources are shown also depends on other settings such as
+# SOURCE_BROWSER.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
+RTF_SOURCE_CODE = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for
+# classes and files.
+# The default value is: NO.
+
+GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it. A directory man3 will be created inside the directory specified by
+# MAN_OUTPUT.
+# The default directory is: man.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to the generated
+# man pages. In case the manual section does not start with a number, the number
+# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is
+# optional.
+# The default value is: .3.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_EXTENSION = .3
+
+# The MAN_SUBDIR tag determines the name of the directory created within
+# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by
+# MAN_EXTENSION with the initial . removed.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_SUBDIR =
+
+# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
+# will generate one additional man file for each entity documented in the real
+# man page(s). These additional files only source the real man page, but without
+# them the man command would be unable to find the correct page.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_LINKS = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
+# captures the structure of the code including all documentation.
+# The default value is: NO.
+
+GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: xml.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_OUTPUT = xml
+
+# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
+# listings (including syntax highlighting and cross-referencing information) to
+# the XML output. Note that enabling this will significantly increase the size
+# of the XML output.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_PROGRAMLISTING = YES
+
+#---------------------------------------------------------------------------
+# Configuration options related to the DOCBOOK output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files
+# that can be used to generate PDF.
+# The default value is: NO.
+
+GENERATE_DOCBOOK = NO
+
+# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in
+# front of it.
+# The default directory is: docbook.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_OUTPUT = docbook
+
+# If the DOCBOOK_PROGRAMLISTING tag is set to YES, doxygen will include the
+# program listings (including syntax highlighting and cross-referencing
+# information) to the DOCBOOK output. Note that enabling this will significantly
+# increase the size of the DOCBOOK output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_PROGRAMLISTING = NO
+
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
+# AutoGen Definitions (see http://autogen.sf.net) file that captures the
+# structure of the code including all documentation. Note that this feature is
+# still experimental and incomplete at the moment.
+# The default value is: NO.
+
+GENERATE_AUTOGEN_DEF = NO
+
+#---------------------------------------------------------------------------
+# Configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module
+# file that captures the structure of the code including all documentation.
+#
+# Note that this feature is still experimental and incomplete at the moment.
+# The default value is: NO.
+
+GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary
+# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI
+# output from the Perl module output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely
+# formatted so it can be parsed by a human reader. This is useful if you want to
+# understand what is going on. On the other hand, if this tag is set to NO, the
+# size of the Perl module output will be much smaller and Perl will parse it
+# just the same.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file are
+# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful
+# so different doxyrules.make files included by the same Makefile don't
+# overwrite each other's variables.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
+# C-preprocessor directives found in the sources and include files.
+# The default value is: YES.
+
+ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
+# in the source code. If set to NO, only conditional compilation will be
+# performed. Macro expansion can be done in a controlled way by setting
+# EXPAND_ONLY_PREDEF to YES.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+MACRO_EXPANSION = YES
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
+# the macro expansion is limited to the macros specified with the PREDEFINED and
+# EXPAND_AS_DEFINED tags.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+EXPAND_ONLY_PREDEF = YES
+
+# If the SEARCH_INCLUDES tag is set to YES, the include files in the
+# INCLUDE_PATH will be searched if a #include is found.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by the
+# preprocessor.
+# This tag requires that the tag SEARCH_INCLUDES is set to YES.
+
+INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will be
+# used.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+INCLUDE_FILE_PATTERNS =
+
+# The PREDEFINED tag can be used to specify one or more macro names that are
+# defined before the preprocessor is started (similar to the -D option of e.g.
+# gcc). The argument of the tag is a list of macros of the form: name or
+# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
+# is assumed. To prevent a macro definition from being undefined via #undef or
+# recursively expanded use the := operator instead of the = operator.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+PREDEFINED =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
+# tag can be used to specify a list of macro names that should be expanded. The
+# macro definition that is found in the sources will be used. Use the PREDEFINED
+# tag if you want to use a different macro definition that overrules the
+# definition found in the source code.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
+# remove all references to function-like macros that are alone on a line, have
+# an all uppercase name, and do not end with a semicolon. Such function macros
+# are typically used for boiler-plate code, and will confuse the parser if not
+# removed.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+SKIP_FUNCTION_MACROS = YES
+
+#---------------------------------------------------------------------------
+# Configuration options related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES tag can be used to specify one or more tag files. For each tag
+# file the location of the external documentation should be added. The format of
+# a tag file without this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where loc1 and loc2 can be relative or absolute paths or URLs. See the
+# section "Linking to external documentation" for more information about the use
+# of tag files.
+# Note: Each tag file must have a unique name (where the name does NOT include
+# the path). If a tag file is not located in the directory in which doxygen is
+# run, you must also specify the path to the tagfile here.
+
+TAGFILES =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
+# tag file that is based on the input files it reads. See section "Linking to
+# external documentation" for more information about the usage of tag files.
+
+GENERATE_TAGFILE =
+
+# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
+# the class index. If set to NO, only the inherited external classes will be
+# listed.
+# The default value is: NO.
+
+ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will be
+# listed.
+# The default value is: YES.
+
+EXTERNAL_GROUPS = YES
+
+# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
+# the related pages index. If set to NO, only the current project's pages will
+# be listed.
+# The default value is: YES.
+
+EXTERNAL_PAGES = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of 'which perl').
+# The default file (with absolute path) is: /usr/bin/perl.
+
+PERL_PATH = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES, doxygen will generate a class diagram
+# (in HTML and LaTeX) for classes with base or super classes. Setting the tag to
+# NO turns the diagrams off. Note that this option also works with HAVE_DOT
+# disabled, but it is recommended to install and use dot, since it yields more
+# powerful graphs.
+# The default value is: YES.
+
+CLASS_DIAGRAMS = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see:
+# http://www.mcternan.me.uk/mscgen/)) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH =
+
+# You can include diagrams made with dia in doxygen documentation. Doxygen will
+# then run dia to produce the diagram and insert it in the documentation. The
+# DIA_PATH tag allows you to specify the directory where the dia binary resides.
+# If left empty dia is assumed to be found in the default search path.
+
+DIA_PATH =
+
+# If set to YES the inheritance and collaboration graphs will hide inheritance
+# and usage relations if the target is undocumented or is not a class.
+# The default value is: YES.
+
+HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz (see:
+# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
+# Bell Labs. The other options in this section have no effect if this option is
+# set to NO
+# The default value is: YES.
+
+HAVE_DOT = YES
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
+# to run in parallel. When set to 0 doxygen will base this on the number of
+# processors available in the system. You can set it explicitly to a value
+# larger than 0 to get control over the balance between CPU load and processing
+# speed.
+# Minimum value: 0, maximum value: 32, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_NUM_THREADS = 0
+
+# When you want a differently looking font in the dot files that doxygen
+# generates you can specify the font name using DOT_FONTNAME. You need to make
+# sure dot is able to find the font, which can be done by putting it in a
+# standard location or by setting the DOTFONTPATH environment variable or by
+# setting DOT_FONTPATH to the directory containing the font.
+# The default value is: Helvetica.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTNAME = Helvetica
+
+# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of
+# dot graphs.
+# Minimum value: 4, maximum value: 24, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the default font as specified with
+# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set
+# the path where dot can find it using this tag.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH tag is set to YES then doxygen will generate a graph for
+# each documented class showing the direct and indirect inheritance relations.
+# Setting this tag to YES will force the CLASS_DIAGRAMS tag to NO.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CLASS_GRAPH = YES
+
+# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
+# graph for each documented class showing the direct and indirect implementation
+# dependencies (inheritance, containment, and class references variables) of the
+# class with other documented classes.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+COLLABORATION_GRAPH = YES
+
+# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
+# groups, showing the direct groups dependencies.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GROUP_GRAPHS = YES
+
+# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+UML_LOOK = NO
+
+# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
+# class node. If there are many fields or methods and many nodes the graph may
+# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the
+# number of items for each type to make the size more manageable. Set this to 0
+# for no limit. Note that the threshold may be exceeded by 50% before the limit
+# is enforced. So when you set the threshold to 10, up to 15 fields may appear,
+# but if the number exceeds 15, the total amount of fields shown is limited to
+# 10.
+# Minimum value: 0, maximum value: 100, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+UML_LIMIT_NUM_FIELDS = 10
+
+# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
+# collaboration graphs will show the relations between templates and their
+# instances.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+TEMPLATE_RELATIONS = NO
+
+# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
+# YES then doxygen will generate a graph for each documented file showing the
+# direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INCLUDE_GRAPH = YES
+
+# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
+# set to YES then doxygen will generate a graph for each documented file showing
+# the direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable call graphs for selected
+# functions only using the \callgraph command. Disabling a call graph can be
+# accomplished by means of the command \hidecallgraph.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CALL_GRAPH = NO
+
+# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable caller graphs for selected
+# functions only using the \callergraph command. Disabling a caller graph can be
+# accomplished by means of the command \hidecallergraph.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+CALLER_GRAPH = NO
+
+# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
+# hierarchy of all classes instead of a textual one.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GRAPHICAL_HIERARCHY = YES
+
+# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
+# dependencies a directory has on other directories in a graphical way. The
+# dependency relations are determined by the #include relations between the
+# files in the directories.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DIRECTORY_GRAPH = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. For an explanation of the image formats see the section
+# output formats in the documentation of the dot tool (Graphviz (see:
+# http://www.graphviz.org/)).
+# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
+# to make the SVG files visible in IE 9+ (other browsers do not have this
+# requirement).
+# Possible values are: png, png:cairo, png:cairo:cairo, png:cairo:gd, png:gd,
+# png:gd:gd, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd, gif, gif:cairo,
+# gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd, png:cairo,
+# png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and
+# png:gdiplus:gdiplus.
+# The default value is: png.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_IMAGE_FORMAT = png
+
+# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
+# enable generation of interactive SVG images that allow zooming and panning.
+#
+# Note that this requires a modern browser other than Internet Explorer. Tested
+# and working are Firefox, Chrome, Safari, and Opera.
+# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make
+# the SVG files visible. Older versions of IE do not have SVG support.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+INTERACTIVE_SVG = NO
+
+# The DOT_PATH tag can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the \dotfile
+# command).
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOTFILE_DIRS =
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the \mscfile
+# command).
+
+MSCFILE_DIRS =
+
+# The DIAFILE_DIRS tag can be used to specify one or more directories that
+# contain dia files that are included in the documentation (see the \diafile
+# command).
+
+DIAFILE_DIRS =
+
+# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
+# path where java can find the plantuml.jar file. If left blank, it is assumed
+# PlantUML is not used or called during a preprocessing step. Doxygen will
+# generate a warning when it encounters a \startuml command in this case and
+# will not generate output for the diagram.
+
+PLANTUML_JAR_PATH =
+
+# When using plantuml, the specified paths are searched for files specified by
+# the !include statement in a plantuml block.
+
+PLANTUML_INCLUDE_PATH =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
+# that will be shown in the graph. If the number of nodes in a graph becomes
+# larger than this value, doxygen will truncate the graph, which is visualized
+# by representing a node as a red box. Note that doxygen if the number of direct
+# children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that
+# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+# Minimum value: 0, maximum value: 10000, default value: 50.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_GRAPH_MAX_NODES = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
+# generated by dot. A depth value of 3 means that only nodes reachable from the
+# root by following a path via at most 3 edges will be shown. Nodes that lay
+# further from the root node will be omitted. Note that setting this option to 1
+# or 2 may greatly reduce the computation time needed for large code bases. Also
+# note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+# Minimum value: 0, maximum value: 1000, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+MAX_DOT_GRAPH_DEPTH = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not seem
+# to support this out of the box.
+#
+# Warning: Depending on the platform used, enabling this option may lead to
+# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
+# read).
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_TRANSPARENT = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10) support
+# this, this feature is disabled by default.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
+# explaining the meaning of the various boxes and arrows in the dot generated
+# graphs.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate dot
+# files that are used to generate the various graphs.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_CLEANUP = YES
diff --git a/extras/libmemif/examples/ExampleSetup.md b/extras/libmemif/examples/ExampleSetup.md
new file mode 100644
index 00000000000..a02506dd0ca
--- /dev/null
+++ b/extras/libmemif/examples/ExampleSetup.md
@@ -0,0 +1,206 @@
+## Example setup
+
+#### VPP-memif master icmp_responder slave
+
+> Libmemif example app(s) use memif default socket file: /run/vpp/memif.sock.
+
+Run VPP and icmpr-epoll example (default example when running in container).
+> Other examples work similar to icmpr-epoll. Brief explanation can be found in [Examples readme](README.md) file.
+
+VPP-side config:
+```
+DBGvpp# create memif id 0 master
+DBGvpp# set int state memif0/0 up
+DBGvpp# set int ip address memif0/0 192.168.1.1/24
+```
+icmpr-epoll:
+```
+conn 0 0
+```
+Memif in slave mode will try to connect every 2 seconds. If connection establishment is successfull, a message will show.
+```
+INFO: memif connected!
+```
+> Error messages like "unmatched interface id" are printed only in debug mode.
+
+Check connected status.
+Use show command in icmpr-epoll:
+```
+show
+MEMIF DETAILS
+==============================
+interface index: 0
+ interface ip: 192.168.1.2
+ interface name: memif_connection
+ app name: ICMP_Responder
+ remote interface name: memif0/0
+ remote app name: VPP 17.10-rc0~132-g62f9cdd
+ id: 0
+ secret:
+ role: slave
+ mode: ethernet
+ socket filename: /run/vpp/memif.sock
+ rx queues:
+ queue id: 0
+ ring size: 1024
+ buffer size: 2048
+ tx queues:
+ queue id: 0
+ ring size: 1024
+ buffer size: 2048
+ link: up
+interface index: 1
+ no connection
+
+```
+Use sh memif command in VPP:
+```
+DBGvpp# sh memif
+interface memif0/0
+ remote-name "ICMP_Responder"
+ remote-interface "memif_connection"
+ id 0 mode ethernet file /run/vpp/memif.sock
+ flags admin-up connected
+ listener-fd 12 conn-fd 13
+ num-s2m-rings 1 num-m2s-rings 1 buffer-size 0
+ master-to-slave ring 0:
+ region 0 offset 32896 ring-size 1024 int-fd 16
+ head 0 tail 0 flags 0x0000 interrupts 0
+ master-to-slave ring 0:
+ region 0 offset 0 ring-size 1024 int-fd 15
+ head 0 tail 0 flags 0x0001 interrupts 0
+```
+
+Send ping from VPP to icmpr-epoll:
+```
+DBGvpp# ping 192.168.1.2
+64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=.1888 ms
+64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=.1985 ms
+64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=.1813 ms
+64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=.1929 ms
+
+Statistics: 5 sent, 4 received, 20% packet loss
+```
+#### multiple queues VPP-memif slave icmp_responder master
+
+Run icmpr-epoll as in previous example setup.
+Run VPP with startup conf, enabling 2 worker threads.
+Example startup.conf:
+```
+unix {
+ interactive
+ nodaemon
+ full-coredump
+}
+
+cpu {
+ workers 2
+}
+```
+VPP-side config:
+```
+DBGvpp# create memif id 0 slave rx-queues 2 tx-queues 2
+DBGvpp# set int state memif0/0 up
+DBGvpp# set int ip address memif0/0 192.168.1.1/24
+```
+icmpr-epoll:
+```
+conn 0 1
+```
+When connection is established a message will print:
+```
+INFO: memif connected!
+```
+> Error messages like "unmatched interface id" are printed only in debug mode.
+
+Check connected status.
+Use show command in icmpr-epoll:
+```
+show
+MEMIF DETAILS
+==============================
+interface index: 0
+ interface ip: 192.168.1.2
+ interface name: memif_connection
+ app name: ICMP_Responder
+ remote interface name: memif0/0
+ remote app name: VPP 17.10-rc0~132-g62f9cdd
+ id: 0
+ secret:
+ role: master
+ mode: ethernet
+ socket filename: /run/vpp/memif.sock
+ rx queues:
+ queue id: 0
+ ring size: 1024
+ buffer size: 2048
+ queue id: 1
+ ring size: 1024
+ buffer size: 2048
+ tx queues:
+ queue id: 0
+ ring size: 1024
+ buffer size: 2048
+ queue id: 1
+ ring size: 1024
+ buffer size: 2048
+ link: up
+interface index: 1
+ no connection
+
+```
+Use sh memif command in VPP:
+```
+DBGvpp# sh memif
+interface memif0/0
+ remote-name "ICMP_Responder"
+ remote-interface "memif_connection"
+ id 0 mode ethernet file /run/vpp/memif.sock
+ flags admin-up slave connected
+ listener-fd -1 conn-fd 12
+ num-s2m-rings 2 num-m2s-rings 2 buffer-size 2048
+ slave-to-master ring 0:
+ region 0 offset 0 ring-size 1024 int-fd 14
+ head 0 tail 0 flags 0x0000 interrupts 0
+ slave-to-master ring 1:
+ region 0 offset 32896 ring-size 1024 int-fd 15
+ head 0 tail 0 flags 0x0000 interrupts 0
+ slave-to-master ring 0:
+ region 0 offset 65792 ring-size 1024 int-fd 16
+ head 0 tail 0 flags 0x0001 interrupts 0
+ slave-to-master ring 1:
+ region 0 offset 98688 ring-size 1024 int-fd 17
+ head 0 tail 0 flags 0x0001 interrupts 0
+
+```
+Send ping from VPP to icmpr-epoll:
+```
+DBGvpp# ping 192.168.1.2
+64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=.1439 ms
+64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=.2184 ms
+64 bytes from 192.168.1.2: icmp_seq=4 ttl=64 time=.1458 ms
+64 bytes from 192.168.1.2: icmp_seq=5 ttl=64 time=.1687 ms
+
+Statistics: 5 sent, 4 received, 20% packet loss
+```
+
+#### icmp_responder master icmp_responder slave
+
+> Example apps can only repond to ping. This setup creates connection between two applications using libmemif. Traffic functionality is the same as when connection to VPP. App can receive ARP/ICMP request and transmit response, but can not send ARP/ICMP request.
+
+Run two instances of icmpr-epoll example.
+> If not running in container, make sure folder /run/vpp/ exists before creating memif master.
+Instance 1 will be in master mode, instance 2 in slave mode.
+instance 1:
+```
+conn 0 1
+```
+instance 2:
+```
+conn 0 0
+```
+In 2 seconds, both instances should print connected! message:
+```
+INFO: memif connected!
+```
+Check peer interface names using show command.
diff --git a/extras/libmemif/examples/README.md b/extras/libmemif/examples/README.md
new file mode 100644
index 00000000000..bbd663b99e2
--- /dev/null
+++ b/extras/libmemif/examples/README.md
@@ -0,0 +1,16 @@
+## Examples
+
+After build, root folder will contain scripts linking binary examples with library (same name as example apps). These scripts can be executed to run example apps without installing the library. Example apps binaries can be found in _libs_ filder. To run binaries directly, make sure that libmemif library is installed.
+
+#### Run in container
+ligato/libmemif-sample-service image contains built and installed libmemf. To run different examples, override docker CMD to start container in bash:
+```
+# docker run -it --entrypoint=/bin/bash -i --rm --name icmp-responder --hostname icmp-responder --privileged -v "/run/vpp/:/run/vpp/" ligato/libmemif-sample-service
+```
+Current WORKDIR is set to root repository directory. Example apps can be run from this directory (a script linking binary with library), or browse to ./.libs folder and execute binary directly.
+
+Example app | Description
+------------|------------
+[icmpr](../examples/icmp_responder/main.c) | Simplest implementaion. Event polling is handled by libmemif. Single memif conenction in slave mode is created (id 0). Use Ctrl + C to exit app.
+[icmpr-epoll](../examples/icmp_responder-epoll/main.c) (run in container by default) | Supports multiple connections and master mode. User can create/delete connections, set ip addresses, print connection information. [Example setup](ExampleSetup.md) contains instructions on basic connection use cases setups.
+[icmpr-mt](../examples/icmp_responder-mt/main.c) | Multi-thread example, very similar to icmpr-epoll. Packets are handled in threads assigned to specific queues. Slave mode only.
diff --git a/extras/libmemif/examples/icmp_responder-epoll/main.c b/extras/libmemif/examples/icmp_responder-epoll/main.c
new file mode 100644
index 00000000000..4172785f0ef
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder-epoll/main.c
@@ -0,0 +1,791 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+#include <string.h>
+#include <sys/epoll.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <libmemif.h>
+#include <icmp_proto.h>
+
+#define APP_NAME "ICMP_Responder"
+#define IF_NAME "memif_connection"
+
+
+#ifdef ICMP_DBG
+#define DBG(...) do { \
+ printf (APP_NAME":%s:%d: ", __func__, __LINE__); \
+ printf (__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+#else
+#define DBG(...)
+#endif
+
+#define INFO(...) do { \
+ printf ("INFO: "__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+
+/* maximum tx/rx memif buffers */
+#define MAX_MEMIF_BUFS 256
+#define MAX_CONNS 50
+
+int epfd;
+
+typedef struct
+{
+ uint16_t index;
+ /* memif conenction handle */
+ memif_conn_handle_t conn;
+ /* 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;
+
+memif_connection_t memif_connection[MAX_CONNS];
+long ctx[MAX_CONNS];
+
+/* print details for all memif connections */
+static void
+print_memif_details ()
+{
+ memif_details_t md;
+ ssize_t buflen;
+ char *buf;
+ int err, i, e;
+ buflen = 2048;
+ buf = malloc (buflen);
+ printf ("MEMIF DETAILS\n");
+ printf ("==============================\n");
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+
+ memset (&md, 0, sizeof (md));
+ memset (buf, 0, buflen);
+
+ err = memif_get_details (c->conn, &md, buf, buflen);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ if (err != MEMIF_ERR_NOCONN)
+ INFO ("%s", memif_strerror (err));
+ continue;
+ }
+
+ printf ("interface index: %d\n", i);
+
+ printf ("\tinterface ip: %u.%u.%u.%u\n",
+ c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
+ printf ("\tinterface name: %s\n", (char *) md.if_name);
+ printf ("\tapp name: %s\n", (char *) md.inst_name);
+ printf ("\tremote interface name: %s\n", (char *) md.remote_if_name);
+ printf ("\tremote app name: %s\n", (char *) md.remote_inst_name);
+ printf ("\tid: %u\n", md.id);
+ printf ("\tsecret: %s\n", (char *) md.secret);
+ printf ("\trole: ");
+ if (md.role)
+ printf ("slave\n");
+ else
+ printf ("master\n");
+ printf ("\tmode: ");
+ switch (md.mode)
+ {
+ case 0:
+ printf ("ethernet\n");
+ break;
+ case 1:
+ printf ("ip\n");
+ break;
+ case 2:
+ printf ("punt/inject\n");
+ break;
+ default:
+ printf ("unknown\n");
+ break;
+ }
+ printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
+ printf ("\trx queues:\n");
+ for (e = 0; e < md.rx_queues_num; e++)
+ {
+ printf ("\t\tqueue id: %u\n", md.rx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.rx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.rx_queues[e].buffer_size);
+ }
+ printf ("\ttx queues:\n");
+ for (e = 0; e < md.tx_queues_num; e++)
+ {
+ printf ("\t\tqueue id: %u\n", md.tx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.tx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.tx_queues[e].buffer_size);
+ }
+ printf ("\tlink: ");
+ if (md.link_up_down)
+ printf ("up\n");
+ else
+ printf ("down\n");
+ }
+ free (buf);
+}
+
+int
+add_epoll_fd (int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (epfd, EPOLL_CTL_ADD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d added to epoll", fd);
+ return 0;
+}
+
+int
+mod_epoll_fd (int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (epfd, EPOLL_CTL_MOD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d moddified on epoll", fd);
+ return 0;
+}
+
+int
+del_epoll_fd (int fd)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ if (epoll_ctl (epfd, EPOLL_CTL_DEL, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d removed from epoll", fd);
+ return 0;
+}
+
+/* informs user about connected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_connect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif connected!");
+ return 0;
+}
+
+/* informs user about disconnected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_disconnect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif disconnected!");
+ return 0;
+}
+
+/* user needs to watch new fd or stop watching fd that is about to be closed.
+ control fd will be modified during connection establishment to minimize CPU usage */
+int
+control_fd_update (int fd, uint8_t events)
+{
+ /* convert memif event definitions to epoll events */
+ if (events & MEMIF_FD_EVENT_DEL)
+ return del_epoll_fd (fd);
+
+ uint32_t evt = 0;
+ if (events & MEMIF_FD_EVENT_READ)
+ evt |= EPOLLIN;
+ if (events & MEMIF_FD_EVENT_WRITE)
+ evt |= EPOLLOUT;
+
+ if (events & MEMIF_FD_EVENT_MOD)
+ return mod_epoll_fd (fd, evt);
+
+ return add_epoll_fd (fd, evt);
+}
+
+int
+icmpr_buffer_alloc (long index, long n, uint16_t qid)
+{
+ memif_connection_t *c = &memif_connection[index];
+ int err;
+ uint16_t r;
+ /* set data pointer to shared memory and set buffer_len to shared mmeory buffer len */
+ err = memif_buffer_alloc (c->conn, qid, c->tx_bufs, n, &r);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_buffer_alloc: %s", memif_strerror (err));
+ c->tx_buf_num += r;
+ return -1;
+ }
+ c->tx_buf_num += r;
+ DBG ("allocated %d/%ld buffers, %u free buffers", r, n,
+ MAX_MEMIF_BUFS - c->tx_buf_num);
+ return 0;
+}
+
+int
+icmpr_tx_burst (long index, uint16_t qid)
+{
+ memif_connection_t *c = &memif_connection[index];
+ int err;
+ uint16_t r;
+ /* inform peer memif interface about data in shared memory buffers */
+ /* mark memif buffers as free */
+ err = memif_tx_burst (c->conn, qid, c->tx_bufs, c->tx_buf_num, &r);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_tx_burst: %s", memif_strerror (err));
+ DBG ("tx: %d/%u", r, c->tx_buf_num);
+ c->tx_buf_num -= r;
+ return 0;
+}
+
+/* called when event is polled on interrupt file descriptor.
+ there are packets in shared memory ready to be received */
+int
+on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
+{
+ long index = *((long *) private_ctx);
+ memif_connection_t *c = &memif_connection[index];
+ if (c->index != index)
+ {
+ INFO ("invalid context: %ld/%u", index, c->index);
+ return 0;
+ }
+ int err;
+ uint16_t rx;
+ uint16_t fb;
+ /* receive data from shared memory buffers */
+ err = memif_rx_burst (c->conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &rx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_rx_burst: %s", memif_strerror (err));
+ c->rx_buf_num += rx;
+ goto error;
+ }
+ c->rx_buf_num += rx;
+
+ DBG ("received %d buffers. %u/%u alloc/free buffers",
+ rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+
+ if (icmpr_buffer_alloc (index, rx, qid) < 0)
+ {
+ INFO ("buffer_alloc error");
+ goto error;
+ }
+ int i;
+ for (i = 0; i < rx; i++)
+ {
+ resolve_packet ((void *) (c->rx_bufs + i)->data,
+ (c->rx_bufs + i)->data_len,
+ (void *) (c->tx_bufs + i)->data,
+ &(c->tx_bufs + i)->data_len, c->ip_addr);
+ }
+
+ /* mark memif buffers and shared memory buffers as free */
+ err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ c->rx_buf_num -= fb;
+
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+
+ icmpr_tx_burst (index, qid);
+
+ return 0;
+
+error:
+ err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ c->rx_buf_num -= fb;
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+ return 0;
+}
+
+int
+icmpr_memif_create (long index, long mode)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ /* setting memif connection arguments */
+ memif_conn_args_t args;
+ int fd = -1;
+ memset (&args, 0, sizeof (args));
+ args.is_master = mode;
+ args.log2_ring_size = 10;
+ args.buffer_size = 2048;
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+ strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
+ strncpy ((char *) args.instance_name, APP_NAME, strlen (APP_NAME));
+ args.mode = 0;
+ /* socket filename is not specified, because this app is supposed to
+ connect to VPP over memif. so default socket filename will be used */
+ /* default socketfile = /run/vpp/memif.sock */
+
+ args.interface_id = index;
+ /* last argument for memif_create (void * private_ctx) is used by user
+ to identify connection. this context is returned with callbacks */
+ int err = memif_create (&c->conn,
+ &args, on_connect, on_disconnect, on_interrupt,
+ &ctx[index]);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_create: %s", memif_strerror (err));
+ return 0;
+ }
+
+ c->index = index;
+ /* alloc memif buffers */
+ c->rx_buf_num = 0;
+ c->rx_bufs =
+ (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ c->tx_buf_num = 0;
+ c->tx_bufs =
+ (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+
+ c->ip_addr[0] = 192;
+ c->ip_addr[1] = 168;
+ c->ip_addr[2] = c->index + 1;
+ c->ip_addr[3] = 2;
+ return 0;
+}
+
+int
+icmpr_memif_delete (long index)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ if (c->rx_bufs)
+ free (c->rx_bufs);
+ c->rx_bufs = NULL;
+ c->rx_buf_num = 0;
+ if (c->tx_bufs)
+ free (c->tx_bufs);
+ c->tx_bufs = NULL;
+ c->tx_buf_num = 0;
+
+ int err;
+ /* disconenct then delete memif connection */
+ err = memif_delete (&c->conn);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+ if (c->conn != NULL)
+ INFO ("memif delete fail");
+ return 0;
+}
+
+void
+print_help ()
+{
+ printf ("LIBMEMIF EXAMPLE APP: %s", APP_NAME);
+#ifdef ICMP_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("==============================\n");
+ printf ("libmemif version: %s", LIBMEMIF_VERSION);
+#ifdef MEMIF_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("memif version: %d\n", MEMIF_VERSION);
+ printf ("commands:\n");
+ printf ("\thelp - prints this help\n");
+ printf ("\texit - exit app\n");
+ printf
+ ("\tconn <index> <mode> - create memif. index is also used as interface id, mode 0 = slave 1 = master\n");
+ printf ("\tdel <index> - delete memif\n");
+ printf ("\tshow - show connection details\n");
+ printf ("\tip-set <index> <ip-addr> - set interface ip address\n");
+ printf
+ ("\trx-mode <index> <qid> <polling|interrupt> - set queue rx mode\n");
+}
+
+int
+icmpr_free ()
+{
+ /* application cleanup */
+ int err;
+ long i;
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+ if (c->conn)
+ icmpr_memif_delete (i);
+ }
+
+ err = memif_cleanup ();
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+
+ return 0;
+}
+
+int
+icmpr_set_ip (long index, char *ip)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+ if (c->conn == NULL)
+ {
+ INFO ("no connection at index %ld", index);
+ return 0;
+ }
+
+ char *end;
+ char *ui;
+ uint8_t tmp[4];
+ ui = strtok (ip, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[0] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[1] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[2] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[3] = strtol (ui, &end, 10);
+
+ c->ip_addr[0] = tmp[0];
+ c->ip_addr[1] = tmp[1];
+ c->ip_addr[2] = tmp[2];
+ c->ip_addr[3] = tmp[3];
+
+ INFO ("memif %ld ip address set to %u.%u.%u.%u",
+ index, c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
+
+ return 0;
+
+error:
+ INFO ("invalid ip address");
+ return 0;
+}
+
+int
+icmpr_set_rx_mode (long index, long qid, char *mode)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ if (c->conn == NULL)
+ {
+ INFO ("no connection at index %ld", index);
+ return 0;
+ }
+
+ if (strncmp (mode, "interrupt", 9) == 0)
+ {
+ memif_set_rx_mode (c->conn, MEMIF_RX_MODE_INTERRUPT, qid);
+ }
+
+ else if (strncmp (mode, "polling", 7) == 0)
+ {
+ memif_set_rx_mode (c->conn, MEMIF_RX_MODE_POLLING, qid);
+ }
+ else
+ INFO ("expected rx mode <interrupt|polling>");
+ return 0;
+}
+
+int
+user_input_handler ()
+{
+ int i;
+ char *in = (char *) malloc (256);
+ char *ui = fgets (in, 256, stdin);
+ char *end;
+ long a;
+ if (in[0] == '\n')
+ goto done;
+ ui = strtok (in, " ");
+ if (strncmp (ui, "exit", 4) == 0)
+ {
+ free (in);
+ icmpr_free ();
+ exit (EXIT_SUCCESS);
+ }
+ else if (strncmp (ui, "help", 4) == 0)
+ {
+ print_help ();
+ goto done;
+ }
+ else if (strncmp (ui, "conn", 4) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ a = strtol (ui, &end, 10);
+ else
+ {
+ INFO ("expected id");
+ goto done;
+ }
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_memif_create (a, strtol (ui, &end, 10));
+ else
+ INFO ("expected mode <0|1>");
+ goto done;
+ }
+ else if (strncmp (ui, "del", 3) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_memif_delete (strtol (ui, &end, 10));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else if (strncmp (ui, "show", 4) == 0)
+ {
+ print_memif_details ();
+ goto done;
+ }
+ else if (strncmp (ui, "ip-set", 6) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_set_ip (strtol (ui, &end, 10), strtok (NULL, " "));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else if (strncmp (ui, "rx-mode", 7) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ a = strtol (ui, &end, 10);
+ else
+ {
+ INFO ("expected id");
+ goto done;
+ }
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_set_rx_mode (a, strtol (ui, &end, 10), strtok (NULL, " "));
+ else
+ INFO ("expected qid");
+ goto done;
+ }
+ else
+ {
+ DBG ("unknown command: %s", ui);
+ goto done;
+ }
+
+ return 0;
+done:
+ free (in);
+ return 0;
+}
+
+int
+poll_event (int timeout)
+{
+ struct epoll_event evt, *e;
+ int app_err = 0, memif_err = 0, en = 0;
+ int tmp, nfd;
+ uint32_t events = 0;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = EPOLLIN | EPOLLOUT;
+ sigset_t sigset;
+ sigemptyset (&sigset);
+ en = epoll_pwait (epfd, &evt, 1, timeout, &sigset);
+ if (en < 0)
+ {
+ DBG ("epoll_pwait: %s", strerror (errno));
+ return -1;
+ }
+ if (en > 0)
+ {
+ /* this app does not use any other file descriptors than stds and memif control fds */
+ if (evt.data.fd > 2)
+ {
+ /* event of memif control fd */
+ /* convert epolle events to memif events */
+ if (evt.events & EPOLLIN)
+ events |= MEMIF_FD_EVENT_READ;
+ if (evt.events & EPOLLOUT)
+ events |= MEMIF_FD_EVENT_WRITE;
+ if (evt.events & EPOLLERR)
+ events |= MEMIF_FD_EVENT_ERROR;
+ memif_err = memif_control_fd_handler (evt.data.fd, events);
+ if (memif_err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_control_fd_handler: %s", memif_strerror (memif_err));
+ }
+ else if (evt.data.fd == 0)
+ {
+ app_err = user_input_handler ();
+ }
+ else
+ {
+ DBG ("unexpected event at memif_epfd. fd %d", evt.data.fd);
+ }
+ }
+
+ if ((app_err < 0) || (memif_err < 0))
+ {
+ if (app_err < 0)
+ DBG ("user input handler error");
+ if (memif_err < 0)
+ DBG ("memif control fd handler error");
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+main ()
+{
+ epfd = epoll_create (1);
+ add_epoll_fd (0, EPOLLIN);
+
+ /* initialize memory interface */
+ int err, i;
+ /* if valid callback is passed as argument, fd event polling will be done by user
+ all file descriptors and events will be passed to user in this callback */
+ /* if callback is set to NULL libmemif will handle fd event polling */
+ err = memif_init (control_fd_update, APP_NAME);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_init: %s", memif_strerror (err));
+
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection[i].conn = NULL;
+ ctx[i] = i;
+ }
+
+ print_help ();
+
+ /* main loop */
+ while (1)
+ {
+ if (poll_event (-1) < 0)
+ {
+ DBG ("poll_event error!");
+ }
+ }
+}
diff --git a/extras/libmemif/examples/icmp_responder-mt/main.c b/extras/libmemif/examples/icmp_responder-mt/main.c
new file mode 100644
index 00000000000..860569bc20b
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder-mt/main.c
@@ -0,0 +1,921 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+#include <string.h>
+#include <sys/epoll.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+#include <pthread.h>
+
+#include <libmemif.h>
+#include <icmp_proto.h>
+
+#define APP_NAME "ICMP_Responder"
+#define IF_NAME "memif_connection"
+
+
+#ifdef ICMP_DBG
+#define DBG(...) do { \
+ printf (APP_NAME":%s:%d: ", __func__, __LINE__); \
+ printf (__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+#else
+#define DBG(...)
+#endif
+
+#define INFO(...) do { \
+ printf ("INFO: "__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+
+/* maximum tx/rx memif buffers */
+#define MAX_MEMIF_BUFS 256
+#define MAX_CONNS 50
+#define MAX_QUEUES 2
+#define MAX_THREADS ((MAX_CONNS) * (MAX_QUEUES))
+
+int main_epfd;
+
+typedef struct
+{
+ /* thread id */
+ uint8_t id;
+ /* memif connection index */
+ uint16_t index;
+ /* id of queue to be handled by thread */
+ uint8_t qid;
+ uint8_t isRunning;
+
+ uint16_t rx_buf_num;
+ uint16_t tx_buf_num;
+ memif_buffer_t *rx_bufs;
+ memif_buffer_t *tx_bufs;
+} memif_thread_data_t;
+
+typedef struct
+{
+ uint16_t index;
+ /* memif conenction handle */
+ memif_conn_handle_t conn;
+ /* interface ip address */
+ uint8_t ip_addr[4];
+ /* inform pthread about connection termination */
+ uint8_t pending_del;
+} memif_connection_t;
+
+memif_connection_t memif_connection[MAX_CONNS];
+long ctx[MAX_CONNS];
+
+/* thread data specific for each thread */
+memif_thread_data_t thread_data[MAX_THREADS];
+pthread_t thread[MAX_THREADS];
+
+void
+user_signal_handler (int sig)
+{
+ sig = sig;
+}
+
+static void
+print_memif_details ()
+{
+ memif_details_t md;
+ ssize_t buflen;
+ char *buf;
+ int err, i, e, ti;
+ buflen = 2048;
+ buf = malloc (buflen);
+ printf ("MEMIF DETAILS\n");
+ printf ("==============================\n");
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+
+ memset (&md, 0, sizeof (md));
+ memset (buf, 0, buflen);
+
+ err = memif_get_details (c->conn, &md, buf, buflen);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ if (err != MEMIF_ERR_NOCONN)
+ INFO ("%s", memif_strerror (err));
+ continue;
+ }
+
+ printf ("interface index: %d\n", i);
+
+ printf ("\tinterface ip: %u.%u.%u.%u\n",
+ c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
+ printf ("\tinterface name: %s\n", (char *) md.if_name);
+ printf ("\tapp name: %s\n", (char *) md.inst_name);
+ printf ("\tremote interface name: %s\n", (char *) md.remote_if_name);
+ printf ("\tremote app name: %s\n", (char *) md.remote_inst_name);
+ printf ("\tid: %u\n", md.id);
+ printf ("\tsecret: %s\n", (char *) md.secret);
+ printf ("\trole: ");
+ if (md.role)
+ printf ("slave\n");
+ else
+ printf ("master\n");
+ printf ("\tmode: ");
+ switch (md.mode)
+ {
+ case 0:
+ printf ("ethernet\n");
+ break;
+ case 1:
+ printf ("ip\n");
+ break;
+ case 2:
+ printf ("punt/inject\n");
+ break;
+ default:
+ printf ("unknown\n");
+ break;
+ }
+ printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
+ printf ("\trx queues:\n");
+ for (e = 0; e < md.rx_queues_num; e++)
+ {
+ ti = (i * MAX_QUEUES) + e;
+ printf ("\tqueue id: %u\n", md.rx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.rx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.rx_queues[e].buffer_size);
+ printf ("\t\tthread id: %u\n", thread_data[ti].id);
+ printf ("\t\tthread connection index: %u\n", thread_data[ti].index);
+ printf ("\t\tthread running: ");
+ if (thread_data[ti].isRunning)
+ printf ("yes\n");
+ else
+ printf ("no");
+ }
+ printf ("\ttx queues:\n");
+ for (e = 0; e < md.tx_queues_num; e++)
+ {
+ printf ("\tqueue id: %u\n", md.tx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.tx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.tx_queues[e].buffer_size);
+ }
+ printf ("\tlink: ");
+ if (md.link_up_down)
+ printf ("up\n");
+ else
+ printf ("down\n");
+ }
+ free (buf);
+}
+
+int
+add_epoll_fd (int epfd, int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (epfd, EPOLL_CTL_ADD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d added to epoll", fd);
+ return 0;
+}
+
+int
+mod_epoll_fd (int epfd, int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (epfd, EPOLL_CTL_MOD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d moddified on epoll", fd);
+ return 0;
+}
+
+int
+del_epoll_fd (int epfd, int fd)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ if (epoll_ctl (epfd, EPOLL_CTL_DEL, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d removed from epoll", fd);
+ return 0;
+}
+
+void *
+memif_rx_poll (void *ptr)
+{
+ memif_thread_data_t *data = (memif_thread_data_t *) ptr;
+ memif_connection_t *c = &memif_connection[data->index];
+ int err;
+ uint16_t rx = 0, tx = 0, fb = 0;
+
+ data->rx_bufs = malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ data->tx_bufs = malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ data->rx_buf_num = 0;
+ data->tx_buf_num = 0;
+
+ data->isRunning = 1;
+ INFO ("pthread id %u starts in polling mode", data->id);
+
+ while (1)
+ {
+ if (c->pending_del)
+ goto close;
+
+ /* receive data from shared memory buffers */
+ err =
+ memif_rx_burst (c->conn, data->qid, data->rx_bufs, MAX_MEMIF_BUFS,
+ &rx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_rx_burst: %s", memif_strerror (err));
+ data->rx_buf_num += rx;
+ goto error;
+ }
+ data->rx_buf_num += rx;
+ if (rx == 0)
+ {
+ continue;
+ }
+
+ DBG ("thread id: %u", data->id);
+
+ DBG ("received %d buffers. %u/%u alloc/free buffers",
+ rx, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+
+ err =
+ memif_buffer_alloc (c->conn, data->qid, data->tx_bufs,
+ data->rx_buf_num, &tx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_buffer_alloc: %s", memif_strerror (err));
+ data->tx_buf_num += tx;
+ goto error;
+ }
+ data->tx_buf_num += tx;
+ DBG ("allocated %d/%d buffers, %u free buffers",
+ tx, data->rx_buf_num, MAX_MEMIF_BUFS - data->tx_buf_num);
+
+ int i;
+ for (i = 0; i < rx; i++)
+ {
+ resolve_packet ((void *) (data->rx_bufs + i)->data,
+ (data->rx_bufs + i)->data_len,
+ (void *) (data->tx_bufs + i)->data,
+ &(data->tx_bufs + i)->data_len, c->ip_addr);
+ }
+
+ /* mark memif buffers and shared memory buffers as free */
+ err = memif_buffer_free (c->conn, data->qid, data->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ data->rx_buf_num -= fb;
+
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+
+ err =
+ memif_tx_burst (c->conn, data->qid, data->tx_bufs, data->tx_buf_num,
+ &tx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_tx_burst: %s", memif_strerror (err));
+ goto error;
+ }
+ DBG ("tx: %d/%u", tx, data->tx_buf_num);
+ data->tx_buf_num -= tx;
+ }
+
+error:
+ INFO ("thread %u error!", data->id);
+ goto close;
+
+close:
+ err = memif_buffer_free (c->conn, data->qid, data->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ data->rx_buf_num -= fb;
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+ free (data->rx_bufs);
+ free (data->tx_bufs);
+ data->isRunning = 0;
+ INFO ("pthread id %u exit", data->id);
+ pthread_exit (NULL);
+}
+
+void *
+memif_rx_interrupt (void *ptr)
+{
+ memif_thread_data_t *data = (memif_thread_data_t *) ptr;
+ memif_connection_t *c = &memif_connection[data->index];
+ int err;
+ uint16_t rx = 0, tx = 0, fb = 0;
+ struct epoll_event evt, *e;
+ int en = 0;
+ uint32_t events = 0;
+ sigset_t sigset;
+
+ signal (SIGUSR1, user_signal_handler);
+
+ data->rx_bufs = malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ data->tx_bufs = malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ data->rx_buf_num = 0;
+ data->tx_buf_num = 0;
+
+ data->isRunning = 1;
+ INFO ("pthread id %u starts in interrupt mode", data->id);
+ int thread_epfd = epoll_create (1);
+
+ /* get interrupt queue id */
+ int fd = -1;
+ err = memif_get_queue_efd (c->conn, data->qid, &fd);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_get_queue_efd: %s", memif_strerror (err));
+ goto error;
+ }
+ add_epoll_fd (thread_epfd, fd, EPOLLIN);
+
+ while (1)
+ {
+ memset (&evt, 0, sizeof (evt));
+ evt.events = EPOLLIN | EPOLLOUT;
+ sigemptyset (&sigset);
+ en = epoll_pwait (thread_epfd, &evt, 1, -1, &sigset);
+ if (en < 0)
+ {
+ if (errno == EINTR)
+ goto close;
+ DBG ("epoll_pwait: %s", strerror (errno));
+ goto error;
+ }
+ else if (en > 0)
+ {
+ /* receive data from shared memory buffers */
+ err =
+ memif_rx_burst (c->conn, data->qid, data->rx_bufs, MAX_MEMIF_BUFS,
+ &rx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_rx_burst: %s", memif_strerror (err));
+ data->rx_buf_num += rx;
+ goto error;
+ }
+ data->rx_buf_num += rx;
+ if (rx == 0)
+ {
+ continue;
+ }
+
+ DBG ("thread id: %u", data->id);
+
+ DBG ("received %d buffers. %u/%u alloc/free buffers",
+ rx, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+
+ err =
+ memif_buffer_alloc (c->conn, data->qid, data->tx_bufs,
+ data->rx_buf_num, &tx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_buffer_alloc: %s", memif_strerror (err));
+ data->tx_buf_num += tx;
+ goto error;
+ }
+ data->tx_buf_num += tx;
+ DBG ("allocated %d/%d buffers, %u free buffers",
+ tx, data->rx_buf_num, MAX_MEMIF_BUFS - data->tx_buf_num);
+
+ int i;
+ for (i = 0; i < rx; i++)
+ {
+ resolve_packet ((void *) (data->rx_bufs + i)->data,
+ (data->rx_bufs + i)->data_len,
+ (void *) (data->tx_bufs + i)->data,
+ &(data->tx_bufs + i)->data_len, c->ip_addr);
+ }
+
+ /* mark memif buffers and shared memory buffers as free */
+ err =
+ memif_buffer_free (c->conn, data->qid, data->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ data->rx_buf_num -= fb;
+
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+
+ err =
+ memif_tx_burst (c->conn, data->qid, data->tx_bufs,
+ data->tx_buf_num, &tx);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_tx_burst: %s", memif_strerror (err));
+ goto error;
+ }
+ DBG ("tx: %d/%u", tx, data->tx_buf_num);
+ data->tx_buf_num -= tx;
+ }
+ }
+
+error:
+ INFO ("thread %u error!", data->id);
+ goto close;
+
+close:
+ err = memif_buffer_free (c->conn, data->qid, data->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ data->rx_buf_num -= fb;
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, data->rx_buf_num, MAX_MEMIF_BUFS - data->rx_buf_num);
+ free (data->rx_bufs);
+ free (data->tx_bufs);
+ data->isRunning = 0;
+ INFO ("pthread id %u exit", data->id);
+ pthread_exit (NULL);
+
+}
+
+/* informs user about connected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_connect (memif_conn_handle_t conn, void *private_ctx)
+{
+ long index = (*(long *) private_ctx);
+ int err, i, ti;
+ INFO ("memif connected! index %ld", index);
+ memif_connection_t *c = &memif_connection[index];
+ c->pending_del = 0;
+
+ for (i = 0; i < MAX_QUEUES; i++)
+ {
+ err = memif_set_rx_mode (c->conn, MEMIF_RX_MODE_POLLING, i);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_set_rx_mode: %s qid: %u", memif_strerror (err), i);
+ else
+ {
+ ti = (index * MAX_QUEUES) + i;
+ if (thread_data[ti].isRunning)
+ {
+ INFO ("thread id: %d already running!", ti);
+ continue;
+ }
+ thread_data[ti].index = index;
+ thread_data[ti].qid = i;
+ thread_data[ti].id = ti;
+ if ((i % 2) == 0)
+ pthread_create (&thread[ti],
+ NULL, memif_rx_poll, (void *) &thread_data[ti]);
+ else
+ pthread_create (&thread[ti],
+ NULL, memif_rx_interrupt,
+ (void *) &thread_data[ti]);
+ }
+
+ }
+ return 0;
+}
+
+/* informs user about disconnected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_disconnect (memif_conn_handle_t conn, void *private_ctx)
+{
+ void *ptr;
+ long index = (*(long *) private_ctx);
+ memif_connection_t *c = &memif_connection[index];
+ int i, ti;
+ INFO ("memif disconnected!");
+ /* inform thread in polling mode about memif disconenction */
+ c->pending_del = 1;
+ for (i = 0; i < MAX_QUEUES; i++)
+ {
+ ti = (index * MAX_QUEUES) + i;
+ if (!thread_data[ti].isRunning)
+ continue;
+ if ((i % 2) != 0)
+ pthread_kill (thread[ti], SIGUSR1); /* interrupt thread in interrupt mode */
+ pthread_join (thread[ti], &ptr);
+ }
+ return 0;
+}
+
+/* user needs to watch new fd or stop watching fd that is about to be closed.
+ control fd will be modified during connection establishment to minimize CPU usage */
+int
+control_fd_update (int fd, uint8_t events)
+{
+ /* convert memif event definitions to epoll events */
+ if (events & MEMIF_FD_EVENT_DEL)
+ return del_epoll_fd (main_epfd, fd);
+
+ uint32_t evt = 0;
+ if (events & MEMIF_FD_EVENT_READ)
+ evt |= EPOLLIN;
+ if (events & MEMIF_FD_EVENT_WRITE)
+ evt |= EPOLLOUT;
+
+ if (events & MEMIF_FD_EVENT_MOD)
+ return mod_epoll_fd (main_epfd, fd, evt);
+
+ return add_epoll_fd (main_epfd, fd, evt);
+}
+
+int
+icmpr_memif_create (long index)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ /* setting memif connection arguments */
+ memif_conn_args_t args;
+ int fd = -1;
+ memset (&args, 0, sizeof (args));
+ args.is_master = 0;
+ args.log2_ring_size = 10;
+ args.buffer_size = 2048;
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+ strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
+ strncpy ((char *) args.instance_name, APP_NAME, strlen (APP_NAME));
+ args.mode = 0;
+ /* socket filename is not specified, because this app is supposed to
+ connect to VPP over memif. so default socket filename will be used */
+ /* default socketfile = /run/vpp/memif.sock */
+
+ args.interface_id = index;
+ /* last argument for memif_create (void * private_ctx) is used by user
+ to identify connection. this context is returned with callbacks */
+ int err = memif_create (&c->conn,
+ &args, on_connect, on_disconnect, NULL,
+ &ctx[index]);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_create: %s", memif_strerror (err));
+ return 0;
+ }
+
+ c->index = index;
+
+ c->ip_addr[0] = 192;
+ c->ip_addr[1] = 168;
+ c->ip_addr[2] = c->index + 1;
+ c->ip_addr[3] = 2;
+ return 0;
+}
+
+int
+icmpr_memif_delete (long index)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+
+ int err;
+ /* disconenct then delete memif connection */
+ err = memif_delete (&c->conn);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+ return 0;
+}
+
+void
+print_help ()
+{
+ printf ("LIBMEMIF EXAMPLE APP: %s", APP_NAME);
+#ifdef ICMP_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("==============================\n");
+ printf ("libmemif version: %s", LIBMEMIF_VERSION);
+#ifdef MEMIF_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("memif version: %d\n", MEMIF_VERSION);
+ printf ("commands:\n");
+ printf ("\thelp - prints this help\n");
+ printf ("\texit - exit app\n");
+ printf ("\tconn <index> - create memif (slave-mode)\n");
+ printf ("\tdel <index> - delete memif\n");
+ printf ("\tshow - show connection details\n");
+ printf ("\tip-set <index> <ip-addr> - set interface ip address\n");
+}
+
+int
+icmpr_free ()
+{
+ /* application cleanup */
+ int err;
+ long i;
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection_t *c = &memif_connection[i];
+ if (c->conn)
+ icmpr_memif_delete (i);
+ }
+
+ err = memif_cleanup ();
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+
+ return 0;
+}
+
+int
+icmpr_set_ip (long index, char *ip)
+{
+ if (index >= MAX_CONNS)
+ {
+ INFO ("connection array overflow");
+ return 0;
+ }
+ if (index < 0)
+ {
+ INFO ("don't even try...");
+ return 0;
+ }
+ memif_connection_t *c = &memif_connection[index];
+ if (c->conn == NULL)
+ {
+ INFO ("no connection at index %ld", index);
+ return 0;
+ }
+
+ char *end;
+ char *ui;
+ uint8_t tmp[4];
+ ui = strtok (ip, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[0] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[1] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[2] = strtol (ui, &end, 10);
+
+ ui = strtok (NULL, ".");
+ if (ui == NULL)
+ goto error;
+ tmp[3] = strtol (ui, &end, 10);
+
+ c->ip_addr[0] = tmp[0];
+ c->ip_addr[1] = tmp[1];
+ c->ip_addr[2] = tmp[2];
+ c->ip_addr[3] = tmp[3];
+
+ INFO ("memif %ld ip address set to %u.%u.%u.%u",
+ index, c->ip_addr[0], c->ip_addr[1], c->ip_addr[2], c->ip_addr[3]);
+
+ return 0;
+
+error:
+ INFO ("invalid ip address");
+ return 0;
+}
+
+
+int
+user_input_handler ()
+{
+ int i;
+ char *in = (char *) malloc (256);
+ char *ui = fgets (in, 256, stdin);
+ char *end;
+ if (in[0] == '\n')
+ goto done;
+ ui = strtok (in, " ");
+ if (strncmp (ui, "exit", 4) == 0)
+ {
+ free (in);
+ icmpr_free ();
+ exit (EXIT_SUCCESS);
+ }
+ else if (strncmp (ui, "help", 4) == 0)
+ {
+ print_help ();
+ goto done;
+ }
+ else if (strncmp (ui, "conn", 4) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_memif_create (strtol (ui, &end, 10));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else if (strncmp (ui, "del", 3) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_memif_delete (strtol (ui, &end, 10));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else if (strncmp (ui, "show", 4) == 0)
+ {
+ print_memif_details ();
+ goto done;
+ }
+ else if (strncmp (ui, "ip-set", 6) == 0)
+ {
+ ui = strtok (NULL, " ");
+ if (ui != NULL)
+ icmpr_set_ip (strtol (ui, &end, 10), strtok (NULL, " "));
+ else
+ INFO ("expected id");
+ goto done;
+ }
+ else
+ {
+ DBG ("unknown command: %s", ui);
+ goto done;
+ }
+
+ return 0;
+done:
+ free (in);
+ return 0;
+}
+
+int
+poll_event (int timeout)
+{
+ struct epoll_event evt, *e;
+ int app_err = 0, memif_err = 0, en = 0;
+ int tmp, nfd;
+ uint32_t events = 0;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = EPOLLIN | EPOLLOUT;
+ sigset_t sigset;
+ sigemptyset (&sigset);
+ en = epoll_pwait (main_epfd, &evt, 1, timeout, &sigset);
+ if (en < 0)
+ {
+ DBG ("epoll_pwait: %s", strerror (errno));
+ return -1;
+ }
+ if (en > 0)
+ {
+ /* this app does not use any other file descriptors than stds and memif control fds */
+ if (evt.data.fd > 2)
+ {
+ /* event of memif control fd */
+ /* convert epolle events to memif events */
+ if (evt.events & EPOLLIN)
+ events |= MEMIF_FD_EVENT_READ;
+ if (evt.events & EPOLLOUT)
+ events |= MEMIF_FD_EVENT_WRITE;
+ if (evt.events & EPOLLERR)
+ events |= MEMIF_FD_EVENT_ERROR;
+ memif_err = memif_control_fd_handler (evt.data.fd, events);
+ if (memif_err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_control_fd_handler: %s", memif_strerror (memif_err));
+ }
+ else if (evt.data.fd == 0)
+ {
+ app_err = user_input_handler ();
+ }
+ else
+ {
+ DBG ("unexpected event at memif_epfd. fd %d", evt.data.fd);
+ }
+ }
+
+ if ((app_err < 0) || (memif_err < 0))
+ {
+ if (app_err < 0)
+ DBG ("user input handler error");
+ if (memif_err < 0)
+ DBG ("memif control fd handler error");
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+main ()
+{
+ main_epfd = epoll_create (1);
+ add_epoll_fd (main_epfd, 0, EPOLLIN);
+
+ /* initialize memory interface */
+ int err, i;
+ /* if valid callback is passed as argument, fd event polling will be done by user
+ all file descriptors and events will be passed to user in this callback */
+ /* if callback is set to NULL libmemif will handle fd event polling */
+ err = memif_init (control_fd_update, APP_NAME);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_init: %s", memif_strerror (err));
+
+ for (i = 0; i < MAX_CONNS; i++)
+ {
+ memif_connection[i].conn = NULL;
+ ctx[i] = i;
+ }
+
+ memset (&thread_data, 0, sizeof (memif_thread_data_t) * MAX_THREADS);
+
+ print_help ();
+
+ /* main loop */
+ while (1)
+ {
+ if (poll_event (-1) < 0)
+ {
+ DBG ("poll_event error!");
+ }
+ }
+}
diff --git a/extras/libmemif/examples/icmp_responder/icmp_proto.c b/extras/libmemif/examples/icmp_responder/icmp_proto.c
new file mode 100644
index 00000000000..a923f209126
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder/icmp_proto.c
@@ -0,0 +1,246 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+
+#include <icmp_proto.h>
+
+static uint16_t
+cksum (void *addr, ssize_t len)
+{
+ char *data = (char *) addr;
+
+ uint32_t acc = 0xffff;
+
+ ssize_t i;
+ for (i = 0; (i + 1) < len; i += 2)
+ {
+ uint16_t word;
+ memcpy (&word, data + i, 2);
+ acc += ntohs (word);
+ if (acc > 0xffff)
+ acc -= 0xffff;
+ }
+
+ if (len & 1)
+ {
+ uint16_t word = 0;
+ memcpy (&word, data + len - 1, 1);
+ acc += ntohs (word);
+ if (acc > 0xffff)
+ acc -= 0xffff;
+ }
+ return htons (~acc);
+}
+
+int
+print_packet (void *pck)
+{
+ if (pck == NULL)
+ {
+ printf ("ICMP_PROTO: no data\n");
+ return -1;
+ }
+ struct iphdr *ip;
+ struct icmphdr *icmp;
+ ip = (struct iphdr *) pck;
+ icmp = (struct icmphdr *) (pck + sizeof (struct iphdr));
+ printf ("received packet:\n");
+ printf ("\tiphdr:\n");
+ printf ("\t\tihl: %u\n\t\tversion: %u\n\t\tlen: %u\n\t\tid: %u\n",
+ ip->ihl, ip->version, __bswap_16 (ip->tot_len), ip->id);
+ printf ("\t\tprotocol: %u\n", ip->protocol);
+
+ printf ("\t\tsaddr: ");
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ printf ("%u.", ((uint8_t *) & ip->saddr)[i]);
+ }
+ printf ("\n");
+
+ printf ("\t\tdaddr: ");
+ for (i = 0; i < 4; i++)
+ {
+ printf ("%u.", ((uint8_t *) & ip->daddr)[i]);
+ }
+ printf ("\n");
+ printf ("\ticmphdr:\n");
+ printf ("\t\ttype: %s\n",
+ (icmp->type == ICMP_ECHO) ? "ICMP_ECHO" : "ICMP_ECHOREPLY");
+
+ return 0;
+}
+
+static ssize_t
+resolve_arp (void *arp)
+{
+ struct arphdr *resp = (struct arphdr *) arp;
+
+ resp->ar_hrd = __bswap_16 (ARPHRD_ETHER);
+
+ resp->ar_pro = __bswap_16 (0x0800);
+
+ resp->ar_hln = 6;
+ resp->ar_pln = 4;
+
+ resp->ar_op = __bswap_16 (ARPOP_REPLY);
+
+ return sizeof (struct arphdr);
+}
+
+static ssize_t
+resolve_eth_arp (struct ether_arp *eth_arp, void *eth_arp_resp,
+ uint8_t ip_addr[4])
+{
+ struct ether_arp *resp = (struct ether_arp *) eth_arp_resp;
+
+ resolve_arp (&resp->ea_hdr);
+
+ memcpy (resp->arp_tha, eth_arp->arp_sha, 6);
+ memcpy (resp->arp_tpa, eth_arp->arp_spa, 4);
+
+ memcpy (resp->arp_sha,
+ (((struct ether_header *) (eth_arp_resp -
+ sizeof (struct ether_header)))->
+ ether_shost), 6);
+
+ memcpy (resp->arp_spa, ip_addr, 4);
+
+ return sizeof (struct ether_arp);
+}
+
+static ssize_t
+resolve_eth (struct ether_header *eth, void *eth_resp)
+{
+ struct ether_header *resp = (struct ether_header *) eth_resp;
+ memcpy (resp->ether_dhost, eth->ether_shost, 6);
+
+ uint8_t hw_addr[6];
+ int i;
+ for (i = 0; i < 6; i++)
+ {
+ hw_addr[i] = 'a';
+ }
+ memcpy (resp->ether_shost, hw_addr, 6);
+
+ resp->ether_type = eth->ether_type;
+
+ return sizeof (struct ether_header);
+}
+
+static ssize_t
+resolve_ip (struct iphdr *ip, void *ip_resp, uint8_t ip_addr[4])
+{
+ struct iphdr *resp = (struct iphdr *) ip_resp;
+ resp->ihl = 5;
+ resp->version = 4;
+ resp->tos = 0;
+ /*len updated later */
+ resp->tot_len = 0x5400;
+ resp->id = 0;
+ resp->frag_off = 0;
+ resp->ttl = 0x40;
+ resp->protocol = 1;
+ ((uint8_t *) & resp->saddr)[0] = ip_addr[0];
+ ((uint8_t *) & resp->saddr)[1] = ip_addr[1];
+ ((uint8_t *) & resp->saddr)[2] = ip_addr[2];
+ ((uint8_t *) & resp->saddr)[3] = ip_addr[3];
+ resp->daddr = ip->saddr;
+
+ resp->check = cksum (resp, sizeof (struct iphdr));
+
+ return sizeof (struct iphdr);
+}
+
+static ssize_t
+resolve_icmp (struct icmphdr *icmp, void *icmp_resp)
+{
+ struct icmphdr *resp = (struct icmphdr *) icmp_resp;
+ resp->type = ICMP_ECHOREPLY;
+ resp->code = 0;
+ resp->un.echo.id = icmp->un.echo.id;
+ resp->un.echo.sequence = icmp->un.echo.sequence;
+
+ /*resp->checksum = cksum (resp, sizeof (struct icmphdr)); */
+
+ return sizeof (struct icmphdr);
+}
+
+int
+resolve_packet (void *in_pck, ssize_t in_size,
+ void *out_pck, uint32_t * out_size, uint8_t ip_addr[4])
+{
+ struct ether_header *eh;
+ struct ether_arp *eah;
+ struct iphdr *ip;
+ struct icmphdr *icmp;
+ *out_size = 0;
+
+ eh = (struct ether_header *) in_pck;
+ *out_size = resolve_eth (eh, out_pck);
+
+ if (eh->ether_type == 0x0608)
+ {
+ eah = (struct ether_arp *) (in_pck + *out_size);
+ *out_size += resolve_eth_arp (eah, out_pck + *out_size, ip_addr);
+
+ }
+ else if (eh->ether_type == 0x0008)
+ {
+#ifdef ICMP_DBG
+ print_packet (in_pck + *out_size);
+#endif
+ ip = (struct iphdr *) (in_pck + *out_size);
+ *out_size += resolve_ip (ip, out_pck + *out_size, ip_addr);
+ if (ip->protocol == 1)
+ {
+ icmp = (struct icmphdr *) (in_pck + *out_size);
+ *out_size += resolve_icmp (icmp, out_pck + *out_size);
+ ((struct icmphdr *) (out_pck + *out_size -
+ sizeof (struct icmphdr)))->checksum =
+ cksum (out_pck + *out_size - sizeof (struct icmphdr),
+ sizeof (struct icmphdr));
+ /* payload */
+ memcpy (out_pck + *out_size, in_pck + *out_size,
+ in_size - *out_size);
+ *out_size = in_size;
+ }
+ }
+ return 0;
+}
diff --git a/extras/libmemif/examples/icmp_responder/icmp_proto.h b/extras/libmemif/examples/icmp_responder/icmp_proto.h
new file mode 100644
index 00000000000..f2f22ac4629
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder/icmp_proto.h
@@ -0,0 +1,26 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#ifndef _ICMP_PROTO_H_
+#define _ICMP_PROTO_H_
+
+int resolve_packet (void *in_pck, ssize_t in_size, void *out_pck,
+ uint32_t * out_size, uint8_t ip_addr[4]);
+
+int print_packet (void *pck);
+
+#endif /* _ICMP_PROTO_H_ */
diff --git a/extras/libmemif/examples/icmp_responder/main.c b/extras/libmemif/examples/icmp_responder/main.c
new file mode 100644
index 00000000000..5351b6b8e3c
--- /dev/null
+++ b/extras/libmemif/examples/icmp_responder/main.c
@@ -0,0 +1,416 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+#include <string.h>
+#include <sys/epoll.h>
+#include <errno.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <libmemif.h>
+#include <icmp_proto.h>
+
+#define APP_NAME "ICMP_Responder"
+#define IF_NAME "memif_connection"
+
+
+#ifdef ICMP_DBG
+#define DBG(...) do { \
+ printf (APP_NAME":%s:%d: ", __func__, __LINE__); \
+ printf (__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+#else
+#define DBG(...)
+#endif
+
+#define INFO(...) do { \
+ printf ("INFO: "__VA_ARGS__); \
+ printf ("\n"); \
+ } while (0)
+
+/* maximum tx/rx memif buffers */
+#define MAX_MEMIF_BUFS 256
+
+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;
+
+memif_connection_t memif_connection;
+int epfd;
+
+static void
+print_memif_details ()
+{
+ memif_connection_t *c = &memif_connection;
+ printf ("MEMIF DETAILS\n");
+ printf ("==============================\n");
+
+
+ memif_details_t md;
+ memset (&md, 0, sizeof (md));
+ ssize_t buflen = 2048;
+ char *buf = malloc (buflen);
+ memset (buf, 0, buflen);
+ int err, e;
+
+ err = memif_get_details (c->conn, &md, buf, buflen);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("%s", memif_strerror (err));
+ if (err == MEMIF_ERR_NOCONN)
+ {
+ free (buf);
+ return;
+ }
+ }
+
+ printf ("\tinterface name: %s\n", (char *) md.if_name);
+ printf ("\tapp name: %s\n", (char *) md.inst_name);
+ printf ("\tremote interface name: %s\n", (char *) md.remote_if_name);
+ printf ("\tremote app name: %s\n", (char *) md.remote_inst_name);
+ printf ("\tid: %u\n", md.id);
+ printf ("\tsecret: %s\n", (char *) md.secret);
+ printf ("\trole: ");
+ if (md.role)
+ printf ("slave\n");
+ else
+ printf ("master\n");
+ printf ("\tmode: ");
+ switch (md.mode)
+ {
+ case 0:
+ printf ("ethernet\n");
+ break;
+ case 1:
+ printf ("ip\n");
+ break;
+ case 2:
+ printf ("punt/inject\n");
+ break;
+ default:
+ printf ("unknown\n");
+ break;
+ }
+ printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
+ printf ("\tsocket filename: %s\n", (char *) md.socket_filename);
+ printf ("\trx queues:\n");
+ for (e = 0; e < md.rx_queues_num; e++)
+ {
+ printf ("\t\tqueue id: %u\n", md.rx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.rx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.rx_queues[e].buffer_size);
+ }
+ printf ("\ttx queues:\n");
+ for (e = 0; e < md.tx_queues_num; e++)
+ {
+ printf ("\t\tqueue id: %u\n", md.tx_queues[e].qid);
+ printf ("\t\tring size: %u\n", md.tx_queues[e].ring_size);
+ printf ("\t\tbuffer size: %u\n", md.tx_queues[e].buffer_size);
+ }
+ printf ("\tlink: ");
+ if (md.link_up_down)
+ printf ("up\n");
+ else
+ printf ("down\n");
+
+ free (buf);
+}
+
+/* informs user about connected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_connect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif connected!");
+ return 0;
+}
+
+/* informs user about disconnected status. private_ctx is used by user to identify connection
+ (multiple connections WIP) */
+int
+on_disconnect (memif_conn_handle_t conn, void *private_ctx)
+{
+ INFO ("memif disconnected!");
+ return 0;
+}
+
+int
+icmpr_memif_delete ()
+{
+ int err;
+ /* disconenct then delete memif connection */
+ err = memif_delete (&(&memif_connection)->conn);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+ return 0;
+}
+
+void
+print_help ()
+{
+ printf ("LIBMEMIF EXAMPLE APP: %s", APP_NAME);
+#ifdef ICMP_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("==============================\n");
+ printf ("libmemif version: %s", LIBMEMIF_VERSION);
+#ifdef MEMIF_DBG
+ printf (" (debug)");
+#endif
+ printf ("\n");
+ printf ("memif version: %d\n", MEMIF_VERSION);
+ printf ("\tuse CTRL+C to exit\n");
+}
+
+int
+icmpr_buffer_alloc (long n, uint16_t qid)
+{
+ memif_connection_t *c = &memif_connection;
+ int err;
+ uint16_t r;
+ /* set data pointer to shared memory and set buffer_len to shared mmeory buffer len */
+ err = memif_buffer_alloc (c->conn, qid, c->tx_bufs, n, &r);
+ if (err != MEMIF_ERR_SUCCESS)
+ {
+ INFO ("memif_buffer_alloc: %s", memif_strerror (err));
+ c->tx_buf_num += r;
+ return -1;
+ }
+ c->tx_buf_num += r;
+ DBG ("allocated %d/%ld buffers, %u free buffers", r, n,
+ MAX_MEMIF_BUFS - c->tx_buf_num);
+ return 0;
+}
+
+int
+icmpr_tx_burst (uint16_t qid)
+{
+ memif_connection_t *c = &memif_connection;
+ int err;
+ uint16_t r;
+ /* inform peer memif interface about data in shared memory buffers */
+ /* mark memif buffers as free */
+ err = memif_tx_burst (c->conn, qid, c->tx_bufs, c->tx_buf_num, &r);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_tx_burst: %s", memif_strerror (err));
+ DBG ("tx: %d/%u", r, c->tx_buf_num);
+ c->tx_buf_num -= r;
+ return 0;
+}
+
+int
+icmpr_free ()
+{
+ /* application cleanup */
+ int err;
+ memif_connection_t *c = &memif_connection;
+ free (c->tx_bufs);
+ c->tx_bufs = NULL;
+ free (c->rx_bufs);
+ c->rx_bufs = NULL;
+
+ err = memif_cleanup ();
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_delete: %s", memif_strerror (err));
+
+ return 0;
+}
+
+void
+icmpr_exit (int sig)
+{
+ printf ("\n");
+ icmpr_memif_delete ();
+ icmpr_free ();
+ exit (EXIT_SUCCESS);
+}
+
+/* called when event is polled on interrupt file descriptor.
+ there are packets in shared memory ready to be received */
+int
+on_interrupt (memif_conn_handle_t conn, void *private_ctx, uint16_t qid)
+{
+ DBG ("interrupted");
+ memif_connection_t *c = &memif_connection;
+ int err;
+ uint16_t rx;
+ /* receive data from shared memory buffers */
+ err = memif_rx_burst (c->conn, qid, c->rx_bufs, MAX_MEMIF_BUFS, &rx);
+ c->rx_buf_num += rx;
+
+ DBG ("received %d buffers. %u/%u alloc/free buffers",
+ rx, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+
+ if (icmpr_buffer_alloc (rx, c->tx_qid) < 0)
+ {
+ INFO ("buffer_alloc error");
+ goto error;
+ }
+ int i;
+ for (i = 0; i < rx; i++)
+ {
+ resolve_packet ((void *) (c->rx_bufs + i)->data,
+ (c->rx_bufs + i)->data_len,
+ (void *) (c->tx_bufs + i)->data,
+ &(c->tx_bufs + i)->data_len, c->ip_addr);
+ }
+
+ uint16_t fb;
+ /* mark memif buffers and shared memory buffers as free */
+ err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+ c->rx_buf_num -= fb;
+
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+
+ icmpr_tx_burst (c->tx_qid);
+
+ return 0;
+
+error:
+ err = memif_buffer_free (c->conn, qid, c->rx_bufs, rx, &fb);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_buffer_free: %s", memif_strerror (err));
+ c->rx_buf_num -= fb;
+ DBG ("freed %d buffers. %u/%u alloc/free buffers",
+ fb, c->rx_buf_num, MAX_MEMIF_BUFS - c->rx_buf_num);
+ return 0;
+}
+
+int
+icmpr_memif_create (int is_master)
+{
+ /* setting memif connection arguments */
+ memif_conn_args_t args;
+ int fd = -1;
+ memset (&args, 0, sizeof (args));
+ args.is_master = is_master;
+ args.log2_ring_size = 10;
+ args.buffer_size = 2048;
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+ strncpy ((char *) args.interface_name, IF_NAME, strlen (IF_NAME));
+ strncpy ((char *) args.instance_name, APP_NAME, strlen (APP_NAME));
+ args.mode = 0;
+ /* socket filename is not specified, because this app is supposed to
+ connect to VPP over memif. so default socket filename will be used */
+ /* default socketfile = /run/vpp/memif.sock */
+
+ args.interface_id = 0;
+ /* last argument for memif_create (void * private_ctx) is used by user
+ to identify connection. this context is returned with callbacks */
+ int err = memif_create (&(&memif_connection)->conn,
+ &args, on_connect, on_disconnect, on_interrupt,
+ NULL);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_create: %s", memif_strerror (err));
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ memif_connection_t *c = &memif_connection;
+
+ signal (SIGINT, icmpr_exit);
+
+ /* initialize global memif connection handle */
+ c->conn = NULL;
+ if (argc == 1)
+ c->tx_qid = 0;
+ else
+ {
+ char *end;
+ c->tx_qid = strtol (argv[1], &end, 10);
+ }
+ INFO ("tx qid: %u", c->tx_qid);
+ /* alloc memif buffers */
+ c->rx_buf_num = 0;
+ c->rx_bufs =
+ (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ c->tx_buf_num = 0;
+ c->tx_bufs =
+ (memif_buffer_t *) malloc (sizeof (memif_buffer_t) * MAX_MEMIF_BUFS);
+ c->ip_addr[0] = 192;
+ c->ip_addr[1] = 168;
+ c->ip_addr[2] = 1;
+ c->ip_addr[3] = 2;
+ /* initialize memory interface */
+ int err;
+ /* if valid callback is passed as argument, fd event polling will be done by user
+ all file descriptors and events will be passed to user in this callback */
+ /* if callback is set to NULL libmemif will handle fd event polling */
+ err = memif_init (NULL, APP_NAME);
+ if (err != MEMIF_ERR_SUCCESS)
+ INFO ("memif_init: %s", memif_strerror (err));
+
+ print_help ();
+
+ icmpr_memif_create (0);
+ print_memif_details ();
+
+ /* main loop */
+ while (1)
+ {
+ if (memif_poll_event (-1) < 0)
+ {
+ DBG ("poll_event error!");
+ }
+ }
+}
diff --git a/extras/libmemif/src/libmemif.h b/extras/libmemif/src/libmemif.h
new file mode 100644
index 00000000000..3732be688e6
--- /dev/null
+++ b/extras/libmemif/src/libmemif.h
@@ -0,0 +1,442 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+/** @file */
+
+#ifndef _LIBMEMIF_H_
+#define _LIBMEMIF_H_
+
+/** Libmemif version. */
+#define LIBMEMIF_VERSION "1.0"
+/** Default name of application using libmemif. */
+#define MEMIF_DEFAULT_APP_NAME "libmemif-app"
+
+#include <inttypes.h>
+
+#include <memif.h>
+
+/*! Error codes */
+typedef enum
+{
+ MEMIF_ERR_SUCCESS = 0, /*!< success */
+/* SYSCALL ERRORS */
+ MEMIF_ERR_SYSCALL, /*!< other syscall error */
+ MEMIF_ERR_ACCES, /*!< permission denied */
+ MEMIF_ERR_NO_FILE, /*!< file does not exist */
+ MEMIF_ERR_FILE_LIMIT, /*!< system open file limit */
+ MEMIF_ERR_PROC_FILE_LIMIT, /*!< process open file limit */
+ MEMIF_ERR_ALREADY, /*!< connection already requested */
+ MEMIF_ERR_AGAIN, /*!< fd is not socket, or operation would block */
+ MEMIF_ERR_BAD_FD, /*!< invalid fd */
+ MEMIF_ERR_NOMEM, /*!< out of memory */
+/* LIBMEMIF ERRORS */
+ MEMIF_ERR_INVAL_ARG, /*!< invalid argument */
+ MEMIF_ERR_NOCONN, /*!< handle points to no connection */
+ MEMIF_ERR_CONN, /*!< handle points to existing connection */
+ MEMIF_ERR_CB_FDUPDATE, /*!< user defined callback memif_control_fd_update_t error */
+ MEMIF_ERR_FILE_NOT_SOCK, /*!< file specified by socket filename
+ exists, but it's not socket */
+ MEMIF_ERR_NO_SHMFD, /*!< missing shm fd */
+ MEMIF_ERR_COOKIE, /*!< wrong cookie on ring */
+ MEMIF_ERR_NOBUF_RING, /*!< ring buffer full */
+ MEMIF_ERR_NOBUF, /*!< not enough memif buffers */
+ MEMIF_ERR_NOBUF_DET, /*!< memif details needs larger buffer */
+ MEMIF_ERR_INT_WRITE, /*!< send interrupt error */
+ MEMIF_ERR_MFMSG, /*!< malformed msg received */
+ MEMIF_ERR_QID, /*!< invalid queue id */
+/* MEMIF PROTO ERRORS */
+ MEMIF_ERR_PROTO, /*!< incompatible protocol version */
+ MEMIF_ERR_ID, /*!< unmatched interface id */
+ MEMIF_ERR_ACCSLAVE, /*!< slave cannot accept connection requests */
+ MEMIF_ERR_ALRCONN, /*!< memif is already connected */
+ MEMIF_ERR_MODE, /*!< mode mismatch */
+ MEMIF_ERR_SECRET, /*!< secret mismatch */
+ MEMIF_ERR_NOSECRET, /*!< secret required */
+ MEMIF_ERR_MAXREG, /*!< max region limit reached */
+ MEMIF_ERR_MAXRING, /*!< max ring limit reached */
+ MEMIF_ERR_NO_INTFD, /*!< missing interrupt fd */
+ MEMIF_ERR_DISCONNECT, /*!< disconenct received */
+ MEMIF_ERR_DISCONNECTED, /*!< peer interface disconnected */
+ MEMIF_ERR_UNKNOWN_MSG, /*!< unknown message type */
+} memif_err_t;
+
+/**
+ * @defgroup MEMIF_FD_EVENT Types of events that need to be watched for specific fd.
+ *
+ * @{
+ */
+
+/** user needs to set events that occured on fd and pass them to memif_control_fd_handler */
+#define MEMIF_FD_EVENT_READ (1 << 0)
+#define MEMIF_FD_EVENT_WRITE (1 << 1)
+/** inform libmemif that error occured on fd */
+#define MEMIF_FD_EVENT_ERROR (1 << 2)
+/** if set, informs that fd is going to be closed (user may want to stop watching for events on this fd) */
+#define MEMIF_FD_EVENT_DEL (1 << 3)
+/** update events */
+#define MEMIF_FD_EVENT_MOD (1 << 4)
+/** @} */
+
+/** *brief Memif connection handle
+ pointer of type void, pointing to internal structure
+*/
+typedef void *memif_conn_handle_t;
+/**
+ * @defgroup CALLBACKS Callback functions definitions
+ *
+ * @{
+ */
+
+/** \brief Memif control file descriptor update (callback function)
+ @param fd - new file descriptor to watch
+ @param events - event type(s) to watch for
+
+ This callback is called when there is new fd to watch for events on
+ or if fd is about to be closed (user mey want to stop watching for events on this fd).
+*/
+typedef int (memif_control_fd_update_t) (int fd, uint8_t events);
+
+/** \brief Memif connection status update (callback function)
+ @param conn - memif connection handle
+ @param private_ctx - private context
+
+ Informs user about connection status connected/disconnected.
+ On connected -> start watching for events on interrupt fd (optional).
+*/
+typedef int (memif_connection_update_t) (memif_conn_handle_t conn,
+ void *private_ctx);
+
+/** \brief Memif interrupt occured (callback function)
+ @param conn - memif connection handle
+ @param private_ctx - private context
+ @param qid - queue id on which interrupt occured
+
+ Called when event is received on interrupt fd.
+*/
+typedef int (memif_interrupt_t) (memif_conn_handle_t conn, void *private_ctx,
+ uint16_t qid);
+/** @} */
+
+/**
+ * @defgroup ARGS_N_BUFS Connection arguments and buffers
+ *
+ * @{
+ */
+
+/** \brief Memif connection arguments
+ @param socket_filename - socket filename
+ @param secret - otional parameter used as interface autenthication
+ @param num_s2m_rings - number of slave to master rings
+ @param num_m2s_rings - number of master to slave rings
+ @param buffer_size - size of buffer in shared memory
+ @param log2_ring_size - logarithm base 2 of ring size
+ @param is_master - 0 == master, 1 == slave
+ @param interface_id - id used to identify peer connection
+ @param interface_name - interface name
+ @param instance_name - application name
+ @param mode - 0 == ethernet, 1 == ip , 2 == punt/inject
+*/
+typedef struct
+{
+ uint8_t *socket_filename; /*!< default = /run/vpp/memif.sock */
+ uint8_t secret[24]; /*!< optional (interface authentication) */
+
+ uint8_t num_s2m_rings; /*!< default = 1 */
+ uint8_t num_m2s_rings; /*!< default = 1 */
+ uint16_t buffer_size; /*!< default = 2048 */
+ memif_log2_ring_size_t log2_ring_size; /*!< default = 10 (1024) */
+ uint8_t is_master;
+
+ memif_interface_id_t interface_id;
+ uint8_t interface_name[32];
+ uint8_t instance_name[32];
+ memif_interface_mode_t mode:8;
+} memif_conn_args_t;
+
+/*! memif receive mode */
+typedef enum
+{
+ MEMIF_RX_MODE_INTERRUPT = 0, /*!< interrupt mode */
+ MEMIF_RX_MODE_POLLING /*!< polling mode */
+} memif_rx_mode_t;
+
+/** \brief Memif buffer
+ @param desc_index - ring descriptor index
+ @param buffer_len - shared meory buffer length
+ @param data_len - data length
+ @param data - pointer to shared memory data
+*/
+typedef struct
+{
+ uint16_t desc_index;
+ uint32_t buffer_len;
+ uint32_t data_len;
+ void *data;
+} memif_buffer_t;
+/** @} */
+
+/**
+ * @defgroup MEMIF_DETAILS Memif details structs
+ *
+ * @{
+ */
+
+/** \brief Memif queue details
+ @param qid - queue id
+ @param ring_size - size of ring buffer in sharem memory
+ @param buffer_size - buffer size on sharem memory
+*/
+typedef struct
+{
+ uint8_t qid;
+ uint32_t ring_size;
+ uint16_t buffer_size;
+ /* add ring information */
+} memif_queue_details_t;
+
+/** \brief Memif details
+ @param if_name - interface name
+ @param inst_name - application name
+ @param remote_if_name - peer interface name
+ @param remote_inst_name - peer application name
+ @param id - connection id
+ @param secret - secret
+ @param role - 0 = master, 1 = slave
+ @param mode - 0 = ethernet, 1 = ip , 2 = punt/inject
+ @param socket_filename = socket filename
+ @param rx_queues_num - number of receive queues
+ @param tx_queues_num - number of transmit queues
+ @param rx_queues - struct containing receive queue details
+ @param tx_queues - struct containing transmit queue details
+ @param link_up_down - 1 = up (connected), 2 = down (disconnected)
+*/
+typedef struct
+{
+ uint8_t *if_name;
+ uint8_t *inst_name;
+ uint8_t *remote_if_name;
+ uint8_t *remote_inst_name;
+
+ uint32_t id;
+ uint8_t *secret; /* optional */
+ uint8_t role; /* 0 = master, 1 = slave */
+ uint8_t mode; /* 0 = ethernet, 1 = ip, 2 = punt/inject */
+ uint8_t *socket_filename;
+ uint8_t rx_queues_num;
+ uint8_t tx_queues_num;
+ memif_queue_details_t *rx_queues;
+ memif_queue_details_t *tx_queues;
+
+ uint8_t link_up_down; /* 1 = up, 0 = down */
+} memif_details_t;
+/** @} */
+
+/**
+ * @defgroup API_CALLS Api calls
+ *
+ * @{
+ */
+
+/** \biref Memif get queue event file descriptor
+ @param conn - memif connection handle
+ @param qid - queue id
+ @param[out] fd - returns event file descriptor
+
+ \return memif_err_t
+*/
+
+int memif_get_queue_efd (memif_conn_handle_t conn, uint16_t qid, int *fd);
+
+/** \brief Memif set rx mode
+ @param conn - memif connection handle
+ @param rx_mode - receive mode
+ @param qid - queue id
+
+ \return memif_err_t
+*/
+int memif_set_rx_mode (memif_conn_handle_t conn, memif_rx_mode_t rx_mode,
+ uint16_t qid);
+
+/** \brief Memif strerror
+ @param err_code - error code
+
+ Converts error code to error message.
+
+ \return Error string
+*/
+char *memif_strerror (int err_code);
+
+/** \brief Memif get details
+ @param conn - memif conenction handle
+ @param md - pointer to memif details struct
+ @param buf - buffer containing details strings
+ @param buflen - length of buffer
+
+ \return memif_err_t
+*/
+int memif_get_details (memif_conn_handle_t conn, memif_details_t * md,
+ char *buf, ssize_t buflen);
+
+/** \brief Memif initialization
+ @param on_control_fd_update - if control fd updates inform user to watch new fd
+ @param app_name - application name
+
+ if param on_control_fd_update is set to NULL,
+ libmemif will handle file descriptor event polling
+ if a valid callback is set, file descriptor event polling needs to be done by
+ user application, all file descriptors and event types will be passed in
+ this callback to user application
+
+ Initialize internal libmemif structures. Create timerfd (used to periodically request connection by
+ disconnected memifs in slave mode, with no additional API call). This fd is passed to user with memif_control_fd_update_t
+ timer is inactive at this state. It activates with if there is at least one memif in slave mode.
+
+ \return memif_err_t
+*/
+int memif_init (memif_control_fd_update_t * on_control_fd_update,
+ char *app_name);
+
+/** \brief Memif cleanup
+
+ Free libmemif internal allocations.
+
+ \return 0
+*/
+int memif_cleanup ();
+
+/** \brief Memory interface create function
+ @param conn - connection handle for user app
+ @param args - memory interface connection arguments
+ @param on_connect - inform user about connected status
+ @param on_disconnect - inform user about disconnected status
+ @param on_interrupt - informs user about interrupt, if set to null user will not be notified about interrupt, user can use memif_get_queue_efd call to get interrupt fd to poll for events
+ @param private_ctx - private contex passed back to user with callback
+
+ Creates memory interface.
+
+ SLAVE-MODE -
+ Start timer that will send events to timerfd. If this fd is passed to memif_control_fd_handler
+ every disconnected memif in slave mode will send connection request.
+ On success new fd is passed to user with memif_control_fd_update_t.
+
+ MASTER-MODE -
+ Create listener socket and pass fd to user with memif_cntrol_fd_update_t.
+ If this fd is passed to memif_control_fd_handler accept will be called and
+ new fd will be passed to user with memif_control_fd_update_t.
+
+
+ \return memif_err_t
+*/
+int memif_create (memif_conn_handle_t * conn, memif_conn_args_t * args,
+ memif_connection_update_t * on_connect,
+ memif_connection_update_t * on_disconnect,
+ memif_interrupt_t * on_interrupt, void *private_ctx);
+
+/** \brief Memif control file descriptor handler
+ @param fd - file descriptor on which the event occured
+ @param events - event type(s) that occured
+
+ If event occures on any control fd, call memif_control_fd_handler.
+ Internal - lib will "identify" fd (timerfd, lsitener, control) and handle event accordingly.
+
+ FD-TYPE -
+ TIMERFD -
+ Every disconnected memif in slave mode will request connection.
+ LISTENER or CONTROL -
+ Handle socket messaging (internal connection establishment).
+ INTERRUPT -
+ Call on_interrupt callback (if set).
+
+ \return memif_err_t
+
+*/
+int memif_control_fd_handler (int fd, uint8_t events);
+
+/** \brief Memif delete
+ @param conn - pointer to memif connection handle
+
+
+ disconnect session (free queues and regions, close file descriptors, unmap shared memory)
+ set connection handle to NULL, to avoid possible double free
+
+ \return memif_err_t
+*/
+int memif_delete (memif_conn_handle_t * conn);
+
+/** \brief Memif buffer alloc
+ @param conn - memif conenction handle
+ @param qid - number indentifying queue
+ @param bufs - memif buffers
+ @param count - number of memif buffers to allocate
+ @param count_out - returns number of allocated buffers
+
+ \return memif_err_t
+*/
+int memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count,
+ uint16_t * count_out);
+
+/** \brief Memif buffer free
+ @param conn - memif conenction handle
+ @param qid - number indentifying queue
+ @param bufs - memif buffers
+ @param count - number of memif buffers to free
+ @param count_out - returns number of freed buffers
+
+ \return memif_err_t
+*/
+int memif_buffer_free (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count,
+ uint16_t * count_out);
+
+/** \brief Memif transmit buffer burst
+ @param conn - memif conenction handle
+ @param qid - number indentifying queue
+ @param bufs - memif buffers
+ @param count - number of memif buffers to transmit
+ @param tx - returns number of transmitted buffers
+
+ \return memif_err_t
+*/
+int memif_tx_burst (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count, uint16_t * tx);
+
+/** \brief Memif receive buffer burst
+ @param conn - memif conenction handle
+ @param qid - number indentifying queue
+ @param bufs - memif buffers
+ @param count - number of memif buffers to receive
+ @param rx - returns number of received buffers
+
+ \return memif_err_t
+*/
+int memif_rx_burst (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count, uint16_t * rx);
+
+/** \brief Memif poll event
+ @param timeout - timeout in seconds
+
+ Passive event polling -
+ timeout = 0 - dont wait for event, check event queue if there is an event and return.
+ timeout = -1 - wait until event
+
+ \return memif_err_t
+*/
+int memif_poll_event (int timeout);
+/** @} */
+
+#endif /* _LIBMEMIF_H_ */
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
new file mode 100644
index 00000000000..d1b59eea8fe
--- /dev/null
+++ b/extras/libmemif/src/main.c
@@ -0,0 +1,1810 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#include <stdint.h>
+#include <net/if.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+#include <netdb.h>
+#include <linux/ip.h>
+#include <linux/icmp.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <asm/byteorder.h>
+#include <byteswap.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/eventfd.h>
+#include <sys/timerfd.h>
+#include <sys/epoll.h>
+#include <signal.h>
+
+/* memif protocol msg, ring and descriptor definitions */
+#include <memif.h>
+/* memif api */
+#include <libmemif.h>
+/* socket messaging functions */
+#include <socket.h>
+/* private structs and functions */
+#include <memif_private.h>
+
+#define ERRLIST_LEN 36
+#define MAX_ERRBUF_LEN 256
+
+#if __x86_x64__
+#define MEMIF_MEMORY_BARRIER() __builtin_ia32_sfence ()
+#else
+#define MEMIF_MEORY_BARRIER() __sync_synchronize ()
+#endif /* __x86_x64__ */
+
+libmemif_main_t libmemif_main;
+int memif_epfd;
+
+static char memif_buf[MAX_ERRBUF_LEN];
+
+const char *memif_errlist[ERRLIST_LEN] = { /* MEMIF_ERR_SUCCESS */
+ "Success.",
+ /* MEMIF_ERR_SYSCALL */
+ "Unspecified syscall error (build with -DMEMIF_DBG or make debug).",
+ /* MEMIF_ERR_ACCES */
+ "Permission to resoure denied.",
+ /* MEMIF_ERR_NO_FILE */
+ "Socket file does not exist",
+ /* MEMIF_ERR_FILE_LIMIT */
+ "System limit on total numer of open files reached.",
+ /* MEMIF_ERR_PROC_FILE_LIMIT */
+ "Per-process limit on total number of open files reached.",
+ /* MEMIF_ERR_ALREADY */
+ "Connection already requested.",
+ /* MEMIF_ERR_AGAIN */
+ "File descriptor refers to file other than socket, or operation would block.",
+ /* MEMIF_ERR_BAD_FD */
+ "Bad file descriptor.",
+ /* MEMIF_ERR_NOMEM */
+ "Out of memory.",
+ /* MEMIF_ERR_INVAL_ARG */
+ "Invalid argument.",
+ /* MEMIF_ERR_NOCONN */
+ "Memif connection handle does not point to existing conenction",
+ /* MEMIF_ERR_CONN */
+ "Memif connection handle points to existing connection",
+ /* MEMIF_ERR_CB_FDUPDATE */
+ "Callback memif_control_fd_update_t returned error",
+ /* MEMIF_ERR_FILE_NOT_SOCK */
+ "File specified by socket filename exists and is not socket.",
+ /* MEMIF_ERR_NO_SHMFD */
+ "Missing shared memory file descriptor. (internal error)",
+ /* MEMIF_ERR_COOKIE */
+ "Invalid cookie on ring. (internal error)",
+ /* MEMIF_ERR_NOBUF_RING */
+ "Ring buffer full.",
+ /* MEMIF_ERR_NOBUF */
+ "Not enough memif buffers. There are unreceived data in shared memory.",
+ /* MEMIF_ERR_NOBUF_DET */
+ "Not enough space for memif details in suplied buffer. String data might be malformed.",
+ /* MEMIF_ERR_INT_WRITE */
+ "Send interrupt error.",
+ /* MEMIF_ERR_MFMSG */
+ "Malformed message received on control channel.",
+ /* MEMIF_ERR_QID */
+ "Invalid queue id",
+ /* MEMIF_ERR_PROTO */
+ "Incompatible memory interface protocol version.",
+ /* MEMIF_ERR_ID */
+ "Unmatched interface id.",
+ /* MEMIF_ERR_ACCSLAVE */
+ "Slave cannot accept connection reqest.",
+ /* MEMIF_ERR_ALRCONN */
+ "Interface is already connected.",
+ /* MEMIF_ERR_MODE */
+ "Mode mismatch.",
+ /* MEMIF_ERR_SECRET */
+ "Secret mismatch.",
+ /* MEMIF_ERR_NOSECRET */
+ "Secret required.",
+ /* MEMIF_ERR_MAXREG */
+ "Limit on total number of regions reached.",
+ /* MEMIF_ERR_MAXRING */
+ "Limit on total number of ring reached.",
+ /* MEMIF_ERR_NO_INTFD */
+ "Missing interrupt file descriptor. (internal error)",
+ /* MEMIF_ERR_DISCONNECT */
+ "Interface received disconnect request.",
+ /* MEMIF_ERR_DISCONNECTED */
+ "Interface is disconnected.",
+ /* MEMIF_ERR_UNKNOWN_MSG */
+ "Unknown message type received on control channel. (internal error)"
+};
+
+#define MEMIF_ERR_UNDEFINED "undefined error"
+
+char *
+memif_strerror (int err_code)
+{
+ if (err_code >= ERRLIST_LEN)
+ {
+ strncpy (memif_buf, MEMIF_ERR_UNDEFINED, strlen (MEMIF_ERR_UNDEFINED));
+ memif_buf[strlen (MEMIF_ERR_UNDEFINED)] = '\0';
+ }
+ else
+ {
+ strncpy (memif_buf, memif_errlist[err_code],
+ strlen (memif_errlist[err_code]));
+ memif_buf[strlen (memif_errlist[err_code])] = '\0';
+ }
+ return memif_buf;
+}
+
+#define DBG_TX_BUF (0)
+#define DBG_RX_BUF (1)
+
+#ifdef MEMIF_DBG_SHM
+static void
+print_bytes (void *data, uint16_t len, uint8_t q)
+{
+ if (q == DBG_TX_BUF)
+ printf ("\nTX:\n\t");
+ else
+ printf ("\nRX:\n\t");
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ if (i % 8 == 0)
+ printf ("\n%d:\t", i);
+ printf ("%02X ", ((uint8_t *) (data))[i]);
+ }
+ printf ("\n\n");
+}
+#endif /* MEMIF_DBG */
+
+int
+memif_syscall_error_handler (int err_code)
+{
+ DBG_UNIX ("%s", strerror (err_code));
+
+ if (err_code == 0)
+ return MEMIF_ERR_SUCCESS;
+ if (err_code == EACCES)
+ return MEMIF_ERR_ACCES;
+ if (err_code == ENFILE)
+ return MEMIF_ERR_FILE_LIMIT;
+ if (err_code == EMFILE)
+ return MEMIF_ERR_PROC_FILE_LIMIT;
+ if (err_code == ENOMEM)
+ return MEMIF_ERR_NOMEM;
+/* connection refused if master dows not exist
+ this error would spam the user until master was created */
+ if (err_code == ECONNREFUSED)
+ return MEMIF_ERR_SUCCESS;
+ if (err_code == EALREADY)
+ return MEMIF_ERR_ALREADY;
+ if (err_code == EAGAIN)
+ return MEMIF_ERR_AGAIN;
+ if (err_code == EBADF)
+ return MEMIF_ERR_BAD_FD;
+ if (err_code == ENOENT)
+ return MEMIF_ERR_NO_FILE;
+
+ /* other syscall errors */
+ return MEMIF_ERR_SYSCALL;
+}
+
+static int
+memif_add_epoll_fd (int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (memif_epfd, EPOLL_CTL_ADD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d added to epoll", fd);
+ return 0;
+}
+
+static int
+memif_mod_epoll_fd (int fd, uint32_t events)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = events;
+ evt.data.fd = fd;
+ if (epoll_ctl (memif_epfd, EPOLL_CTL_MOD, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d moddified on epoll", fd);
+ return 0;
+}
+
+static int
+memif_del_epoll_fd (int fd)
+{
+ if (fd < 0)
+ {
+ DBG ("invalid fd %d", fd);
+ return -1;
+ }
+ struct epoll_event evt;
+ memset (&evt, 0, sizeof (evt));
+ if (epoll_ctl (memif_epfd, EPOLL_CTL_DEL, fd, &evt) < 0)
+ {
+ DBG ("epoll_ctl: %s fd %d", strerror (errno), fd);
+ return -1;
+ }
+ DBG ("fd %d removed from epoll", fd);
+ return 0;
+}
+
+int
+memif_control_fd_update (int fd, uint8_t events)
+{
+ if (events & MEMIF_FD_EVENT_DEL)
+ return memif_del_epoll_fd (fd);
+
+ uint32_t evt = 0;
+ if (events & MEMIF_FD_EVENT_READ)
+ evt |= EPOLLIN;
+ if (events & MEMIF_FD_EVENT_WRITE)
+ evt |= EPOLLOUT;
+
+ if (events & MEMIF_FD_EVENT_MOD)
+ return memif_mod_epoll_fd (fd, evt);
+
+ return memif_add_epoll_fd (fd, evt);
+}
+
+int
+add_list_elt (memif_list_elt_t * e, memif_list_elt_t ** list, uint16_t * len)
+{
+ libmemif_main_t *lm = &libmemif_main;
+
+ int i;
+ for (i = 0; i < *len; i++)
+ {
+ if ((*list)[i].data_struct == NULL)
+ {
+ (*list)[i].key = e->key;
+ (*list)[i].data_struct = e->data_struct;
+ return i;
+ }
+ }
+ memif_list_elt_t *tmp;
+ tmp = realloc (*list, sizeof (memif_list_elt_t) * *len * 2);
+ if (tmp == NULL)
+ return -1;
+
+ for (i = *len; i < *len * 2; i++)
+ {
+ tmp[i].key = -1;
+ tmp[i].data_struct = NULL;
+ }
+
+ tmp[*len].key = e->key;
+ tmp[*len].data_struct = e->data_struct;
+ i = *len;
+ *len = *len * 2;
+ *list = tmp;
+
+ return i;
+}
+
+int
+get_list_elt (memif_list_elt_t ** e, memif_list_elt_t * list, uint16_t len,
+ int key)
+{
+ if (key == -1)
+ {
+ *e = NULL;
+ return -1;
+ }
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ if (list[i].key == key)
+ {
+ *e = &list[i];
+ return 0;
+ }
+ }
+ *e = NULL;
+ return -1;
+}
+
+/* does not free memory, only marks element as free */
+int
+free_list_elt (memif_list_elt_t * list, uint16_t len, int key)
+{
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ if (list[i].key == key)
+ {
+ list[i].key = -1;
+ list[i].data_struct = NULL;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int
+free_list_elt_ctx (memif_list_elt_t * list, uint16_t len,
+ memif_connection_t * ctx)
+{
+ int i;
+ for (i = 0; i < len; i++)
+ {
+ if (list[i].key == -1)
+ {
+ if (list[i].data_struct == ctx)
+ {
+ list[i].data_struct = NULL;
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+static void
+memif_control_fd_update_register (memif_control_fd_update_t * cb)
+{
+ libmemif_main_t *lm = &libmemif_main;
+ lm->control_fd_update = cb;
+}
+
+int
+memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name)
+{
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+ libmemif_main_t *lm = &libmemif_main;
+
+ if (app_name)
+ {
+ lm->app_name = malloc (strlen (app_name) + sizeof (char));
+ memset (lm->app_name, 0, strlen (app_name) + sizeof (char));
+ strncpy ((char *) lm->app_name, app_name, strlen (app_name));
+ }
+ else
+ {
+ lm->app_name = malloc (strlen (MEMIF_DEFAULT_APP_NAME) + sizeof (char));
+ memset (lm->app_name, 0, strlen (app_name) + sizeof (char));
+ strncpy ((char *) lm->app_name, MEMIF_DEFAULT_APP_NAME,
+ strlen (MEMIF_DEFAULT_APP_NAME));
+ }
+
+ /* register control fd update callback */
+ if (on_control_fd_update != NULL)
+ memif_control_fd_update_register (on_control_fd_update);
+ else
+ {
+ memif_epfd = epoll_create (1);
+ memif_control_fd_update_register (memif_control_fd_update);
+ DBG ("libmemif event polling initialized");
+ }
+
+ memset (&lm->ms, 0, sizeof (memif_socket_t));
+
+ lm->control_list_len = 2;
+ lm->interrupt_list_len = 2;
+ lm->listener_list_len = 1;
+ lm->pending_list_len = 1;
+
+ lm->control_list =
+ malloc (sizeof (memif_list_elt_t) * lm->control_list_len);
+ lm->interrupt_list =
+ malloc (sizeof (memif_list_elt_t) * lm->interrupt_list_len);
+ lm->listener_list =
+ malloc (sizeof (memif_list_elt_t) * lm->listener_list_len);
+ lm->pending_list =
+ malloc (sizeof (memif_list_elt_t) * lm->pending_list_len);
+
+ int i;
+ for (i = 0; i < lm->control_list_len; i++)
+ {
+ lm->control_list[i].key = -1;
+ lm->control_list[i].data_struct = NULL;
+ }
+ for (i = 0; i < lm->interrupt_list_len; i++)
+ {
+ lm->interrupt_list[i].key = -1;
+ lm->interrupt_list[i].data_struct = NULL;
+ }
+ for (i = 0; i < lm->listener_list_len; i++)
+ {
+ lm->listener_list[i].key = -1;
+ lm->listener_list[i].data_struct = NULL;
+ }
+ for (i = 0; i < lm->pending_list_len; i++)
+ {
+ lm->pending_list[i].key = -1;
+ lm->pending_list[i].data_struct = NULL;
+ }
+
+ lm->disconn_slaves = 0;
+
+ lm->timerfd = timerfd_create (CLOCK_REALTIME, TFD_NONBLOCK);
+ if (lm->timerfd < 0)
+ {
+ err = errno;
+ DBG ("timerfd: %s", strerror (err));
+ return memif_syscall_error_handler (err);
+ }
+
+ lm->arm.it_value.tv_sec = 2;
+ lm->arm.it_value.tv_nsec = 0;
+ lm->arm.it_interval.tv_sec = 2;
+ lm->arm.it_interval.tv_nsec = 0;
+ memset (&lm->disarm, 0, sizeof (lm->disarm));
+
+ if (lm->control_fd_update (lm->timerfd, MEMIF_FD_EVENT_READ) < 0)
+ {
+ DBG ("callback type memif_control_fd_update_t error!");
+ return MEMIF_ERR_CB_FDUPDATE;
+ }
+
+ return 0;
+}
+
+static inline memif_ring_t *
+memif_get_ring (memif_connection_t * conn, memif_ring_type_t type,
+ uint16_t ring_num)
+{
+ if (&conn->regions[0] == NULL)
+ return NULL;
+ void *p = conn->regions[0].shm;
+ int ring_size =
+ sizeof (memif_ring_t) +
+ sizeof (memif_desc_t) * (1 << conn->run_args.log2_ring_size);
+ p += (ring_num + type * conn->run_args.num_s2m_rings) * ring_size;
+
+ return (memif_ring_t *) p;
+}
+
+int
+memif_set_rx_mode (memif_conn_handle_t c, memif_rx_mode_t rx_mode,
+ uint16_t qid)
+{
+ memif_connection_t *conn = (memif_connection_t *) c;
+ if (conn == NULL)
+ return MEMIF_ERR_NOCONN;
+ uint8_t num =
+ (conn->args.is_master) ? conn->run_args.num_s2m_rings : conn->run_args.
+ num_m2s_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+
+ conn->rx_queues[qid].ring->flags = rx_mode;
+ DBG ("rx_mode flag: %u", conn->rx_queues[qid].ring->flags);
+ return MEMIF_ERR_SUCCESS;
+}
+
+int
+memif_create (memif_conn_handle_t * c, memif_conn_args_t * args,
+ memif_connection_update_t * on_connect,
+ memif_connection_update_t * on_disconnect,
+ memif_interrupt_t * on_interrupt, void *private_ctx)
+{
+ int err, i, index, sockfd = -1;
+ memif_list_elt_t list_elt;
+ memif_connection_t *conn = (memif_connection_t *) * c;
+ if (conn != NULL)
+ {
+ DBG ("This handle already points to existing memif.");
+ return MEMIF_ERR_CONN;
+ }
+ conn = (memif_connection_t *) malloc (sizeof (memif_connection_t));
+ if (conn == NULL)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ memset (conn, 0, sizeof (memif_connection_t));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ conn->args.interface_id = args->interface_id;
+
+ if (args->log2_ring_size == 0)
+ args->log2_ring_size = MEMIF_DEFAULT_LOG2_RING_SIZE;
+ if (args->buffer_size == 0)
+ args->buffer_size = MEMIF_DEFAULT_BUFFER_SIZE;
+ if (args->num_s2m_rings == 0)
+ args->num_s2m_rings = MEMIF_DEFAULT_TX_QUEUES;
+ if (args->num_m2s_rings == 0)
+ args->num_m2s_rings = MEMIF_DEFAULT_RX_QUEUES;
+
+ conn->args.num_s2m_rings = args->num_s2m_rings;
+ conn->args.num_m2s_rings = args->num_m2s_rings;
+ conn->args.buffer_size = args->buffer_size;
+ conn->args.log2_ring_size = args->log2_ring_size;
+ conn->args.is_master = args->is_master;
+ conn->args.mode = args->mode;
+ conn->msg_queue = NULL;
+ conn->regions = NULL;
+ conn->tx_queues = NULL;
+ conn->rx_queues = NULL;
+ conn->fd = -1;
+ conn->on_connect = on_connect;
+ conn->on_disconnect = on_disconnect;
+ conn->on_interrupt = on_interrupt;
+ conn->private_ctx = private_ctx;
+ memset (&conn->run_args, 0, sizeof (memif_conn_run_args_t));
+
+ uint8_t l = strlen ((char *) args->interface_name);
+ strncpy ((char *) conn->args.interface_name, (char *) args->interface_name,
+ l);
+
+ l = strlen ((char *) args->instance_name);
+ strncpy ((char *) conn->args.instance_name, (char *) args->instance_name,
+ l);
+
+ /* allocate and initialize socket_filename so it can be copyed to sun_path
+ without memory leaks */
+ conn->args.socket_filename = malloc (sizeof (char *) * 108);
+ memset (conn->args.socket_filename, 0, 108 * sizeof (char *));
+
+ if (args->socket_filename)
+ {
+ if (conn->args.socket_filename == NULL)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ strncpy ((char *) conn->args.socket_filename,
+ (char *) args->socket_filename,
+ strlen ((char *) args->socket_filename));
+ }
+ else
+ {
+ uint16_t sdl = strlen (MEMIF_DEFAULT_SOCKET_DIR);
+ uint16_t sfl = strlen (MEMIF_DEFAULT_SOCKET_FILENAME);
+ if (conn->args.socket_filename == NULL)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ strncpy ((char *) conn->args.socket_filename,
+ MEMIF_DEFAULT_SOCKET_DIR, sdl);
+ conn->args.socket_filename[sdl] = '/';
+ strncpy ((char *) (conn->args.socket_filename + 1 + sdl),
+ MEMIF_DEFAULT_SOCKET_FILENAME, sfl);
+ }
+
+ if (args->secret)
+ {
+ l = strlen ((char *) args->secret);
+ strncpy ((char *) conn->args.secret, (char *) args->secret, l);
+ }
+
+ if (conn->args.is_master)
+ {
+ conn->run_args.buffer_size = conn->args.buffer_size;
+ memif_socket_t *ms;
+ memif_list_elt_t elt;
+ for (i = 0; i < lm->listener_list_len; i++)
+ {
+ if ((ms =
+ (memif_socket_t *) lm->listener_list[i].data_struct) != NULL)
+ {
+ if (strncmp
+ ((char *) ms->filename, (char *) conn->args.socket_filename,
+ strlen ((char *) ms->filename)) == 0)
+ {
+ /* add interface to listener socket */
+ elt.key = conn->args.interface_id;
+ *c = elt.data_struct = conn;
+ add_list_elt (&elt, &ms->interface_list,
+ &ms->interface_list_len);
+ ms->use_count++;
+ conn->listener_fd = ms->fd;
+ break;
+ }
+ }
+ else
+ {
+ struct stat file_stat;
+ if (stat ((char *) conn->args.socket_filename, &file_stat) == 0)
+ {
+ if (S_ISSOCK (file_stat.st_mode))
+ unlink ((char *) conn->args.socket_filename);
+ else
+ return memif_syscall_error_handler (errno);
+ }
+ DBG ("creating socket file");
+ ms = malloc (sizeof (memif_socket_t));
+ ms->filename = malloc (strlen ((char *) conn->args.
+ socket_filename) +
+ sizeof (char));
+ memset (ms->filename, 0,
+ strlen ((char *) conn->args.socket_filename) +
+ sizeof (char));
+ strncpy ((char *) ms->filename,
+ (char *) conn->args.socket_filename,
+ strlen ((char *) conn->args.socket_filename));
+ ms->interface_list_len = 1;
+ ms->interface_list =
+ malloc (sizeof (memif_list_elt_t) * ms->interface_list_len);
+ ms->interface_list[0].key = -1;
+ ms->interface_list[0].data_struct = NULL;
+ struct sockaddr_un un = { 0 };
+ int on = 1;
+
+ ms->fd = socket (AF_UNIX, SOCK_SEQPACKET, 0);
+ if (ms->fd < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ DBG ("socket %d created", ms->fd);
+ un.sun_family = AF_UNIX;
+ strncpy ((char *) un.sun_path, (char *) ms->filename,
+ sizeof (un.sun_path) - 1);
+ DBG ("sockopt");
+ if (setsockopt
+ (ms->fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on)) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ DBG ("bind");
+ if (bind (ms->fd, (struct sockaddr *) &un, sizeof (un)) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ DBG ("listen");
+ if (listen (ms->fd, 1) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ DBG ("stat");
+ if (stat ((char *) ms->filename, &file_stat) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+
+ /* add interface to listener socket */
+ elt.key = conn->args.interface_id;
+ *c = elt.data_struct = conn;
+ add_list_elt (&elt, &ms->interface_list,
+ &ms->interface_list_len);
+ ms->use_count = 1;
+ conn->listener_fd = ms->fd;
+
+ /* add listener socket to libmemif main */
+ elt.key = ms->fd;
+ elt.data_struct = ms;
+ add_list_elt (&elt, &lm->listener_list, &lm->listener_list_len);
+ lm->control_fd_update (ms->fd, MEMIF_FD_EVENT_READ);
+ break;
+ }
+ }
+ }
+ else
+ {
+ if (lm->disconn_slaves == 0)
+ {
+ if (timerfd_settime (lm->timerfd, 0, &lm->arm, NULL) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ }
+
+ lm->disconn_slaves++;
+
+ list_elt.key = -1;
+ *c = list_elt.data_struct = conn;
+ if ((index =
+ add_list_elt (&list_elt, &lm->control_list,
+ &lm->control_list_len)) < 0)
+ {
+ err = MEMIF_ERR_NOMEM;
+ goto error;
+ }
+ }
+
+ conn->index = index;
+
+ return 0;
+
+error:
+ if (sockfd > 0)
+ close (sockfd);
+ sockfd = -1;
+ if (conn->args.socket_filename)
+ free (conn->args.socket_filename);
+ if (conn != NULL)
+ free (conn);
+ *c = conn = NULL;
+ return err;
+}
+
+int
+memif_control_fd_handler (int fd, uint8_t events)
+{
+ int i, rv, sockfd = -1, err = MEMIF_ERR_SUCCESS; /* 0 */
+ uint16_t num;
+ memif_list_elt_t *e = NULL;
+ memif_connection_t *conn;
+ libmemif_main_t *lm = &libmemif_main;
+ if (fd == lm->timerfd)
+ {
+ uint64_t b;
+ ssize_t size;
+ size = read (fd, &b, sizeof (b));
+ for (i = 0; i < lm->control_list_len; i++)
+ {
+ if ((lm->control_list[i].key < 0)
+ && (lm->control_list[i].data_struct != NULL))
+ {
+ conn = lm->control_list[i].data_struct;
+ if (conn->args.is_master)
+ continue;
+
+ struct sockaddr_un sun;
+ sockfd = socket (AF_UNIX, SOCK_SEQPACKET, 0);
+ if (sockfd < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+
+ sun.sun_family = AF_UNIX;
+
+ strncpy (sun.sun_path, conn->args.socket_filename,
+ sizeof (sun.sun_path) - 1);
+
+ if (connect (sockfd, (struct sockaddr *) &sun,
+ sizeof (struct sockaddr_un)) == 0)
+ {
+ conn->fd = sockfd;
+ conn->read_fn = memif_conn_fd_read_ready;
+ conn->write_fn = memif_conn_fd_write_ready;
+ conn->error_fn = memif_conn_fd_error;
+
+ lm->control_list[conn->index].key = conn->fd;
+
+ lm->control_fd_update (sockfd,
+ MEMIF_FD_EVENT_READ |
+ MEMIF_FD_EVENT_WRITE);
+
+ lm->disconn_slaves--;
+ if (lm->disconn_slaves == 0)
+ {
+ if (timerfd_settime (lm->timerfd, 0, &lm->disarm, NULL)
+ < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ }
+ }
+ else
+ {
+ err = memif_syscall_error_handler (errno);
+ goto error;
+ }
+ }
+ }
+ }
+ else
+ {
+ get_list_elt (&e, lm->interrupt_list, lm->interrupt_list_len, fd);
+ if (e != NULL)
+ {
+ if (((memif_connection_t *) e->data_struct)->on_interrupt != NULL)
+ {
+ num =
+ (((memif_connection_t *) e->data_struct)->args.
+ is_master) ? ((memif_connection_t *) e->data_struct)->
+ run_args.num_s2m_rings : ((memif_connection_t *) e->
+ data_struct)->run_args.
+ num_m2s_rings;
+ for (i = 0; i < num; i++)
+ {
+ if (((memif_connection_t *) e->data_struct)->rx_queues[i].
+ int_fd == fd)
+ {
+ ((memif_connection_t *) e->data_struct)->on_interrupt ((void *) e->data_struct, ((memif_connection_t *) e->data_struct)->private_ctx, i);
+ return MEMIF_ERR_SUCCESS;
+ }
+ }
+ }
+ return MEMIF_ERR_SUCCESS;
+ }
+ get_list_elt (&e, lm->listener_list, lm->listener_list_len, fd);
+ if (e != NULL)
+ {
+ memif_conn_fd_accept_ready ((memif_socket_t *) e->data_struct);
+ return MEMIF_ERR_SUCCESS;
+ }
+
+ get_list_elt (&e, lm->pending_list, lm->pending_list_len, fd);
+ if (e != NULL)
+ {
+ memif_read_ready (fd);
+ return MEMIF_ERR_SUCCESS;
+ }
+
+ get_list_elt (&e, lm->control_list, lm->control_list_len, fd);
+ if (e != NULL)
+ {
+ if (events & MEMIF_FD_EVENT_READ)
+ {
+ err =
+ ((memif_connection_t *) e->data_struct)->read_fn (e->
+ data_struct);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ if (events & MEMIF_FD_EVENT_WRITE)
+ {
+ err =
+ ((memif_connection_t *) e->data_struct)->write_fn (e->
+ data_struct);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ if (events & MEMIF_FD_EVENT_ERROR)
+ {
+ err =
+ ((memif_connection_t *) e->data_struct)->error_fn (e->
+ data_struct);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ }
+ }
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+
+error:
+ if (sockfd > 0)
+ close (sockfd);
+ sockfd = -1;
+ return err;
+}
+
+int
+memif_poll_event (int timeout)
+{
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t *elt;
+ struct epoll_event evt, *e;
+ int en = 0, err = MEMIF_ERR_SUCCESS, i = 0; /* 0 */
+ uint16_t num;
+ uint32_t events = 0;
+ memset (&evt, 0, sizeof (evt));
+ evt.events = EPOLLIN | EPOLLOUT;
+ sigset_t sigset;
+ sigemptyset (&sigset);
+ en = epoll_pwait (memif_epfd, &evt, 1, timeout, &sigset);
+ if (en < 0)
+ {
+ DBG ("epoll_pwait: %s", strerror (errno));
+ return -1;
+ }
+ if (en > 0)
+ {
+ if (evt.events & EPOLLIN)
+ events |= MEMIF_FD_EVENT_READ;
+ if (evt.events & EPOLLOUT)
+ events |= MEMIF_FD_EVENT_WRITE;
+ if (evt.events & EPOLLERR)
+ events |= MEMIF_FD_EVENT_ERROR;
+ err = memif_control_fd_handler (evt.data.fd, events);
+ return err;
+ }
+ return 0;
+}
+
+static void
+memif_msg_queue_free (memif_msg_queue_elt_t ** e)
+{
+ if (*e == NULL)
+ return;
+ memif_msg_queue_free (&(*e)->next);
+ free (*e);
+ *e = NULL;
+ return;
+}
+
+/* send disconnect msg and close interface */
+int
+memif_disconnect_internal (memif_connection_t * c)
+{
+ if (c == NULL)
+ {
+ DBG ("no connection");
+ return MEMIF_ERR_NOCONN;
+ }
+ uint16_t num;
+ int err = MEMIF_ERR_SUCCESS, i; /* 0 */
+ memif_queue_t *mq;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t *e;
+
+ c->on_disconnect ((void *) c, c->private_ctx);
+
+ if (c->fd > 0)
+ {
+ memif_msg_send_disconnect (c->fd, "interface deleted", 0);
+ lm->control_fd_update (c->fd, MEMIF_FD_EVENT_DEL);
+ close (c->fd);
+ }
+ get_list_elt (&e, lm->control_list, lm->control_list_len, c->fd);
+ if (e != NULL)
+ {
+ if (c->args.is_master)
+ free_list_elt (lm->control_list, lm->control_list_len, c->fd);
+ e->key = c->fd = -1;
+ }
+
+ if (c->tx_queues != NULL)
+ {
+ num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+ for (i = 0; i < num; i++)
+ {
+ mq = &c->tx_queues[i];
+ if (mq != NULL)
+ {
+ if (mq->int_fd > 0)
+ close (mq->int_fd);
+ free_list_elt (lm->interrupt_list, lm->interrupt_list_len,
+ mq->int_fd);
+ mq->int_fd = -1;
+ }
+ }
+ free (c->tx_queues);
+ c->tx_queues = NULL;
+ }
+
+ if (c->rx_queues != NULL)
+ {
+ num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ for (i = 0; i < num; i++)
+ {
+ mq = &c->rx_queues[i];
+ if (mq != NULL)
+ {
+ if (mq->int_fd > 0)
+ {
+ if (c->on_interrupt != NULL)
+ lm->control_fd_update (mq->int_fd, MEMIF_FD_EVENT_DEL);
+ close (mq->int_fd);
+ }
+ free_list_elt (lm->interrupt_list, lm->interrupt_list_len,
+ mq->int_fd);
+ mq->int_fd = -1;
+ }
+ }
+ free (c->rx_queues);
+ c->rx_queues = NULL;
+ }
+
+ if (c->regions != NULL)
+ {
+ if (munmap (c->regions[0].shm, c->regions[0].region_size) < 0)
+ return memif_syscall_error_handler (errno);
+ if (c->regions[0].fd > 0)
+ close (c->regions[0].fd);
+ c->regions[0].fd = -1;
+ free (c->regions);
+ c->regions = NULL;
+ }
+
+ memset (&c->run_args, 0, sizeof (memif_conn_run_args_t));
+
+ memif_msg_queue_free (&c->msg_queue);
+
+ if (!(c->args.is_master))
+ {
+ if (lm->disconn_slaves == 0)
+ {
+ if (timerfd_settime (lm->timerfd, 0, &lm->arm, NULL) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ DBG_UNIX ("timerfd_settime: arm");
+ }
+ }
+ lm->disconn_slaves++;
+ }
+
+ return err;
+}
+
+int
+memif_delete (memif_conn_handle_t * conn)
+{
+ memif_connection_t *c = (memif_connection_t *) * conn;
+ if (c == NULL)
+ {
+ DBG ("no connection");
+ return MEMIF_ERR_NOCONN;
+ }
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t *e = NULL;
+ memif_socket_t *ms = NULL;
+
+ int err = MEMIF_ERR_SUCCESS;
+
+ if (c->fd > 0)
+ {
+ DBG ("DISCONNECTING");
+ err = memif_disconnect_internal (c);
+ if (err == MEMIF_ERR_NOCONN)
+ return err;
+ }
+
+ free_list_elt_ctx (lm->control_list, lm->control_list_len, c);
+
+ if (c->args.is_master)
+ {
+ get_list_elt (&e, lm->listener_list, lm->listener_list_len,
+ c->listener_fd);
+ if (e != NULL)
+ {
+ ms = (memif_socket_t *) e->data_struct;
+ ms->use_count--;
+ free_list_elt (ms->interface_list, ms->interface_list_len,
+ c->args.interface_id);
+ if (ms->use_count <= 0)
+ {
+ lm->control_fd_update (c->listener_fd, MEMIF_FD_EVENT_DEL);
+ free_list_elt (lm->listener_list, lm->listener_list_len,
+ c->listener_fd);
+ close (c->listener_fd);
+ c->listener_fd = ms->fd = -1;
+ free (ms->interface_list);
+ ms->interface_list = NULL;
+ free (ms->filename);
+ ms->filename = NULL;
+ free (ms);
+ ms = NULL;
+ }
+ }
+ }
+ else
+ {
+ lm->disconn_slaves--;
+ if (lm->disconn_slaves <= 0)
+ {
+ if (timerfd_settime (lm->timerfd, 0, &lm->disarm, NULL) < 0)
+ {
+ err = memif_syscall_error_handler (errno);
+ DBG ("timerfd_settime: disarm");
+ }
+ }
+ }
+
+ if (c->args.socket_filename)
+ free (c->args.socket_filename);
+ c->args.socket_filename = NULL;
+
+ free (c);
+ c = NULL;
+
+ *conn = c;
+ return err;
+}
+
+int
+memif_connect1 (memif_connection_t * c)
+{
+ libmemif_main_t *lm = &libmemif_main;
+ memif_region_t *mr = c->regions;
+ memif_queue_t *mq;
+ int i;
+ uint16_t num;
+
+ if (mr != NULL)
+ {
+ if (!mr->shm)
+ {
+ if (mr->fd < 0)
+ return MEMIF_ERR_NO_SHMFD;
+
+ if ((mr->shm = mmap (NULL, mr->region_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, mr->fd, 0)) == MAP_FAILED)
+ {
+ return memif_syscall_error_handler (errno);
+ }
+ }
+ }
+
+ num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+ for (i = 0; i < num; i++)
+ {
+ mq = &c->tx_queues[i];
+ if (mq != NULL)
+ {
+ mq->ring = c->regions[mq->region].shm + mq->offset;
+ if (mq->ring->cookie != MEMIF_COOKIE)
+ {
+ DBG ("wrong cookie on tx ring %u", i);
+ return MEMIF_ERR_COOKIE;
+ }
+ mq->ring->head = mq->ring->tail = mq->last_head = mq->alloc_bufs =
+ 0;
+ }
+ }
+ num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ for (i = 0; i < num; i++)
+ {
+ mq = &c->rx_queues[i];
+ if (mq != NULL)
+ {
+ mq->ring = c->regions[mq->region].shm + mq->offset;
+ if (mq->ring->cookie != MEMIF_COOKIE)
+ {
+ DBG ("wrong cookie on rx ring %u", i);
+ return MEMIF_ERR_COOKIE;
+ }
+ mq->ring->head = mq->ring->tail = mq->last_head = mq->alloc_bufs =
+ 0;
+ }
+ }
+
+ lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD);
+
+ return 0;
+}
+
+int
+memif_init_regions_and_queues (memif_connection_t * conn)
+{
+ memif_ring_t *ring = NULL;
+ uint64_t buffer_offset;
+ memif_region_t *r;
+ int i, j;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t e;
+
+ conn->regions = (memif_region_t *) malloc (sizeof (memif_region_t));
+ if (conn->regions == NULL)
+ return memif_syscall_error_handler (errno);
+ r = conn->regions;
+
+ buffer_offset =
+ (conn->run_args.num_s2m_rings +
+ conn->run_args.num_m2s_rings) * (sizeof (memif_ring_t) +
+ sizeof (memif_desc_t) *
+ (1 << conn->run_args.log2_ring_size));
+
+ r->region_size = buffer_offset +
+ conn->run_args.buffer_size * (1 << conn->run_args.log2_ring_size) *
+ (conn->run_args.num_s2m_rings + conn->run_args.num_m2s_rings);
+
+ if ((r->fd = memfd_create ("memif region 0", MFD_ALLOW_SEALING)) == -1)
+ return memif_syscall_error_handler (errno);
+/*
+ if ((fcntl (r->fd, F_ADD_SEALS, F_SEAL_SHRINK)) == -1)
+ return memif_syscall_error_handler (errno);
+*/
+ if ((ftruncate (r->fd, r->region_size)) == -1)
+ return memif_syscall_error_handler (errno);
+
+ if ((r->shm = mmap (NULL, r->region_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, r->fd, 0)) == MAP_FAILED)
+ return memif_syscall_error_handler (errno);
+
+ for (i = 0; i < conn->run_args.num_s2m_rings; i++)
+ {
+ ring = memif_get_ring (conn, MEMIF_RING_S2M, i);
+ DBG ("RING: %p I: %d", ring, i);
+ ring->head = ring->tail = 0;
+ ring->cookie = MEMIF_COOKIE;
+ ring->flags = 0;
+ for (j = 0; j < (1 << conn->run_args.log2_ring_size); j++)
+ {
+ uint16_t slot = i * (1 << conn->run_args.log2_ring_size) + j;
+ ring->desc[j].region = 0;
+ ring->desc[j].offset = buffer_offset +
+ (uint32_t) (slot * conn->run_args.buffer_size);
+ ring->desc[j].buffer_length = conn->run_args.buffer_size;
+ }
+ }
+ for (i = 0; i < conn->run_args.num_m2s_rings; i++)
+ {
+ ring = memif_get_ring (conn, MEMIF_RING_M2S, i);
+ DBG ("RING: %p I: %d", ring, i);
+ ring->head = ring->tail = 0;
+ ring->cookie = MEMIF_COOKIE;
+ ring->flags = 0;
+ for (j = 0; j < (1 << conn->run_args.log2_ring_size); j++)
+ {
+ uint16_t slot =
+ (i +
+ conn->run_args.num_s2m_rings) *
+ (1 << conn->run_args.log2_ring_size) + j;
+ ring->desc[j].region = 0;
+ ring->desc[j].offset = buffer_offset +
+ (uint32_t) (slot * conn->run_args.buffer_size);
+ ring->desc[j].buffer_length = conn->run_args.buffer_size;
+ }
+ }
+ memif_queue_t *mq;
+ mq =
+ (memif_queue_t *) malloc (sizeof (memif_queue_t) *
+ conn->run_args.num_s2m_rings);
+ if (mq == NULL)
+ return memif_syscall_error_handler (errno);
+ int x;
+ for (x = 0; x < conn->run_args.num_s2m_rings; x++)
+ {
+ if ((mq[x].int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
+ return memif_syscall_error_handler (errno);
+ /* add int fd to interrupt fd list */
+ e.key = mq[x].int_fd;
+ e.data_struct = conn;
+ add_list_elt (&e, &lm->interrupt_list, &lm->interrupt_list_len);
+
+ mq[x].ring = memif_get_ring (conn, MEMIF_RING_S2M, x);
+ DBG ("RING: %p I: %d", mq[x].ring, x);
+ mq[x].log2_ring_size = conn->run_args.log2_ring_size;
+ mq[x].region = 0;
+ mq[x].offset =
+ (void *) mq[x].ring - (void *) conn->regions[mq->region].shm;
+ mq[x].last_head = 0;
+ mq[x].alloc_bufs = 0;
+ }
+ conn->tx_queues = mq;
+
+ mq =
+ (memif_queue_t *) malloc (sizeof (memif_queue_t) *
+ conn->run_args.num_m2s_rings);
+ if (mq == NULL)
+ return memif_syscall_error_handler (errno);
+ for (x = 0; x < conn->run_args.num_m2s_rings; x++)
+ {
+ if ((mq[x].int_fd = eventfd (0, EFD_NONBLOCK)) < 0)
+ return memif_syscall_error_handler (errno);
+ /* add int fd to interrupt fd list */
+ e.key = mq[x].int_fd;
+ e.data_struct = conn;
+ add_list_elt (&e, &lm->interrupt_list, &lm->interrupt_list_len);
+
+ mq[x].ring = memif_get_ring (conn, MEMIF_RING_M2S, x);
+ DBG ("RING: %p I: %d", mq[x].ring, x);
+ mq[x].log2_ring_size = conn->run_args.log2_ring_size;
+ mq[x].region = 0;
+ mq[x].offset =
+ (void *) mq[x].ring - (void *) conn->regions[mq->region].shm;
+ mq[x].last_head = 0;
+ mq[x].alloc_bufs = 0;
+ }
+ conn->rx_queues = mq;
+
+ return 0;
+}
+
+int
+memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count,
+ uint16_t * count_out)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+ memif_queue_t *mq = &c->tx_queues[qid];
+ memif_ring_t *ring = mq->ring;
+ memif_buffer_t *b0, *b1;
+ uint16_t mask = (1 << mq->log2_ring_size) - 1;
+ uint16_t s0, s1, ns;
+ *count_out = 0;
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+
+ if (ring->tail != ring->head)
+ {
+ if (ring->head > ring->tail)
+ ns = (1 << mq->log2_ring_size) - ring->head + ring->tail;
+ else
+ ns = ring->tail - ring->head;
+ }
+ else
+ ns = (1 << mq->log2_ring_size);
+
+ /* (head == tail) ? receive function will asume that no packets are available */
+ ns -= 1;
+
+ while (count && ns)
+ {
+ while ((count > 2) && (ns > 2))
+ {
+ s0 = (ring->head + mq->alloc_bufs + *count_out) & mask;
+ s1 = (ring->head + mq->alloc_bufs + *count_out + 1) & mask;
+
+ b0 = (bufs + *count_out);
+ b1 = (bufs + *count_out + 1);
+
+ b0->desc_index = s0;
+ b1->desc_index = s1;
+ b0->buffer_len = ring->desc[s0].buffer_length;
+ b1->buffer_len = ring->desc[s1].buffer_length;
+ /* TODO: support multiple regions -> ring descriptor contains region index */
+ b0->data = c->regions->shm + ring->desc[s0].offset;
+ b1->data = c->regions->shm + ring->desc[s1].offset;
+
+ DBG ("allocated ring slots %u, %u", s0, s1);
+ count -= 2;
+ ns -= 2;
+ *count_out += 2;
+ }
+ s0 = (ring->head + mq->alloc_bufs + *count_out) & mask;
+
+ b0 = (bufs + *count_out);
+
+ b0->desc_index = s0;
+ b0->buffer_len = ring->desc[s0].buffer_length;
+ b0->data = c->regions->shm + ring->desc[s0].offset;
+
+ DBG ("allocated ring slot %u", s0);
+ count--;
+ ns--;
+ *count_out += 1;
+ }
+
+ mq->alloc_bufs += *count_out;
+ DBG ("allocated: %u/%u bufs. Total %u allocated bufs", *count_out, count,
+ mq->alloc_bufs);
+
+ if (count)
+ {
+ DBG ("ring buffer full! qid: %u", qid);
+ err = MEMIF_ERR_NOBUF_RING;
+ }
+
+ return err;
+}
+
+int
+memif_buffer_free (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count,
+ uint16_t * count_out)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_queue_t *mq = &c->rx_queues[qid];
+ memif_ring_t *ring = mq->ring;
+ uint16_t tail = ring->tail;
+ uint16_t mask = (1 << mq->log2_ring_size) - 1;
+ memif_buffer_t *b0, *b1;
+ *count_out = 0;
+
+ if (mq->alloc_bufs < count)
+ count = mq->alloc_bufs;
+
+ while (count)
+ {
+ while (count > 2)
+ {
+ b0 = (bufs + *count_out);
+ b1 = (bufs + *count_out + 1);
+ tail = (b0->desc_index + 1) & mask;
+ tail = (b1->desc_index + 1) & mask;
+ b0->data = NULL;
+ b1->data = NULL;
+
+ count -= 2;
+ *count_out += 2;
+ mq->alloc_bufs -= 2;
+ }
+ b0 = (bufs + *count_out);
+ tail = (b0->desc_index + 1) & mask;
+ b0->data = NULL;
+
+ count--;
+ *count_out += 1;
+ mq->alloc_bufs--;
+ }
+ MEMIF_MEORY_BARRIER ();
+ ring->tail = tail;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+int
+memif_tx_burst (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count, uint16_t * tx)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+ memif_queue_t *mq = &c->tx_queues[qid];
+ memif_ring_t *ring = mq->ring;
+ uint16_t head = ring->head;
+ uint16_t mask = (1 << mq->log2_ring_size) - 1;
+ *tx = 0;
+ memif_buffer_t *b0, *b1;
+
+ while (count)
+ {
+ while (count > 2)
+ {
+ b0 = (bufs + *tx);
+ b1 = (bufs + *tx + 1);
+ ring->desc[b0->desc_index].length = b0->data_len;
+ ring->desc[b1->desc_index].length = b1->data_len;
+
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data, b0->data_len, DBG_TX_BUF);
+ print_bytes (b1->data, b1->data_len, DBG_TX_BUF);
+#endif
+
+ head = (b0->desc_index + 1) & mask;
+ head = (b1->desc_index + 1) & mask;
+
+ b0->data = NULL;
+ b0->data_len = 0;
+ b1->data = NULL;
+ b1->data_len = 0;
+
+ count -= 2;
+ *tx += 2;
+ }
+
+ b0 = (bufs + *tx);
+ ring->desc[b0->desc_index].length = b0->data_len;
+
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data, b0->data_len, DBG_TX_BUF);
+#endif
+
+ head = (b0->desc_index + 1) & mask;
+
+ b0->data = NULL;
+ b0->data_len = 0;
+
+ count--;
+ *tx += 1;
+ }
+ MEMIF_MEORY_BARRIER ();
+ ring->head = head;
+
+ mq->alloc_bufs -= *tx;
+
+ if ((ring->flags & MEMIF_RING_FLAG_MASK_INT) == 0)
+ {
+ uint64_t a = 1;
+ int r = write (mq->int_fd, &a, sizeof (a));
+ if (r < 0)
+ return MEMIF_ERR_INT_WRITE;
+ }
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+int
+memif_rx_burst (memif_conn_handle_t conn, uint16_t qid,
+ memif_buffer_t * bufs, uint16_t count, uint16_t * rx)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+ memif_queue_t *mq = &c->rx_queues[qid];
+ memif_ring_t *ring = mq->ring;
+ uint16_t head = ring->head;
+ uint16_t ns;
+ uint16_t mask = (1 << mq->log2_ring_size) - 1;
+ memif_buffer_t *b0, *b1;
+ *rx = 0;
+
+ uint64_t b;
+ ssize_t r = read (mq->int_fd, &b, sizeof (b));
+ if ((r == -1) && (errno != EAGAIN))
+ return memif_syscall_error_handler (errno);
+
+ if (head == mq->last_head)
+ return 0;
+
+ if (head > mq->last_head)
+ ns = head - mq->last_head;
+ else
+ ns = (1 << mq->log2_ring_size) - mq->last_head + head;
+
+ while (ns && count)
+ {
+ while ((ns > 2) && (count > 2))
+ {
+ b0 = (bufs + *rx);
+ b1 = (bufs + *rx + 1);
+
+ b0->desc_index = mq->last_head;
+ b1->desc_index = mq->last_head + 1;
+ b0->data = memif_get_buffer (conn, ring, mq->last_head);
+ b1->data = memif_get_buffer (conn, ring, mq->last_head + 1);
+ b0->data_len = ring->desc[mq->last_head].length;
+ b1->data_len = ring->desc[mq->last_head + 1].length;
+ b0->buffer_len = ring->desc[mq->last_head].buffer_length;
+ b1->buffer_len = ring->desc[mq->last_head + 1].buffer_length;
+
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data, b0->data_len, DBG_RX_BUF);
+ print_bytes (b1->data, b1->data_len, DBG_RX_BUF);
+#endif
+
+ mq->last_head = (mq->last_head + 2) & mask;
+
+ ns -= 2;
+ count -= 2;
+ *rx += 2;
+ }
+ b0 = (bufs + *rx);
+
+ b0->desc_index = mq->last_head;
+ b0->data = memif_get_buffer (conn, ring, mq->last_head);
+ b0->data_len = ring->desc[mq->last_head].length;
+ b0->buffer_len = ring->desc[mq->last_head].buffer_length;
+
+#ifdef MEMIF_DBG_SHM
+ print_bytes (b0->data, b0->data_len, DBG_RX_BUF);
+#endif
+
+ mq->last_head = (mq->last_head + 1) & mask;
+
+ ns--;
+ count--;
+ *rx += 1;
+ }
+
+ mq->alloc_bufs += *rx;
+
+ if (ns)
+ {
+ DBG ("not enough buffers!");
+ return MEMIF_ERR_NOBUF;
+ }
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+int
+memif_get_details (memif_conn_handle_t conn, memif_details_t * md,
+ char *buf, ssize_t buflen)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+
+ int err = MEMIF_ERR_SUCCESS, i;
+ ssize_t l0, l1, total_l;
+ l0 = 0;
+
+ l1 = strlen ((char *) c->args.interface_name);
+ if (l0 + l1 <= buflen)
+ {
+ md->if_name = strncpy (buf + l0, (char *) c->args.interface_name, l1);
+ md->if_name[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ l1 = strlen ((char *) c->args.instance_name);
+ if (l0 + l1 <= buflen)
+ {
+ md->inst_name = strncpy (buf + l0, (char *) c->args.instance_name, l1);
+ md->inst_name[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ l1 = strlen ((char *) c->remote_if_name);
+ if (l0 + l1 <= buflen)
+ {
+ md->remote_if_name = strncpy (buf + l0, (char *) c->remote_if_name, l1);
+ md->remote_if_name[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ l1 = strlen ((char *) c->remote_name);
+ if (l0 + l1 <= buflen)
+ {
+ md->remote_inst_name = strncpy (buf + l0, (char *) c->remote_name, l1);
+ md->remote_inst_name[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ md->id = c->args.interface_id;
+
+ if (c->args.secret)
+ {
+ l1 = strlen ((char *) c->args.secret);
+ md->secret = strncpy (buf + l0, (char *) c->args.secret, l1);
+ md->secret[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ md->role = (c->args.is_master) ? 0 : 1;
+ md->mode = c->args.mode;
+
+ l1 = strlen ((char *) c->args.socket_filename);
+ if (l0 + l1 <= buflen)
+ {
+ md->socket_filename =
+ strncpy (buf + l0, (char *) c->args.socket_filename, l1);
+ md->socket_filename[l0 + l1] = '\0';
+ l0 += l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ md->rx_queues_num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+
+ l1 = sizeof (memif_queue_details_t) * md->rx_queues_num;
+ if (l0 + l1 <= buflen)
+ {
+ md->rx_queues = (memif_queue_details_t *) buf + l0;
+ l0 = l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ for (i = 0; i < md->rx_queues_num; i++)
+ {
+ md->rx_queues[i].qid = i;
+ md->rx_queues[i].ring_size = (1 << c->rx_queues[i].log2_ring_size);
+ md->rx_queues[i].buffer_size = c->run_args.buffer_size;
+ }
+
+ md->tx_queues_num =
+ (c->args.is_master) ? c->run_args.num_m2s_rings : c->run_args.
+ num_s2m_rings;
+
+ l1 = sizeof (memif_queue_details_t) * md->tx_queues_num;
+ if (l0 + l1 <= buflen)
+ {
+ md->tx_queues = (memif_queue_details_t *) buf + l0;
+ l0 = l1 + 1;
+ }
+ else
+ err = MEMIF_ERR_NOBUF_DET;
+
+ for (i = 0; i < md->tx_queues_num; i++)
+ {
+ md->tx_queues[i].qid = i;
+ md->tx_queues[i].ring_size = (1 << c->tx_queues[i].log2_ring_size);
+ md->tx_queues[i].buffer_size = c->run_args.buffer_size;
+ }
+
+ md->link_up_down = (c->fd > 0) ? 1 : 0;
+
+ return err; /* 0 */
+}
+
+int
+memif_get_queue_efd (memif_conn_handle_t conn, uint16_t qid, int *efd)
+{
+ memif_connection_t *c = (memif_connection_t *) conn;
+ *efd = -1;
+ if (c == NULL)
+ return MEMIF_ERR_NOCONN;
+ if (c->fd < 0)
+ return MEMIF_ERR_DISCONNECTED;
+ uint8_t num =
+ (c->args.is_master) ? c->run_args.num_s2m_rings : c->run_args.
+ num_m2s_rings;
+ if (qid >= num)
+ return MEMIF_ERR_QID;
+
+ *efd = c->rx_queues[qid].int_fd;
+
+ return MEMIF_ERR_SUCCESS;
+}
+
+int
+memif_cleanup ()
+{
+ libmemif_main_t *lm = &libmemif_main;
+ if (lm->app_name)
+ free (lm->app_name);
+ lm->app_name = NULL;
+ if (lm->control_list)
+ free (lm->control_list);
+ lm->control_list = NULL;
+ if (lm->interrupt_list)
+ free (lm->interrupt_list);
+ lm->interrupt_list = NULL;
+ if (lm->listener_list)
+ free (lm->listener_list);
+ lm->listener_list = NULL;
+ if (lm->pending_list)
+ free (lm->pending_list);
+ lm->pending_list = NULL;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
diff --git a/extras/libmemif/src/memif.h b/extras/libmemif/src/memif.h
new file mode 100644
index 00000000000..11918eabcde
--- /dev/null
+++ b/extras/libmemif/src/memif.h
@@ -0,0 +1,185 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#ifndef _MEMIF_H_
+#define _MEMIF_H_
+
+#ifndef MEMIF_CACHELINE_SIZE
+#define MEMIF_CACHELINE_SIZE 64
+#endif
+
+#define MEMIF_COOKIE 0x3E31F10
+#define MEMIF_VERSION_MAJOR 1
+#define MEMIF_VERSION_MINOR 0
+#define MEMIF_VERSION ((MEMIF_VERSION_MAJOR << 8) | MEMIF_VERSION_MINOR)
+
+/*
+ * Type definitions
+ */
+
+typedef enum memif_msg_type
+{
+ MEMIF_MSG_TYPE_NONE = 0,
+ MEMIF_MSG_TYPE_ACK = 1,
+ MEMIF_MSG_TYPE_HELLO = 2,
+ MEMIF_MSG_TYPE_INIT = 3,
+ MEMIF_MSG_TYPE_ADD_REGION = 4,
+ MEMIF_MSG_TYPE_ADD_RING = 5,
+ MEMIF_MSG_TYPE_CONNECT = 6,
+ MEMIF_MSG_TYPE_CONNECTED = 7,
+ MEMIF_MSG_TYPE_DISCONNECT = 8,
+} memif_msg_type_t;
+
+typedef enum
+{
+ MEMIF_RING_S2M = 0,
+ MEMIF_RING_M2S = 1
+} memif_ring_type_t;
+
+typedef enum
+{
+ MEMIF_INTERFACE_MODE_ETHERNET = 0,
+ MEMIF_INTERFACE_MODE_IP = 1,
+ MEMIF_INTERFACE_MODE_PUNT_INJECT = 2,
+} memif_interface_mode_t;
+
+typedef uint16_t memif_region_index_t;
+typedef uint64_t memif_region_offset_t;
+typedef uint64_t memif_region_size_t;
+typedef uint16_t memif_ring_index_t;
+typedef uint32_t memif_interface_id_t;
+typedef uint16_t memif_version_t;
+typedef uint8_t memif_log2_ring_size_t;
+
+/*
+ * Socket messages
+ */
+
+typedef struct __attribute__ ((packed))
+{
+ uint8_t name[32];
+ memif_version_t min_version;
+ memif_version_t max_version;
+ memif_region_index_t max_region;
+ memif_ring_index_t max_m2s_ring;
+ memif_ring_index_t max_s2m_ring;
+ memif_log2_ring_size_t max_log2_ring_size;
+} memif_msg_hello_t;
+
+typedef struct __attribute__ ((packed))
+{
+ memif_version_t version;
+ memif_interface_id_t id;
+ memif_interface_mode_t mode:8;
+ uint8_t secret[24];
+ uint8_t name[32];
+} memif_msg_init_t;
+
+typedef struct __attribute__ ((packed))
+{
+ memif_region_index_t index;
+ memif_region_size_t size;
+} memif_msg_add_region_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint16_t flags;
+#define MEMIF_MSG_ADD_RING_FLAG_S2M (1 << 0)
+ memif_ring_index_t index;
+ memif_region_index_t region;
+ memif_region_offset_t offset;
+ memif_log2_ring_size_t log2_ring_size;
+} memif_msg_add_ring_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint8_t if_name[32];
+} memif_msg_connect_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint8_t if_name[32];
+} memif_msg_connected_t;
+
+typedef struct __attribute__ ((packed))
+{
+ uint32_t code;
+ uint8_t string[96];
+} memif_msg_disconnect_t;
+
+typedef struct __attribute__ ((packed, aligned (128)))
+{
+ memif_msg_type_t type:16;
+ union
+ {
+ memif_msg_hello_t hello;
+ memif_msg_init_t init;
+ memif_msg_add_region_t add_region;
+ memif_msg_add_ring_t add_ring;
+ memif_msg_connect_t connect;
+ memif_msg_connected_t connected;
+ memif_msg_disconnect_t disconnect;
+ };
+} memif_msg_t;
+
+_Static_assert (sizeof (memif_msg_t) == 128,
+ "Size of memif_msg_t must be 128");
+
+/*
+ * Ring and Descriptor Layout
+ */
+
+typedef struct __attribute__ ((packed))
+{
+ uint16_t flags;
+#define MEMIF_DESC_FLAG_NEXT (1 << 0)
+ memif_region_index_t region;
+ uint32_t buffer_length;
+ uint32_t length;
+ uint8_t reserved[4];
+ memif_region_offset_t offset;
+ uint64_t metadata;
+} memif_desc_t;
+
+_Static_assert (sizeof (memif_desc_t) == 32,
+ "Size of memif_dsct_t must be 32");
+
+#define MEMIF_CACHELINE_ALIGN_MARK(mark) \
+ uint8_t mark[0] __attribute__((aligned(MEMIF_CACHELINE_SIZE)))
+
+typedef struct
+{
+ MEMIF_CACHELINE_ALIGN_MARK (cacheline0);
+ uint32_t cookie;
+ uint16_t flags;
+#define MEMIF_RING_FLAG_MASK_INT 1
+ volatile uint16_t head;
+ MEMIF_CACHELINE_ALIGN_MARK (cacheline1);
+ volatile uint16_t tail;
+ MEMIF_CACHELINE_ALIGN_MARK (cacheline2);
+ memif_desc_t desc[0];
+} memif_ring_t;
+
+#endif /* _MEMIF_H_ */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/extras/libmemif/src/memif_private.h b/extras/libmemif/src/memif_private.h
new file mode 100644
index 00000000000..51f3be662fb
--- /dev/null
+++ b/extras/libmemif/src/memif_private.h
@@ -0,0 +1,265 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+
+#ifndef _MEMIF_PRIVATE_H_
+#define _MEMIF_PRIVATE_H_
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <sys/timerfd.h>
+
+#include <libmemif.h>
+
+#define MEMIF_DEFAULT_SOCKET_DIR "/run/vpp"
+#define MEMIF_DEFAULT_SOCKET_FILENAME "memif.sock"
+#define MEMIF_DEFAULT_RING_SIZE 1024
+#define MEMIF_DEFAULT_LOG2_RING_SIZE 10
+#define MEMIF_DEFAULT_RX_QUEUES 1
+#define MEMIF_DEFAULT_TX_QUEUES 1
+#define MEMIF_DEFAULT_BUFFER_SIZE 2048
+
+#define MEMIF_MAX_M2S_RING 255
+#define MEMIF_MAX_S2M_RING 255
+#define MEMIF_MAX_REGION 255
+#define MEMIF_MAX_LOG2_RING_SIZE 14
+
+#define MEMIF_MAX_FDS 512
+
+
+#ifdef MEMIF_DBG
+#define DBG(...) do { \
+ printf("MEMIF_DEBUG:%s:%s:%d: ", __FILE__, __func__, __LINE__); \
+ printf(__VA_ARGS__); \
+ printf("\n"); \
+ } while (0)
+
+#define DBG_UNIX(...) do { \
+ printf("MEMIF_DEBUG_UNIX:%s:%s:%d: ", __FILE__, __func__, __LINE__); \
+ printf(__VA_ARGS__); \
+ printf("\n"); \
+ } while (0)
+
+#define error_return_unix(...) do { \
+ DBG_UNIX(__VA_ARGS__); \
+ return -1; \
+ } while (0)
+#define error_return(...) do { \
+ DBG(__VA_ARGS__); \
+ return -1; \
+ } while (0)
+#else
+#define DBG(...)
+#define DBG_UNIX(...)
+#define error_return_unix(...) do { \
+ return -1; \
+ } while (0)
+#define error_return(...) do { \
+ return -1; \
+ } while (0)
+
+#endif /* MEMIF_DBG */
+
+typedef struct
+{
+ void *shm;
+ uint32_t region_size;
+ int fd;
+} memif_region_t;
+
+typedef struct
+{
+ memif_ring_t *ring;
+ uint8_t log2_ring_size;
+ uint8_t region;
+ uint32_t offset;
+
+ uint16_t last_head;
+ uint16_t last_tail;
+
+ int int_fd;
+
+ uint64_t int_count;
+ uint32_t alloc_bufs;
+} memif_queue_t;
+
+typedef struct memif_msg_queue_elt
+{
+ memif_msg_t msg;
+ int fd;
+ struct memif_msg_queue_elt *next;
+} memif_msg_queue_elt_t;
+
+struct memif_connection;
+
+typedef struct memif_connection memif_connection_t;
+
+/* functions called by memif_control_fd_handler */
+typedef int (memif_fn) (memif_connection_t * conn);
+
+typedef struct
+{
+ uint8_t num_s2m_rings;
+ uint8_t num_m2s_rings;
+ uint16_t buffer_size;
+ memif_log2_ring_size_t log2_ring_size;
+} memif_conn_run_args_t;
+
+typedef struct memif_connection
+{
+ uint16_t index;
+ memif_conn_args_t args;
+ memif_conn_run_args_t run_args;
+
+ int fd;
+ int listener_fd;
+
+ memif_fn *write_fn, *read_fn, *error_fn;
+
+ memif_connection_update_t *on_connect, *on_disconnect;
+ memif_interrupt_t *on_interrupt;
+ void *private_ctx;
+
+ /* connection message queue */
+ memif_msg_queue_elt_t *msg_queue;
+
+ uint8_t remote_if_name[32];
+ uint8_t remote_name[32];
+ uint8_t remote_disconnect_string[96];
+
+ memif_region_t *regions;
+
+ memif_queue_t *rx_queues;
+ memif_queue_t *tx_queues;
+
+ uint16_t flags;
+#define MEMIF_CONNECTION_FLAG_WRITE (1 << 0)
+} memif_connection_t;
+
+/*
+ * WIP
+ */
+typedef struct
+{
+ int key; /* fd or id */
+ void *data_struct;
+} memif_list_elt_t;
+
+/*
+ * WIP
+ */
+typedef struct
+{
+ int fd;
+ uint16_t use_count;
+ uint8_t *filename;
+ uint16_t interface_list_len;
+ memif_list_elt_t *interface_list; /* memif master interfaces listening on this socket */
+} memif_socket_t;
+
+/*
+ * WIP
+ */
+/* probably function like memif_cleanup () will need to be called to close timerfd */
+typedef struct
+{
+ memif_control_fd_update_t *control_fd_update;
+ int timerfd;
+ struct itimerspec arm, disarm;
+ uint16_t disconn_slaves;
+ uint8_t *app_name;
+
+ /* master implementation... */
+ memif_socket_t ms;
+
+ uint16_t control_list_len;
+ uint16_t interrupt_list_len;
+ uint16_t listener_list_len;
+ uint16_t pending_list_len;
+ memif_list_elt_t *control_list;
+ memif_list_elt_t *interrupt_list;
+ memif_list_elt_t *listener_list;
+ memif_list_elt_t *pending_list;
+} libmemif_main_t;
+
+extern libmemif_main_t libmemif_main;
+extern int memif_epfd;
+
+/* main.c */
+
+/* if region doesn't contain shared memory, mmap region, check ring cookie */
+int memif_connect1 (memif_connection_t * c);
+
+/* memory map region, initalize rings and queues */
+int memif_init_regions_and_queues (memif_connection_t * c);
+
+int memif_disconnect_internal (memif_connection_t * c);
+
+/* map errno to memif error code */
+int memif_syscall_error_handler (int err_code);
+
+int add_list_elt (memif_list_elt_t * e, memif_list_elt_t ** list,
+ uint16_t * len);
+
+int get_list_elt (memif_list_elt_t ** e, memif_list_elt_t * list,
+ uint16_t len, int key);
+
+int free_list_elt (memif_list_elt_t * list, uint16_t len, int key);
+
+#ifndef __NR_memfd_create
+#if defined __x86_64__
+#define __NR_memfd_create 319
+#elif defined __arm__
+#define __NR_memfd_create 385
+#elif defined __aarch64__
+#define __NR_memfd_create 279
+#else
+#error "__NR_memfd_create unknown for this architecture"
+#endif
+#endif
+
+static inline int
+memfd_create (const char *name, unsigned int flags)
+{
+ return syscall (__NR_memfd_create, name, flags);
+}
+
+static inline void *
+memif_get_buffer (memif_connection_t * conn, memif_ring_t * ring,
+ uint16_t index)
+{
+ return (conn->regions[ring->desc[index].region].shm +
+ ring->desc[index].offset);
+}
+
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+#define MFD_ALLOW_SEALING 0x0002U
+#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
+#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
+
+#define F_SEAL_SEAL 0x0001 /* prevent further seals from being set */
+#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
+#define F_SEAL_GROW 0x0004 /* prevent file from growing */
+#define F_SEAL_WRITE 0x0008 /* prevent writes */
+
+#endif /* _MEMIF_PRIVATE_H_ */
diff --git a/extras/libmemif/src/socket.c b/extras/libmemif/src/socket.c
new file mode 100644
index 00000000000..9c9b3a8dd73
--- /dev/null
+++ b/extras/libmemif/src/socket.c
@@ -0,0 +1,883 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#define _GNU_SOURCE
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <socket.h>
+#include <memif.h>
+
+#define memif_min(a,b) ((a < b) ? (a) : (b))
+
+/* sends msg to socket */
+static_fn int
+memif_msg_send (int fd, memif_msg_t * msg, int afd)
+{
+ struct msghdr mh = { 0 };
+ struct iovec iov[1];
+ char ctl[CMSG_SPACE (sizeof (int))];
+ int rv, err = MEMIF_ERR_SUCCESS; /* 0 */
+
+ iov[0].iov_base = (void *) msg;
+ iov[0].iov_len = sizeof (memif_msg_t);
+ mh.msg_iov = iov;
+ mh.msg_iovlen = 1;
+
+ if (afd > 0)
+ {
+ struct cmsghdr *cmsg;
+ memset (&ctl, 0, sizeof (ctl));
+ mh.msg_control = ctl;
+ mh.msg_controllen = sizeof (ctl);
+ cmsg = CMSG_FIRSTHDR (&mh);
+ cmsg->cmsg_len = CMSG_LEN (sizeof (int));
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ memcpy (CMSG_DATA (cmsg), &afd, sizeof (int));
+ }
+ rv = sendmsg (fd, &mh, 0);
+ if (rv < 0)
+ err = memif_syscall_error_handler (errno);
+ DBG ("Message type %u sent", msg->type);
+ return err;
+}
+
+/* response from memif master - master is ready to handle next message */
+static_fn int
+memif_msg_enq_ack (memif_connection_t * c)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ e->msg.type = MEMIF_MSG_TYPE_ACK;
+ e->fd = -1;
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+static_fn int
+memif_msg_send_hello (int fd)
+{
+ libmemif_main_t *lm = &libmemif_main;
+ memif_msg_t msg = { 0 };
+ memif_msg_hello_t *h = &msg.hello;
+ msg.type = MEMIF_MSG_TYPE_HELLO;
+ h->min_version = MEMIF_VERSION;
+ h->max_version = MEMIF_VERSION;
+ h->max_s2m_ring = MEMIF_MAX_M2S_RING;
+ h->max_m2s_ring = MEMIF_MAX_M2S_RING;
+ h->max_region = MEMIF_MAX_REGION;
+ h->max_log2_ring_size = MEMIF_MAX_LOG2_RING_SIZE;
+
+ strncpy ((char *) h->name, lm->app_name, strlen (lm->app_name));
+
+ /* msg hello is not enqueued but sent directly,
+ because it is the first msg to be sent */
+ return memif_msg_send (fd, &msg, -1);
+}
+
+/* send id and secret (optional) for interface identification */
+static_fn int
+memif_msg_enq_init (memif_connection_t * c)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+ memset (e, 0, sizeof (memif_msg_queue_elt_t));
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_init_t *i = &e->msg.init;
+
+ e->msg.type = MEMIF_MSG_TYPE_INIT;
+ e->fd = -1;
+ i->version = MEMIF_VERSION;
+ i->id = c->args.interface_id;
+ i->mode = c->args.mode;
+
+ strncpy ((char *) i->name, (char *) c->args.instance_name,
+ strlen ((char *) c->args.instance_name));
+ if (c->args.secret)
+ strncpy ((char *) i->secret, (char *) c->args.secret, sizeof (i->secret));
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* send information about region specified by region_index */
+static_fn int
+memif_msg_enq_add_region (memif_connection_t * c, uint8_t region_index)
+{
+ /* maybe check if region is valid? */
+ memif_region_t *mr = &c->regions[region_index];
+
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_add_region_t *ar = &e->msg.add_region;
+
+ e->msg.type = MEMIF_MSG_TYPE_ADD_REGION;
+ e->fd = mr->fd;
+ ar->index = region_index;
+ ar->size = mr->region_size;
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* send information about ring specified by direction (S2M | M2S) and index */
+static_fn int
+memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index, uint8_t dir)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_add_ring_t *ar = &e->msg.add_ring;
+
+ e->msg.type = MEMIF_MSG_TYPE_ADD_RING;
+
+ /* TODO: support multiple rings */
+ memif_queue_t *mq;
+ if (dir == MEMIF_RING_M2S)
+ mq = &c->rx_queues[index];
+ else
+ mq = &c->tx_queues[index];
+
+ e->fd = mq->int_fd;
+ ar->index = index;
+ ar->offset = mq->offset;
+ ar->region = mq->region;
+ ar->log2_ring_size = mq->log2_ring_size;
+ ar->flags = (dir == MEMIF_RING_S2M) ? MEMIF_MSG_ADD_RING_FLAG_S2M : 0;
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* used as connection request from slave */
+static_fn int
+memif_msg_enq_connect (memif_connection_t * c)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_connect_t *cm = &e->msg.connect;
+
+ e->msg.type = MEMIF_MSG_TYPE_CONNECT;
+ e->fd = -1;
+ strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
+ strlen ((char *) c->args.interface_name));
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* used as confirmation of connection by master */
+static_fn int
+memif_msg_enq_connected (memif_connection_t * c)
+{
+ memif_msg_queue_elt_t *e =
+ (memif_msg_queue_elt_t *) malloc (sizeof (memif_msg_queue_elt_t));
+ if (e == NULL)
+ return memif_syscall_error_handler (errno);
+
+ memset (&e->msg, 0, sizeof (e->msg));
+ memif_msg_connected_t *cm = &e->msg.connected;
+
+ e->msg.type = MEMIF_MSG_TYPE_CONNECTED;
+ e->fd = -1;
+ strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
+ strlen ((char *) c->args.interface_name));
+
+ e->next = NULL;
+ if (c->msg_queue == NULL)
+ {
+ c->msg_queue = e;
+ return MEMIF_ERR_SUCCESS; /* 0 */
+ }
+
+ memif_msg_queue_elt_t *cur = c->msg_queue;
+ while (cur->next != NULL)
+ {
+ cur = cur->next;
+ }
+ cur->next = e;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* immediately send disconnect msg */
+ /* specifie protocol for disconnect msg err_code
+ so that it will be compatible with VPP? (header/doc) */
+int
+memif_msg_send_disconnect (int fd, uint8_t * err_string, uint32_t err_code)
+{
+ memif_msg_t msg = { 0 };
+ memif_msg_disconnect_t *d = &msg.disconnect;
+
+ msg.type = MEMIF_MSG_TYPE_DISCONNECT;
+ d->code = err_code;
+ uint16_t l = strlen ((char *) err_string);
+ if (l > 96)
+ {
+ DBG ("Disconnect string too long. Sending first 96 characters.");
+ l = 96;
+ }
+ strncpy ((char *) d->string, (char *) err_string, l);
+
+ return memif_msg_send (fd, &msg, -1);
+}
+
+static_fn int
+memif_msg_receive_hello (memif_connection_t * c, memif_msg_t * msg)
+{
+ memif_msg_hello_t *h = &msg->hello;
+
+ if (msg->hello.min_version > MEMIF_VERSION ||
+ msg->hello.max_version < MEMIF_VERSION)
+ {
+ DBG ("incompatible protocol version");
+ return MEMIF_ERR_PROTO;
+ }
+
+ c->run_args.num_s2m_rings = memif_min (h->max_s2m_ring + 1,
+ c->args.num_s2m_rings);
+ c->run_args.num_m2s_rings = memif_min (h->max_m2s_ring + 1,
+ c->args.num_m2s_rings);
+ c->run_args.log2_ring_size = memif_min (h->max_log2_ring_size,
+ c->args.log2_ring_size);
+ c->run_args.buffer_size = c->args.buffer_size;
+ strncpy ((char *) c->remote_name, (char *) h->name,
+ strlen ((char *) h->name));
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* handle interface identification (id, secret (optional)) */
+static_fn int
+memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg)
+{
+ memif_msg_init_t *i = &msg->init;
+ memif_list_elt_t *elt = NULL;
+ memif_list_elt_t elt2;
+ memif_connection_t *c = NULL;
+ libmemif_main_t *lm = &libmemif_main;
+ uint8_t err_string[96];
+ memset (err_string, 0, sizeof (char) * 96);
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+ int err_disc;
+ if (i->version != MEMIF_VERSION)
+ {
+ DBG ("MEMIF_VER_ERR");
+ strncpy ((char *) err_string, MEMIF_VER_ERR, strlen (MEMIF_VER_ERR));
+ err = MEMIF_ERR_PROTO;
+ goto error;
+ }
+
+ get_list_elt (&elt, ms->interface_list, ms->interface_list_len, i->id);
+ if (elt == NULL)
+ {
+ DBG ("MEMIF_ID_ERR");
+ strncpy ((char *) err_string, MEMIF_ID_ERR, strlen (MEMIF_ID_ERR));
+ err = MEMIF_ERR_ID;
+ goto error;
+ }
+
+ c = (memif_connection_t *) elt->data_struct;
+
+ if (!(c->args.is_master))
+ {
+ DBG ("MEMIF_SLAVE_ERR");
+ strncpy ((char *) err_string, MEMIF_SLAVE_ERR,
+ strlen (MEMIF_SLAVE_ERR));
+ err = MEMIF_ERR_ACCSLAVE;
+ goto error;
+ }
+ if (c->fd != -1)
+ {
+ DBG ("MEMIF_CONN_ERR");
+ strncpy ((char *) err_string, MEMIF_CONN_ERR, strlen (MEMIF_CONN_ERR));
+ err = MEMIF_ERR_ALRCONN;
+ goto error;
+ }
+
+ c->fd = fd;
+
+ if (i->mode != c->args.mode)
+ {
+ DBG ("MEMIF_MODE_ERR");
+ strncpy ((char *) err_string, MEMIF_MODE_ERR, strlen (MEMIF_MODE_ERR));
+ err = MEMIF_ERR_MODE;
+ goto error;
+ }
+
+ strncpy ((char *) c->remote_name, (char *) i->name,
+ strlen ((char *) i->name));
+
+ if (c->args.secret)
+ {
+ int r;
+ if (i->secret)
+ {
+ if (strlen ((char *) c->args.secret) != strlen ((char *) i->secret))
+ {
+ DBG ("MEMIF_SECRET_ERR");
+ strncpy ((char *) err_string,
+ MEMIF_SECRET_ERR, strlen (MEMIF_SECRET_ERR));
+ err = MEMIF_ERR_SECRET;
+ goto error;
+ }
+ r = strncmp ((char *) i->secret, (char *) c->args.secret,
+ strlen ((char *) c->args.secret));
+ if (r != 0)
+ {
+ DBG ("MEMIF_SECRET_ERR");
+ strncpy ((char *) err_string,
+ MEMIF_SECRET_ERR, strlen (MEMIF_SECRET_ERR));
+ err = MEMIF_ERR_SECRET;
+ goto error;
+ }
+ }
+ else
+ {
+ DBG ("MEMIF_NOSECRET_ERR");
+ strncpy ((char *) err_string,
+ MEMIF_NOSECRET_ERR, strlen (MEMIF_NOSECRET_ERR));
+ err = MEMIF_ERR_NOSECRET;
+ goto error;
+ }
+ }
+
+ c->read_fn = memif_conn_fd_read_ready;
+ c->write_fn = memif_conn_fd_write_ready;
+ c->error_fn = memif_conn_fd_error;
+
+ elt2.key = c->fd;
+ elt2.data_struct = c;
+
+ add_list_elt (&elt2, &lm->control_list, &lm->control_list_len);
+ free_list_elt (lm->pending_list, lm->pending_list_len, fd);
+
+ return err;
+
+error:
+ memif_msg_send_disconnect (fd, err_string, 0);
+ lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL);
+ free_list_elt (lm->pending_list, lm->pending_list_len, fd);
+ close (fd);
+ fd = -1;
+ return err;
+}
+
+/* receive region information and add new region to connection (if possible) */
+static_fn int
+memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
+ int fd)
+{
+ memif_msg_add_region_t *ar = &msg->add_region;
+ memif_region_t *mr;
+ if (fd < 0)
+ return MEMIF_ERR_NO_SHMFD;
+
+ if (ar->index > MEMIF_MAX_REGION)
+ return MEMIF_ERR_MAXREG;
+
+ mr =
+ (memif_region_t *) realloc (c->regions,
+ sizeof (memif_region_t) * (ar->index + 1));
+ if (mr == NULL)
+ return memif_syscall_error_handler (errno);
+ c->regions = mr;
+ c->regions[ar->index].fd = fd;
+ c->regions[ar->index].region_size = ar->size;
+ c->regions[ar->index].shm = NULL;
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* receive ring information and add new ring to connection queue
+ (based on direction S2M | M2S) */
+static_fn int
+memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
+{
+ memif_msg_add_ring_t *ar = &msg->add_ring;
+
+ memif_queue_t *mq;
+
+ if (fd < 0)
+ return MEMIF_ERR_NO_INTFD;
+
+ if (ar->flags & MEMIF_MSG_ADD_RING_FLAG_S2M)
+ {
+ if (ar->index > MEMIF_MAX_S2M_RING)
+ return MEMIF_ERR_MAXRING;
+ if (ar->index >= c->args.num_s2m_rings)
+ return MEMIF_ERR_MAXRING;
+
+ mq =
+ (memif_queue_t *) realloc (c->rx_queues,
+ sizeof (memif_queue_t) * (ar->index + 1));
+ if (mq == NULL)
+ return memif_syscall_error_handler (errno);
+ c->rx_queues = mq;
+ c->rx_queues[ar->index].int_fd = fd;
+ c->rx_queues[ar->index].log2_ring_size = ar->log2_ring_size;
+ c->rx_queues[ar->index].region = ar->region;
+ c->rx_queues[ar->index].offset = ar->offset;
+ c->run_args.num_s2m_rings++;
+ }
+ else
+ {
+ if (ar->index > MEMIF_MAX_M2S_RING)
+ return MEMIF_ERR_MAXRING;
+ if (ar->index >= c->args.num_m2s_rings)
+ return MEMIF_ERR_MAXRING;
+
+ mq =
+ (memif_queue_t *) realloc (c->tx_queues,
+ sizeof (memif_queue_t) * (ar->index + 1));
+ if (mq == NULL)
+ return memif_syscall_error_handler (errno);
+ c->tx_queues = mq;
+ c->tx_queues[ar->index].int_fd = fd;
+ c->tx_queues[ar->index].log2_ring_size = ar->log2_ring_size;
+ c->tx_queues[ar->index].region = ar->region;
+ c->tx_queues[ar->index].offset = ar->offset;
+ c->run_args.num_m2s_rings++;
+ }
+
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+/* slave -> master */
+static_fn int
+memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg)
+{
+ memif_msg_connect_t *cm = &msg->connect;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_list_elt_t elt;
+
+ int err;
+ err = memif_connect1 (c);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+
+ strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
+ strlen ((char *) cm->if_name));
+
+ int i;
+ if (c->on_interrupt != NULL)
+ {
+ for (i = 0; i < c->run_args.num_m2s_rings; i++)
+ {
+ elt.key = c->rx_queues[i].int_fd;
+ elt.data_struct = c;
+ add_list_elt (&elt, &lm->interrupt_list, &lm->interrupt_list_len);
+
+ lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
+ }
+
+ }
+
+ c->on_connect ((void *) c, c->private_ctx);
+
+ return err;
+}
+
+/* master -> slave */
+static_fn int
+memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg)
+{
+ memif_msg_connect_t *cm = &msg->connect;
+ libmemif_main_t *lm = &libmemif_main;
+
+ int err;
+ err = memif_connect1 (c);
+ if (err != MEMIF_ERR_SUCCESS)
+ return err;
+
+ strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
+ strlen ((char *) cm->if_name));
+
+ int i;
+ if (c->on_interrupt != NULL)
+ {
+ for (i = 0; i < c->run_args.num_s2m_rings; i++)
+ lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
+ }
+
+ c->on_connect ((void *) c, c->private_ctx);
+
+ return err;
+}
+
+static_fn int
+memif_msg_receive_disconnect (memif_connection_t * c, memif_msg_t * msg)
+{
+ memif_msg_disconnect_t *d = &msg->disconnect;
+
+ memset (c->remote_disconnect_string, 0,
+ sizeof (c->remote_disconnect_string));
+ strncpy ((char *) c->remote_disconnect_string, (char *) d->string,
+ strlen ((char *) d->string));
+
+ /* on returning error, handle function will call memif_disconnect () */
+ DBG ("disconnect received: %s, mode: %d",
+ c->remote_disconnect_string, c->args.mode);
+ return MEMIF_ERR_DISCONNECT;
+}
+
+static_fn int
+memif_msg_receive (int ifd)
+{
+ char ctl[CMSG_SPACE (sizeof (int)) +
+ CMSG_SPACE (sizeof (struct ucred))] = { 0 };
+ struct msghdr mh = { 0 };
+ struct iovec iov[1];
+ memif_msg_t msg = { 0 };
+ ssize_t size;
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+ int fd = -1;
+ int i;
+ libmemif_main_t *lm = &libmemif_main;
+ memif_connection_t *c = NULL;
+ memif_socket_t *ms = NULL;
+ memif_list_elt_t *elt = NULL;
+
+ iov[0].iov_base = (void *) &msg;
+ iov[0].iov_len = sizeof (memif_msg_t);
+ mh.msg_iov = iov;
+ mh.msg_iovlen = 1;
+ mh.msg_control = ctl;
+ mh.msg_controllen = sizeof (ctl);
+
+ DBG ("recvmsg fd %d", ifd);
+ size = recvmsg (ifd, &mh, 0);
+ DBG ("done");
+ if (size != sizeof (memif_msg_t))
+ {
+ if (size == 0)
+ return MEMIF_ERR_DISCONNECTED;
+ else
+ return MEMIF_ERR_MFMSG;
+ }
+
+ struct ucred *cr = 0;
+ struct cmsghdr *cmsg;
+
+ cmsg = CMSG_FIRSTHDR (&mh);
+ while (cmsg)
+ {
+ if (cmsg->cmsg_level == SOL_SOCKET)
+ {
+ if (cmsg->cmsg_type == SCM_CREDENTIALS)
+ {
+ cr = (struct ucred *) CMSG_DATA (cmsg);
+ }
+ else if (cmsg->cmsg_type == SCM_RIGHTS)
+ {
+ int *fdp = (int *) CMSG_DATA (cmsg);
+ fd = *fdp;
+ }
+ }
+ cmsg = CMSG_NXTHDR (&mh, cmsg);
+ }
+
+ DBG ("Message type %u received", msg.type);
+
+ get_list_elt (&elt, lm->control_list, lm->control_list_len, ifd);
+ if (elt != NULL)
+ c = (memif_connection_t *) elt->data_struct;
+
+ switch (msg.type)
+ {
+ case MEMIF_MSG_TYPE_ACK:
+ break;
+
+ case MEMIF_MSG_TYPE_HELLO:
+ if ((err = memif_msg_receive_hello (c, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_init (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_add_region (c, 0)) != MEMIF_ERR_SUCCESS)
+ return err;
+ for (i = 0; i < c->run_args.num_s2m_rings; i++)
+ {
+ if ((err =
+ memif_msg_enq_add_ring (c, i,
+ MEMIF_RING_S2M)) != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ for (i = 0; i < c->run_args.num_m2s_rings; i++)
+ {
+ if ((err =
+ memif_msg_enq_add_ring (c, i,
+ MEMIF_RING_M2S)) != MEMIF_ERR_SUCCESS)
+ return err;
+ }
+ if ((err = memif_msg_enq_connect (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_INIT:
+ get_list_elt (&elt, lm->pending_list, lm->pending_list_len, ifd);
+ if (elt == NULL)
+ return -1;
+ ms = (memif_socket_t *) elt->data_struct;
+ if ((err = memif_msg_receive_init (ms, ifd, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ /* c->remote_pid = cr->pid */
+ /* c->remote_uid = cr->uid */
+ /* c->remote_gid = cr->gid */
+ get_list_elt (&elt, lm->control_list, lm->control_list_len, ifd);
+ if (elt == NULL)
+ return -1;
+ c = (memif_connection_t *) elt->data_struct;
+ if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_ADD_REGION:
+ if ((err =
+ memif_msg_receive_add_region (c, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_ADD_RING:
+ if ((err =
+ memif_msg_receive_add_ring (c, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_ack (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_CONNECT:
+ if ((err = memif_msg_receive_connect (c, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ if ((err = memif_msg_enq_connected (c)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_CONNECTED:
+ if ((err = memif_msg_receive_connected (c, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ case MEMIF_MSG_TYPE_DISCONNECT:
+ if ((err = memif_msg_receive_disconnect (c, &msg)) != MEMIF_ERR_SUCCESS)
+ return err;
+ break;
+
+ default:
+ return MEMIF_ERR_UNKNOWN_MSG;;
+ break;
+ }
+
+ if (c != NULL)
+ c->flags |= MEMIF_CONNECTION_FLAG_WRITE;
+/* libmemif_main_t *lm = &libmemif_main;
+ lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD); */
+ return MEMIF_ERR_SUCCESS; /* 0 */
+}
+
+int
+memif_conn_fd_error (memif_connection_t * c)
+{
+ DBG ("connection fd error");
+ strncpy ((char *) c->remote_disconnect_string, "connection fd error", 19);
+ int err = memif_disconnect_internal (c);
+ return err;
+}
+
+/* calls memif_msg_receive to handle pending messages on socket */
+int
+memif_conn_fd_read_ready (memif_connection_t * c)
+{
+ int err;
+ err = memif_msg_receive (c->fd);
+ if (err != 0)
+ {
+ err = memif_disconnect_internal (c);
+ }
+ return err;
+}
+
+/* get msg from msg queue buffer and send it to socket */
+int
+memif_conn_fd_write_ready (memif_connection_t * c)
+{
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
+
+
+ if ((c->flags & MEMIF_CONNECTION_FLAG_WRITE) == 0)
+ goto done;
+
+ memif_msg_queue_elt_t *e = c->msg_queue;
+ if (e == NULL)
+ goto done;
+
+ c->msg_queue = c->msg_queue->next;
+
+ c->flags &= ~MEMIF_CONNECTION_FLAG_WRITE;
+/*
+ libmemif_main_t *lm = &libmemif_main;
+
+ lm->control_fd_update (c->fd,
+ MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE | MEMIF_FD_EVENT_MOD);
+*/
+ err = memif_msg_send (c->fd, &e->msg, e->fd);
+ free (e);
+ goto done;
+
+done:
+ return err;
+}
+
+int
+memif_conn_fd_accept_ready (memif_socket_t * ms)
+{
+ int addr_len;
+ struct sockaddr_un client;
+ int conn_fd;
+ libmemif_main_t *lm = &libmemif_main;
+
+ DBG ("accept called");
+
+ addr_len = sizeof (client);
+ conn_fd =
+ accept (ms->fd, (struct sockaddr *) &client, (socklen_t *) & addr_len);
+
+ if (conn_fd < 0)
+ {
+ return memif_syscall_error_handler (errno);
+ }
+ DBG ("accept fd %d", ms->fd);
+ DBG ("conn fd %d", conn_fd);
+
+ memif_list_elt_t elt;
+ elt.key = conn_fd;
+ elt.data_struct = ms;
+
+ add_list_elt (&elt, &lm->pending_list, &lm->pending_list_len);
+ lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE);
+
+ return memif_msg_send_hello (conn_fd);
+}
+
+int
+memif_read_ready (int fd)
+{
+ int err;
+ DBG ("call recv");
+ err = memif_msg_receive (fd);
+ DBG ("recv finished");
+ return err;
+}
diff --git a/extras/libmemif/src/socket.h b/extras/libmemif/src/socket.h
new file mode 100644
index 00000000000..a8e9fbce9f6
--- /dev/null
+++ b/extras/libmemif/src/socket.h
@@ -0,0 +1,89 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#ifndef _SOCKET_H_
+#define _SOCKET_H
+
+#include <memif_private.h>
+
+/* interface identification errors (disconnect messages)*/
+#define MEMIF_VER_ERR "incompatible version"
+#define MEMIF_ID_ERR "unmatched interface id"
+#define MEMIF_SLAVE_ERR "cannot connect to salve"
+#define MEMIF_CONN_ERR "already connected"
+#define MEMIF_MODE_ERR "mode mismatch"
+#define MEMIF_SECRET_ERR "incorrect secret"
+#define MEMIF_NOSECRET_ERR "secret required"
+
+/* socket.c */
+
+int memif_conn_fd_read_ready (memif_connection_t * c);
+
+int memif_conn_fd_write_ready (memif_connection_t * c);
+
+int memif_conn_fd_error (memif_connection_t * c);
+
+int memif_conn_fd_accept_ready (memif_socket_t * ms);
+
+int memif_read_ready (int fd);
+
+int memif_msg_send_disconnect (int fd, uint8_t * err_string,
+ uint32_t err_code);
+
+/* when compiling unit tests, compile functions without static keyword
+ and declare functions in header file */
+#ifdef MEMIF_UNIT_TEST
+#define static_fn
+
+int memif_msg_send (int fd, memif_msg_t * msg, int afd);
+
+int memif_msg_enq_ack (memif_connection_t * c);
+
+int memif_msg_send_hello (int fd);
+
+int memif_msg_enq_init (memif_connection_t * c);
+
+int memif_msg_enq_add_region (memif_connection_t * c, uint8_t region);
+
+int memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index,
+ uint8_t dir);
+
+int memif_msg_receive_hello (memif_connection_t * c, memif_msg_t * msg);
+
+int memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg);
+
+int memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
+ int fd);
+
+int memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg,
+ int fd);
+
+int memif_msg_enq_connect (memif_connection_t * c);
+
+int memif_msg_enq_connected (memif_connection_t * c);
+
+int memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg);
+
+int memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg);
+
+int memif_msg_receive_disconnect (memif_connection_t * c, memif_msg_t * msg);
+
+#else
+#define static_fn static
+#endif /* MEMIF_UNIT_TEST */
+
+#endif /* _SOCKET_H_ */
diff --git a/extras/libmemif/test/main_test.c b/extras/libmemif/test/main_test.c
new file mode 100644
index 00000000000..deb8acb69ff
--- /dev/null
+++ b/extras/libmemif/test/main_test.c
@@ -0,0 +1,1079 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <main_test.h>
+
+#include <memif_private.h>
+
+#define SOCKET_FILENAME "/run/vpp/memif.sock"
+
+uint8_t ready_called;
+#define read_call (1 << 0)
+#define write_call (1 << 1)
+#define error_call (1 << 2)
+
+int
+read_fn (memif_connection_t * c)
+{
+ ready_called |= read_call;
+ return 0;
+}
+
+int
+write_fn (memif_connection_t * c)
+{
+ ready_called |= write_call;
+ return 0;
+}
+
+int
+error_fn (memif_connection_t * c)
+{
+ ready_called |= error_call;
+ return 0;
+}
+
+static void
+register_fd_ready_fn (memif_connection_t * c,
+ memif_fn * read_fn, memif_fn * write_fn,
+ memif_fn * error_fn)
+{
+ c->read_fn = read_fn;
+ c->write_fn = write_fn;
+ c->error_fn = error_fn;
+}
+
+START_TEST (test_init)
+{
+ int err;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ ck_assert_ptr_ne (lm, NULL);
+ ck_assert_ptr_ne (lm->control_fd_update, NULL);
+ ck_assert_int_gt (lm->timerfd, 2);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+}
+
+END_TEST
+START_TEST (test_init_epoll)
+{
+ int err;
+
+ if ((err = memif_init (NULL, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ ck_assert_ptr_ne (lm, NULL);
+ ck_assert_ptr_ne (lm->control_fd_update, NULL);
+ ck_assert_int_gt (lm->timerfd, 2);
+ ck_assert_int_gt (memif_epfd, -1);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+}
+
+END_TEST
+START_TEST (test_create)
+{
+ int err;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ ck_assert_ptr_ne (c, NULL);
+
+ ck_assert_uint_eq (c->args.interface_id, args.interface_id);
+ ck_assert_uint_eq (c->args.is_master, args.is_master);
+ ck_assert_uint_eq (c->args.mode, args.mode);
+
+ ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
+ ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
+ ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
+ ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
+
+ ck_assert_ptr_eq (c->msg_queue, NULL);
+ ck_assert_ptr_eq (c->regions, NULL);
+ ck_assert_ptr_eq (c->tx_queues, NULL);
+ ck_assert_ptr_eq (c->rx_queues, NULL);
+
+ ck_assert_int_eq (c->fd, -1);
+
+ ck_assert_ptr_ne (c->on_connect, NULL);
+ ck_assert_ptr_ne (c->on_disconnect, NULL);
+ ck_assert_ptr_ne (c->on_interrupt, NULL);
+
+ ck_assert_str_eq (c->args.interface_name, args.interface_name);
+ ck_assert_str_eq (c->args.instance_name, args.instance_name);
+ ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
+
+ struct itimerspec timer;
+ timerfd_gettime (lm->timerfd, &timer);
+
+ ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
+ "timerfd not armed!");
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_create_master)
+{
+ int err, rv;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.is_master = 1;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ ck_assert_ptr_ne (c, NULL);
+
+ ck_assert_uint_eq (c->args.interface_id, args.interface_id);
+ ck_assert_uint_eq (c->args.is_master, args.is_master);
+ ck_assert_uint_eq (c->args.mode, args.mode);
+
+ ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
+ ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
+ ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
+ ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
+
+ ck_assert_ptr_eq (c->msg_queue, NULL);
+ ck_assert_ptr_eq (c->regions, NULL);
+ ck_assert_ptr_eq (c->tx_queues, NULL);
+ ck_assert_ptr_eq (c->rx_queues, NULL);
+
+ ck_assert_int_eq (c->fd, -1);
+
+ ck_assert_ptr_ne (c->on_connect, NULL);
+ ck_assert_ptr_ne (c->on_disconnect, NULL);
+ ck_assert_ptr_ne (c->on_interrupt, NULL);
+
+ ck_assert_str_eq (c->args.interface_name, args.interface_name);
+ ck_assert_str_eq (c->args.instance_name, args.instance_name);
+ ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
+
+ struct stat file_stat;
+
+ rv = stat (SOCKET_FILENAME, &file_stat);
+ ck_assert_int_eq (rv, 0);
+
+ ck_assert (S_ISSOCK (file_stat.st_mode));
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_create_mult)
+{
+ int err;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_handle_t conn1 = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ args.interface_id = 1;
+
+ if ((err = memif_create (&conn1, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+ memif_connection_t *c1 = (memif_connection_t *) conn1;
+
+ ck_assert_ptr_ne (c, NULL);
+ ck_assert_ptr_ne (c1, NULL);
+
+ ck_assert_uint_eq (c->args.interface_id, 0);
+ ck_assert_uint_eq (c->args.is_master, args.is_master);
+ ck_assert_uint_eq (c->args.mode, args.mode);
+ ck_assert_uint_eq (c1->args.interface_id, 1);
+ ck_assert_uint_eq (c1->args.is_master, args.is_master);
+ ck_assert_uint_eq (c1->args.mode, args.mode);
+
+ ck_assert_uint_eq (c->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
+ ck_assert_uint_eq (c->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
+ ck_assert_uint_eq (c->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
+ ck_assert_uint_eq (c->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
+ ck_assert_uint_eq (c1->args.num_s2m_rings, MEMIF_DEFAULT_TX_QUEUES);
+ ck_assert_uint_eq (c1->args.num_m2s_rings, MEMIF_DEFAULT_RX_QUEUES);
+ ck_assert_uint_eq (c1->args.buffer_size, MEMIF_DEFAULT_BUFFER_SIZE);
+ ck_assert_uint_eq (c1->args.log2_ring_size, MEMIF_DEFAULT_LOG2_RING_SIZE);
+
+ ck_assert_ptr_eq (c->msg_queue, NULL);
+ ck_assert_ptr_eq (c->regions, NULL);
+ ck_assert_ptr_eq (c->tx_queues, NULL);
+ ck_assert_ptr_eq (c->rx_queues, NULL);
+ ck_assert_ptr_eq (c1->msg_queue, NULL);
+ ck_assert_ptr_eq (c1->regions, NULL);
+ ck_assert_ptr_eq (c1->tx_queues, NULL);
+ ck_assert_ptr_eq (c1->rx_queues, NULL);
+
+ ck_assert_int_eq (c->fd, -1);
+ ck_assert_int_eq (c1->fd, -1);
+
+ ck_assert_ptr_ne (c->on_connect, NULL);
+ ck_assert_ptr_ne (c->on_disconnect, NULL);
+ ck_assert_ptr_ne (c->on_interrupt, NULL);
+ ck_assert_ptr_ne (c1->on_connect, NULL);
+ ck_assert_ptr_ne (c1->on_disconnect, NULL);
+ ck_assert_ptr_ne (c1->on_interrupt, NULL);
+
+ ck_assert_str_eq (c->args.interface_name, args.interface_name);
+ ck_assert_str_eq (c->args.instance_name, args.instance_name);
+ ck_assert_str_eq (c->args.socket_filename, SOCKET_FILENAME);
+ ck_assert_str_eq (c1->args.interface_name, args.interface_name);
+ ck_assert_str_eq (c1->args.instance_name, args.instance_name);
+ ck_assert_str_eq (c1->args.socket_filename, SOCKET_FILENAME);
+
+ struct itimerspec timer;
+ timerfd_gettime (lm->timerfd, &timer);
+
+ ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
+ "timerfd not armed!");
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_control_fd_handler)
+{
+ int err;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ if ((err =
+ memif_control_fd_handler (lm->timerfd,
+ MEMIF_FD_EVENT_READ)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_NO_FILE, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ register_fd_ready_fn (c, read_fn, write_fn, error_fn);
+ c->fd = 69;
+ lm->control_list[0].key = c->fd;
+ lm->control_list[0].data_struct = c;
+
+ if ((err =
+ memif_control_fd_handler (c->fd,
+ MEMIF_FD_EVENT_READ)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert (ready_called & read_call);
+
+ if ((err =
+ memif_control_fd_handler (c->fd,
+ MEMIF_FD_EVENT_WRITE)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert (ready_called & write_call);
+
+ if ((err =
+ memif_control_fd_handler (c->fd,
+ MEMIF_FD_EVENT_ERROR)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert (ready_called & error_call);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_buffer_alloc)
+{
+ int err, i;
+ uint8_t qid;
+ uint16_t buf;
+ memif_buffer_t *bufs;
+ uint16_t max_buf = 10;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ c->fd = 69;
+
+ /* test buffer allocation qid 0 (positive) */
+
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ qid = 0;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_uint_eq (bufs[i].buffer_len, MEMIF_DEFAULT_BUFFER_SIZE);
+
+ /* test buffer allocation qid 1 (positive) */
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ qid = 1;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_uint_eq (bufs[i].buffer_len, MEMIF_DEFAULT_BUFFER_SIZE);
+
+ /* test buffer allocation qid 2 (negative) */
+
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ qid = 2;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ free (bufs);
+ bufs = NULL;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_tx_burst)
+{
+ int err, i;
+ uint16_t max_buf = 10, buf, tx;
+ uint8_t qid;
+ memif_buffer_t *bufs;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ c->fd = 69;
+
+ /* test transmit qid 0 (positive) */
+
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+ qid = 0;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_uint_eq (bufs[i].buffer_len, MEMIF_DEFAULT_BUFFER_SIZE);
+
+ if ((err =
+ memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (tx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_eq (bufs[i].data, NULL);
+
+ /* test transmit qid 1 (positive) */
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+ qid = 1;
+ if ((err =
+ memif_buffer_alloc (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_uint_eq (bufs[i].buffer_len, MEMIF_DEFAULT_BUFFER_SIZE);
+
+ if ((err =
+ memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (tx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_eq (bufs[i].data, NULL);
+
+ /* test transmit qid 2 (negative) */
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+ qid = 2;
+ if ((err =
+ memif_tx_burst (conn, qid, bufs, max_buf, &tx)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+ free (bufs);
+ bufs = NULL;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_rx_burst)
+{
+ int err, i;
+ uint16_t max_buf = 10, buf, rx;
+ uint8_t qid;
+ memif_buffer_t *bufs;
+ memif_queue_t *mq;
+ memif_ring_t *ring;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ c->fd = 69;
+
+ /* test receive qid 0 (positive) */
+ qid = 0;
+ mq = &c->rx_queues[qid];
+ ring = mq->ring;
+ ring->head += max_buf;
+
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (rx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_ne (bufs[i].data, NULL);
+
+ /* test receive qid 1 (positive) */
+ qid = 1;
+ mq = &c->rx_queues[qid];
+ ring = mq->ring;
+ ring->head += max_buf;
+
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (rx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_ne (bufs[i].data, NULL);
+
+ /* test receive qid 2 (negative) */
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+ free (bufs);
+ bufs = NULL;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_buffer_free)
+{
+ int err, i;
+ uint16_t max_buf = 10, buf, rx;
+ uint8_t qid;
+ memif_buffer_t *bufs;
+ memif_queue_t *mq;
+ memif_ring_t *ring;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ c->fd = 69;
+
+ /* test buffer free qid 0 (positive) */
+ qid = 0;
+ mq = &c->rx_queues[qid];
+ ring = mq->ring;
+ ring->head += 10;
+
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (rx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_ne (bufs[i].data, NULL);
+
+ if ((err =
+ memif_buffer_free (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_eq (bufs[i].data, NULL);
+ ck_assert_uint_eq (ring->head, ring->tail);
+
+ /* test buffer free qid 1 (positive) */
+ qid = 1;
+ mq = &c->rx_queues[qid];
+ ring = mq->ring;
+ ring->head += 10;
+
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_rx_burst (conn, qid, bufs, max_buf, &rx)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (rx, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_ne (bufs[i].data, NULL);
+
+ if ((err =
+ memif_buffer_free (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (buf, max_buf);
+ for (i = 0; i < max_buf; i++)
+ ck_assert_ptr_eq (bufs[i].data, NULL);
+ ck_assert_uint_eq (ring->head, ring->tail);
+
+
+ /* test buffer free qid 2 (negative) */
+ qid = 2;
+ free (bufs);
+ bufs = malloc (sizeof (memif_buffer_t) * max_buf);
+
+ if ((err =
+ memif_buffer_free (conn, qid, bufs, max_buf,
+ &buf)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_QID, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+ free (bufs);
+ bufs = NULL;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_get_details)
+{
+ int err, i;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_details_t md;
+ memset (&md, 0, sizeof (md));
+ ssize_t buflen = 2048;
+ char *buf = malloc (buflen);
+ memset (buf, 0, buflen);
+
+ if ((err = memif_get_details (conn, &md, buf, buflen)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_str_eq (md.if_name, c->args.interface_name);
+ ck_assert_str_eq (md.inst_name, c->args.instance_name);
+ ck_assert_str_eq (md.remote_if_name, c->remote_if_name);
+ ck_assert_str_eq (md.remote_inst_name, c->remote_name);
+ ck_assert_str_eq (md.secret, c->args.secret);
+ ck_assert_str_eq (md.socket_filename, c->args.socket_filename);
+
+ ck_assert_uint_eq (md.id, c->args.interface_id);
+ ck_assert_uint_ne (md.role, c->args.is_master);
+ ck_assert_uint_eq (md.mode, c->args.mode);
+ for (i = 0; i < md.rx_queues_num; i++)
+ {
+ ck_assert_uint_eq (md.rx_queues[i].qid, i);
+ ck_assert_uint_eq (md.rx_queues[i].ring_size,
+ (1 << c->args.log2_ring_size));
+ ck_assert_uint_eq (md.rx_queues[i].buffer_size, c->args.buffer_size);
+ }
+ for (i = 0; i < md.tx_queues_num; i++)
+ {
+ ck_assert_uint_eq (md.tx_queues[i].qid, i);
+ ck_assert_uint_eq (md.tx_queues[i].ring_size,
+ (1 << c->args.log2_ring_size));
+ ck_assert_uint_eq (md.tx_queues[i].buffer_size, c->args.buffer_size);
+ }
+ ck_assert_uint_eq (md.link_up_down, 0);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_init_regions_and_queues)
+{
+ int err;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_ptr_ne (c->regions, NULL);
+ ck_assert_ptr_ne (c->tx_queues, NULL);
+ ck_assert_ptr_ne (c->rx_queues, NULL);
+
+ ck_assert_ptr_ne (c->regions->shm, NULL);
+ ck_assert_ptr_ne (c->tx_queues->ring, NULL);
+ ck_assert_ptr_ne (c->rx_queues->ring, NULL);
+
+ ck_assert_int_ne (c->regions->fd, -1);
+ ck_assert_uint_eq (c->tx_queues->ring->cookie, MEMIF_COOKIE);
+ ck_assert_uint_eq (c->rx_queues->ring->cookie, MEMIF_COOKIE);
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_connect1)
+{
+ int err;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_connect1 (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST
+START_TEST (test_disconnect_internal)
+{
+ int err;
+ ready_called = 0;
+ memif_conn_handle_t conn = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+ args.num_s2m_rings = 2;
+ args.num_m2s_rings = 2;
+
+ libmemif_main_t *lm = &libmemif_main;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ strncpy ((char *) args.interface_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err = memif_create (&conn, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *c = (memif_connection_t *) conn;
+
+ c->run_args.num_s2m_rings = 2;
+ c->run_args.num_m2s_rings = 2;
+ c->run_args.log2_ring_size = 10;
+ c->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_disconnect_internal (c)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_int_eq (c->fd, -1);
+
+ ck_assert_ptr_eq (c->tx_queues, NULL);
+ ck_assert_ptr_eq (c->rx_queues, NULL);
+ ck_assert_ptr_eq (c->regions, NULL);
+ ck_assert_ptr_eq (c->msg_queue, NULL);
+
+ struct itimerspec timer;
+ timerfd_gettime (lm->timerfd, &timer);
+
+ ck_assert_msg (timer.it_interval.tv_sec == lm->arm.it_interval.tv_sec,
+ "timerfd not armed!");
+
+ if (lm->timerfd > 0)
+ close (lm->timerfd);
+ lm->timerfd = -1;
+
+ memif_delete (&conn);
+ ck_assert_ptr_eq (conn, NULL);
+}
+
+END_TEST Suite * main_suite ()
+{
+ Suite *s;
+
+ TCase *tc_api;
+ TCase *tc_internal;
+
+ /* create main test suite */
+ s = suite_create ("Libmemif main");
+
+ /* create api test case */
+ tc_api = tcase_create ("Api calls");
+ /* add tests to test case */
+ tcase_add_test (tc_api, test_init);
+ tcase_add_test (tc_api, test_init_epoll);
+ tcase_add_test (tc_api, test_create);
+ tcase_add_test (tc_api, test_create_master);
+ tcase_add_test (tc_api, test_create_mult);
+ tcase_add_test (tc_api, test_control_fd_handler);
+ tcase_add_test (tc_api, test_buffer_alloc);
+ tcase_add_test (tc_api, test_tx_burst);
+ tcase_add_test (tc_api, test_rx_burst);
+ tcase_add_test (tc_api, test_buffer_free);
+ tcase_add_test (tc_api, test_get_details);
+
+ /* create internal test case */
+ tc_internal = tcase_create ("Internal");
+ /* add tests to test case */
+ tcase_add_test (tc_internal, test_init_regions_and_queues);
+ tcase_add_test (tc_internal, test_connect1);
+ tcase_add_test (tc_internal, test_disconnect_internal);
+
+ /* add test cases to test suite */
+ suite_add_tcase (s, tc_api);
+ suite_add_tcase (s, tc_internal);
+
+ /* return main test suite to test runner */
+ return s;
+}
diff --git a/extras/libmemif/test/main_test.h b/extras/libmemif/test/main_test.h
new file mode 100644
index 00000000000..300d8a8e46b
--- /dev/null
+++ b/extras/libmemif/test/main_test.h
@@ -0,0 +1,25 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#ifndef _MAIN_TEST_H_
+#define _MAIN_TEST_H_
+
+#include <unit_test.h>
+
+Suite *main_suite ();
+
+#endif /* _MAIN_TEST_H_ */
diff --git a/extras/libmemif/test/socket_test.c b/extras/libmemif/test/socket_test.c
new file mode 100644
index 00000000000..f148495afb2
--- /dev/null
+++ b/extras/libmemif/test/socket_test.c
@@ -0,0 +1,625 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#include <socket_test.h>
+
+#include <memif_private.h>
+#include <socket.h>
+
+static int
+get_queue_len (memif_msg_queue_elt_t * q)
+{
+ int r = 0;
+ memif_msg_queue_elt_t *c = q;
+ while (c != NULL)
+ {
+ r++;
+ c = c->next;
+ }
+ return r;
+}
+
+static void
+queue_free (memif_msg_queue_elt_t ** e)
+{
+ if (*e == NULL)
+ return;
+ queue_free (&(*e)->next);
+ free (*e);
+ *e = NULL;
+ return;
+}
+
+START_TEST (test_msg_queue)
+{
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ conn.fd = -1;
+
+ int i, len = 10;
+
+ for (i = 0; i < len; i++)
+ {
+ if (i % 2)
+ memif_msg_enq_ack (&conn);
+ else
+ memif_msg_enq_init (&conn);
+ }
+
+ ck_assert_int_eq (len, get_queue_len (conn.msg_queue));
+
+ int pop = 6;
+
+ for (i = 0; i < pop; i++)
+ {
+ if (i % 2)
+ {
+ ck_assert_uint_eq (conn.msg_queue->msg.type, MEMIF_MSG_TYPE_ACK);
+ }
+ else
+ {
+ ck_assert_uint_eq (conn.msg_queue->msg.type, MEMIF_MSG_TYPE_INIT);
+ }
+ conn.flags |= MEMIF_CONNECTION_FLAG_WRITE;
+ /* function will return -1 because no socket is created */
+ memif_conn_fd_write_ready (&conn);
+ }
+
+ ck_assert_int_eq ((len - pop), get_queue_len (conn.msg_queue));
+
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_ack)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+
+ if ((err = memif_msg_enq_ack (&conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_ACK);
+ ck_assert_int_eq (e->fd, -1);
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_init)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+
+ conn.args.interface_id = 69;
+ conn.args.mode = 0;
+
+ strncpy ((char *) conn.args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+ strncpy ((char *) conn.args.secret, TEST_SECRET, strlen (TEST_SECRET));
+
+ if ((err = memif_msg_enq_init (&conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_INIT);
+ ck_assert_int_eq (e->fd, -1);
+
+ memif_msg_init_t *i = &e->msg.init;
+
+ ck_assert_uint_eq (i->version, MEMIF_VERSION);
+ ck_assert_uint_eq (i->id, conn.args.interface_id);
+ ck_assert_uint_eq (i->mode, conn.args.mode);
+ ck_assert_str_eq (i->name, conn.args.instance_name);
+ ck_assert_str_eq (i->secret, conn.args.secret);
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_add_region)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ conn.regions = (memif_region_t *) malloc (sizeof (memif_region_t));
+ memif_region_t *mr = conn.regions;
+ mr->fd = 5;
+ mr->region_size = 2048;
+ uint8_t region_index = 0;
+
+ if ((err =
+ memif_msg_enq_add_region (&conn, region_index)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_ADD_REGION);
+ ck_assert_int_eq (e->fd, mr->fd);
+
+ memif_msg_add_region_t *ar = &e->msg.add_region;
+
+ ck_assert_uint_eq (ar->index, region_index);
+ ck_assert_uint_eq (ar->size, mr->region_size);
+
+ free (conn.regions);
+ conn.regions = NULL;
+ mr = NULL;
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_add_ring)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ conn.rx_queues = (memif_queue_t *) malloc (sizeof (memif_queue_t));
+ conn.tx_queues = (memif_queue_t *) malloc (sizeof (memif_queue_t));
+
+ memif_queue_t *mq = conn.tx_queues;
+ uint8_t dir = MEMIF_RING_S2M;
+ mq->int_fd = 5;
+ mq->offset = 0;
+ mq->log2_ring_size = 10;
+
+ if ((err = memif_msg_enq_add_ring (&conn, 0, dir)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_ADD_RING);
+ ck_assert_int_eq (e->fd, mq->int_fd);
+
+ memif_msg_add_ring_t *ar = &e->msg.add_ring;
+
+ ck_assert_uint_eq (ar->index, 0);
+ ck_assert_uint_eq (ar->offset, mq->offset);
+ ck_assert_uint_eq (ar->log2_ring_size, mq->log2_ring_size);
+ ck_assert (ar->flags & MEMIF_MSG_ADD_RING_FLAG_S2M);
+
+ dir = MEMIF_RING_M2S;
+ if ((err = memif_msg_enq_add_ring (&conn, 0, dir)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_connect)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ memset (conn.args.interface_name, 0, sizeof (conn.args.interface_name));
+ strncpy ((char *) conn.args.interface_name, TEST_IF_NAME,
+ strlen (TEST_IF_NAME));
+
+ if ((err = memif_msg_enq_connect (&conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_CONNECT);
+ ck_assert_int_eq (e->fd, -1);
+ ck_assert_str_eq (e->msg.connect.if_name, TEST_IF_NAME);
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_enq_connected)
+{
+ int err;
+ memif_connection_t conn;
+ conn.msg_queue = NULL;
+ memset (conn.args.interface_name, 0, sizeof (conn.args.interface_name));
+ strncpy ((char *) conn.args.interface_name, TEST_IF_NAME,
+ strlen (TEST_IF_NAME));
+
+ if ((err = memif_msg_enq_connected (&conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_queue_elt_t *e = conn.msg_queue;
+
+ ck_assert_uint_eq (e->msg.type, MEMIF_MSG_TYPE_CONNECTED);
+ ck_assert_int_eq (e->fd, -1);
+ ck_assert_str_eq (e->msg.connect.if_name, TEST_IF_NAME);
+ queue_free (&conn.msg_queue);
+}
+
+END_TEST
+START_TEST (test_send)
+{
+ int err;
+ int fd = -1, afd = 5;
+ memif_msg_t msg;
+ memset (&msg, 0, sizeof (msg));
+
+ if ((err = memif_msg_send (fd, &msg, afd)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_BAD_FD,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_send_hello)
+{
+ int err;
+ memif_connection_t conn;
+ conn.fd = -1;
+ memset (conn.args.instance_name, 0, sizeof (conn.args.instance_name));
+ strncpy ((char *) conn.args.instance_name, TEST_APP_NAME,
+ strlen (TEST_APP_NAME));
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_msg_send_hello (conn.fd)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_BAD_FD,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_send_disconnect)
+{
+ int err;
+ memif_connection_t conn;
+ conn.fd = -1;
+
+ /* only possible fail if memif_msg_send fails... */
+ /* obsolete without socket */
+ if ((err =
+ memif_msg_send_disconnect (conn.fd, "unit_test_dc",
+ 0)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_BAD_FD, "err code: %u, err msg: %s", err,
+ memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_recv_hello)
+{
+ int err;
+ memif_connection_t conn;
+ memif_msg_t msg;
+
+ memif_msg_hello_t *h = &msg.hello;
+
+ msg.type = MEMIF_MSG_TYPE_HELLO;
+
+ h->min_version = MEMIF_VERSION;
+ h->max_version = MEMIF_VERSION;
+ h->max_s2m_ring = 1;
+ h->max_m2s_ring = 1;
+ h->max_log2_ring_size = 14;
+ strncpy ((char *) h->name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ memset (conn.remote_name, 0, sizeof (conn.remote_name));
+
+ conn.args.num_s2m_rings = 4;
+ conn.args.num_m2s_rings = 6;
+ conn.args.log2_ring_size = 10;
+
+ if ((err = memif_msg_receive_hello (&conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_uint_eq (conn.run_args.num_s2m_rings, 2);
+ ck_assert_uint_eq (conn.run_args.num_m2s_rings, 2);
+ ck_assert_uint_eq (conn.run_args.log2_ring_size, 10);
+ ck_assert_str_eq (conn.remote_name, TEST_IF_NAME);
+
+ h->max_version = 9;
+ if ((err = memif_msg_receive_hello (&conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_PROTO,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_recv_init)
+{
+ int err;
+ memif_connection_t conn;
+
+ conn.args.interface_id = 69;
+ conn.args.is_master = 1;
+ conn.fd = -1;
+ conn.args.mode = 0;
+ memset (conn.args.secret, '\0', 24);
+ strncpy ((char *) conn.args.secret, TEST_SECRET, strlen (TEST_SECRET));
+
+ memif_msg_t msg;
+
+ memif_msg_init_t *i = &msg.init;
+
+ msg.type = MEMIF_MSG_TYPE_INIT;
+
+ i->version = MEMIF_VERSION;
+ i->id = 69;
+ i->mode = 0;
+ memset (i->name, '\0', 32);
+ memset (i->secret, '\0', 24);
+ strncpy ((char *) i->name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+ strncpy ((char *) i->secret, TEST_SECRET, strlen (TEST_SECRET));
+
+ memif_socket_t ms;
+ ms.interface_list_len = 1;
+ ms.interface_list = malloc (sizeof (memif_list_elt_t));
+ memif_list_elt_t elt;
+ elt.key = 69;
+ elt.data_struct = &conn;
+ add_list_elt (&elt, &ms.interface_list, &ms.interface_list_len);
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ i->version = 9;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_PROTO,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ i->version = MEMIF_VERSION;
+
+ i->id = 78;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_ID,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ i->id = 69;
+
+ i->mode = 1;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_MODE,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ i->mode = 0;
+
+ i->secret[0] = '\0';
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_SECRET,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ strncpy ((char *) i->secret, TEST_SECRET, strlen (TEST_SECRET));
+
+ conn.args.is_master = 0;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_ACCSLAVE,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+ conn.args.is_master = 1;
+
+ conn.fd = 5;
+ if ((err = memif_msg_receive_init (&ms, -1, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg ((err == MEMIF_ERR_ALRCONN) || (err == MEMIF_ERR_BAD_FD),
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+}
+
+END_TEST
+START_TEST (test_recv_add_region)
+{
+ int err;
+ memif_connection_t conn;
+ conn.regions = NULL;
+ memif_msg_t msg;
+ msg.type = MEMIF_MSG_TYPE_ADD_REGION;
+ msg.add_region.size = 2048;
+ msg.add_region.index = 0;
+
+ int fd = 5;
+
+ if ((err =
+ memif_msg_receive_add_region (&conn, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_region_t *mr = conn.regions;
+
+ ck_assert_uint_eq (mr->fd, fd);
+ ck_assert_uint_eq (mr->region_size, 2048);
+ ck_assert_ptr_eq (mr->shm, NULL);
+}
+
+END_TEST
+START_TEST (test_recv_add_ring)
+{
+ int err;
+ memif_connection_t conn;
+ int fd = 5;
+ memif_msg_t msg;
+ conn.args.num_s2m_rings = 2;
+ conn.args.num_m2s_rings = 2;
+ conn.rx_queues = NULL;
+ conn.tx_queues = NULL;
+
+ msg.type = MEMIF_MSG_TYPE_ADD_RING;
+ memif_msg_add_ring_t *ar = &msg.add_ring;
+
+ ar->log2_ring_size = 10;
+ ar->region = 0;
+ ar->offset = 0;
+ ar->flags = 0;
+ ar->flags |= MEMIF_MSG_ADD_RING_FLAG_S2M;
+ ar->index = 1;
+
+ if ((err =
+ memif_msg_receive_add_ring (&conn, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+
+ ar->offset = 2048;
+ ar->flags &= ~MEMIF_MSG_ADD_RING_FLAG_S2M;
+
+ if ((err =
+ memif_msg_receive_add_ring (&conn, &msg, fd)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+}
+
+END_TEST
+START_TEST (test_recv_connect)
+{
+ int err;
+ memif_conn_handle_t c = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+
+ args.interface_id = 0;
+ args.is_master = 0;
+ args.mode = 0;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_create (&c, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *conn = (memif_connection_t *) c;
+
+ conn->run_args.num_s2m_rings = 1;
+ conn->run_args.num_m2s_rings = 1;
+ conn->run_args.log2_ring_size = 10;
+ conn->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_t msg;
+ memset (&msg, 0, sizeof (msg));
+ msg.type = MEMIF_MSG_TYPE_CONNECT;
+
+ memset (msg.connect.if_name, 0, sizeof (msg.connect.if_name));
+ strncpy ((char *) msg.connect.if_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+
+ if ((err = memif_msg_receive_connect (conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_str_eq (conn->remote_if_name, TEST_IF_NAME);
+}
+
+END_TEST
+START_TEST (test_recv_connected)
+{
+ int err;
+ memif_conn_handle_t c = NULL;
+ memif_conn_args_t args;
+ memset (&args, 0, sizeof (args));
+
+ args.interface_id = 0;
+ args.is_master = 0;
+ args.mode = 0;
+
+ if ((err =
+ memif_init (control_fd_update, TEST_APP_NAME)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ if ((err = memif_create (&c, &args, on_connect,
+ on_disconnect, on_interrupt,
+ NULL)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_connection_t *conn = (memif_connection_t *) c;
+
+ conn->run_args.num_s2m_rings = 1;
+ conn->run_args.num_m2s_rings = 1;
+ conn->run_args.log2_ring_size = 10;
+ conn->run_args.buffer_size = 2048;
+
+ if ((err = memif_init_regions_and_queues (conn)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ memif_msg_t msg;
+ memset (&msg, 0, sizeof (msg));
+ msg.type = MEMIF_MSG_TYPE_CONNECT;
+
+ memset (msg.connect.if_name, 0, sizeof (msg.connect.if_name));
+ strncpy ((char *) msg.connect.if_name, TEST_IF_NAME, strlen (TEST_IF_NAME));
+
+ if ((err = memif_msg_receive_connected (conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_abort_msg ("err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_str_eq (conn->remote_if_name, TEST_IF_NAME);
+}
+
+END_TEST
+START_TEST (test_recv_disconnect)
+{
+ int err;
+ memif_connection_t conn;
+ memif_msg_t msg;
+ msg.type = MEMIF_MSG_TYPE_DISCONNECT;
+ memset (msg.disconnect.string, 0, sizeof (msg.disconnect.string));
+ strncpy ((char *) msg.disconnect.string, "unit_test_dc", 12);
+
+ if ((err = memif_msg_receive_disconnect (&conn, &msg)) != MEMIF_ERR_SUCCESS)
+ ck_assert_msg (err == MEMIF_ERR_DISCONNECT,
+ "err code: %u, err msg: %s", err, memif_strerror (err));
+
+ ck_assert_str_eq (conn.remote_disconnect_string, "unit_test_dc");
+}
+
+END_TEST Suite * socket_suite ()
+{
+ Suite *s;
+ TCase *tc_msg_queue;
+ TCase *tc_msg_enq;
+ TCase *tc_msg_send;
+ TCase *tc_msg_recv;
+
+ /* create socket test suite */
+ s = suite_create ("Socket messaging");
+
+ /* create msg queue test case */
+ tc_msg_queue = tcase_create ("Message queue");
+ /* add tests to test case */
+ tcase_add_test (tc_msg_queue, test_msg_queue);
+
+ /* create msg enq test case */
+ tc_msg_enq = tcase_create ("Message enqueue");
+ /* add tests to test case */
+ tcase_add_test (tc_msg_enq, test_enq_ack);
+ tcase_add_test (tc_msg_enq, test_enq_init);
+ tcase_add_test (tc_msg_enq, test_enq_add_region);
+ tcase_add_test (tc_msg_enq, test_enq_add_ring);
+ tcase_add_test (tc_msg_enq, test_enq_connect);
+ tcase_add_test (tc_msg_enq, test_enq_connected);
+
+ /* create msg send test case */
+ tc_msg_send = tcase_create ("Message send");
+ /* add tests to test case */
+ tcase_add_test (tc_msg_send, test_send);
+ tcase_add_test (tc_msg_send, test_send_hello);
+ tcase_add_test (tc_msg_send, test_send_disconnect);
+
+ /* create msg recv test case */
+ tc_msg_recv = tcase_create ("Message receive");
+ /* add tests to test case */
+ tcase_add_test (tc_msg_recv, test_recv_hello);
+ tcase_add_test (tc_msg_recv, test_recv_init);
+ tcase_add_test (tc_msg_recv, test_recv_add_region);
+ tcase_add_test (tc_msg_recv, test_recv_add_ring);
+ tcase_add_test (tc_msg_recv, test_recv_connect);
+ tcase_add_test (tc_msg_recv, test_recv_connected);
+ tcase_add_test (tc_msg_recv, test_recv_disconnect);
+
+ /* add test cases to test suite */
+ suite_add_tcase (s, tc_msg_queue);
+ suite_add_tcase (s, tc_msg_enq);
+ suite_add_tcase (s, tc_msg_send);
+ suite_add_tcase (s, tc_msg_recv);
+
+ /* return socket test suite to test runner */
+ return s;
+}
diff --git a/extras/libmemif/test/socket_test.h b/extras/libmemif/test/socket_test.h
new file mode 100644
index 00000000000..02ec69cfbd7
--- /dev/null
+++ b/extras/libmemif/test/socket_test.h
@@ -0,0 +1,25 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#ifndef _SOCKET_TEST_H_
+#define _SOCKET_TEST_H_
+
+#include <unit_test.h>
+
+Suite *socket_suite ();
+
+#endif /* _SOCKET_TEST_H_ */
diff --git a/extras/libmemif/test/unit_test.c b/extras/libmemif/test/unit_test.c
new file mode 100644
index 00000000000..a305de93fbe
--- /dev/null
+++ b/extras/libmemif/test/unit_test.c
@@ -0,0 +1,63 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#include <main_test.h>
+#include <socket_test.h>
+
+int
+on_connect (memif_conn_handle_t conn, void *ctx)
+{
+ return 0;
+}
+
+int
+on_disconnect (memif_conn_handle_t conn, void *ctx)
+{
+ return 0;
+}
+
+int
+on_interrupt (memif_conn_handle_t conn, void *ctx, uint16_t qid)
+{
+ return 0;
+}
+
+int
+control_fd_update (int fd, uint8_t events)
+{
+ return 0;
+}
+
+int
+main (void)
+{
+ int num_fail;
+ Suite *main, *socket;
+ SRunner *sr;
+
+ main = main_suite ();
+ socket = socket_suite ();
+
+ sr = srunner_create (main);
+
+ srunner_add_suite (sr, socket);
+
+ srunner_run_all (sr, CK_VERBOSE);
+ num_fail = srunner_ntests_failed (sr);
+ srunner_free (sr);
+ return (num_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/extras/libmemif/test/unit_test.h b/extras/libmemif/test/unit_test.h
new file mode 100644
index 00000000000..fae3cbaae2a
--- /dev/null
+++ b/extras/libmemif/test/unit_test.h
@@ -0,0 +1,38 @@
+/*
+ *------------------------------------------------------------------
+ * Copyright (c) 2017 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.
+ *------------------------------------------------------------------
+ */
+
+#ifndef _UNIT_TEST_H_
+#define _UNIT_TEST_H_
+
+#include <stdlib.h>
+#include <check.h>
+
+#include <libmemif.h>
+
+#define TEST_APP_NAME "unit_test_app"
+#define TEST_IF_NAME "unit_test_if"
+#define TEST_SECRET "psst"
+
+int on_connect (memif_conn_handle_t conn, void *ctx);
+
+int on_disconnect (memif_conn_handle_t conn, void *ctx);
+
+int on_interrupt (memif_conn_handle_t conn, void *ctx, uint16_t qid);
+
+int control_fd_update (int fd, uint8_t events);
+
+#endif /* _UNIT_TEST_H_ */