Shared memory packet interface (memif) library

Change-Id: I5097462ae85acd705f19e92517c01094dba7565f
Signed-off-by: Jakub Grajciar <grajciar.jakub@gmail.com>
This commit is contained in:
Jakub Grajciar
2017-08-30 10:13:25 +02:00
committed by Damjan Marion
parent a4393be1a0
commit 7c5c40db2a
28 changed files with 11034 additions and 0 deletions

View File

@@ -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)

72
extras/libmemif/README.md Normal file
View File

@@ -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.

3
extras/libmemif/bootstrap Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
autoreconf -fis

View File

@@ -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])

View File

@@ -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

View File

@@ -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.

View File

@@ -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)

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

2427
extras/libmemif/doxygen.conf Normal file
View File

File diff suppressed because it is too large Load Diff

View File

@@ -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.

View File

@@ -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.

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -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;
}

View File

@@ -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_ */

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

1810
extras/libmemif/src/main.c Normal file
View File

File diff suppressed because it is too large Load Diff

185
extras/libmemif/src/memif.h Normal file
View File

@@ -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:
*/

View File

@@ -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_ */

View File

File diff suppressed because it is too large Load Diff

View File

@@ -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_ */

View File

File diff suppressed because it is too large Load Diff

View File

@@ -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_ */

View File

File diff suppressed because it is too large Load Diff

View File

@@ -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_ */

View File

@@ -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;
}

View File

@@ -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_ */