73 Commits

Author SHA1 Message Date
Mohsin Kazmi
7280e3f866 libmemif: add testing application
Type: test

This application creates two memif interfaces which connect
to an external application i.e. VPP.

Usage:
1) Start VPP with following config.
create interface memif id 0 master
create interface memif id 1 master
set int state memif0/0 up
set int state memif0/1 up
create packet-generator interface pg0
set int state pg0 up
create packet-generator interface pg1
set int state pg1 up

set int l2 xconn pg0 memif0/0
set int l2 xconn memif0/0 pg0
set int l2 xconn pg1 memif0/1
set int l2 xconn memif0/1 pg1

packet-generator new { \
  name memif           \
  limit -1             \
  node ethernet-input  \
  size 64-64           \
  interface pg0        \
  worker 0             \
  data {               \
    IP4: 42:01:0a:00:00:0a -> 02:fe:4b:6e:4d:c1 \
    UDP: 172.16.2.2 -> 172.16.0.2               \
    UDP: 1234 -> 1234                           \
      length 30 checksum 0 incrementing 1       \
  }                                             \
}

2) Compile and Run the test_app in another terminal.
mkdir -p extras/libmemif/build
cd extras/libmemif/build
cmake ..
make
sudo ./examples/test_app

3) Run in VPP cli
vpp# packet enable

4) Run monitor to see the throughput and pps
vpp# monitor interface memif0/0
Or
vpp# monitor interface memif0/1

Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: I4b9062fca8ad3020225adb7b1b09e5d66b1a7d48
2023-05-30 09:01:53 +00:00
Mohsin Kazmi
8a34484057 libmemif: fix the buffer size
Type: fix

Previously, libmemif can only use buffer size which
have to be power of 2. memif protocol does not enforce
this. This patch fixes this issue.

Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: Ic71e6a51685e2c2228c744920797064d4c7c65c9
2022-08-29 07:07:07 +00:00
Mohsin Kazmi
6e284ef6ce libmemif: add support for custom buffer-size and headroom in icmp example app
Type: improvement

Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: I2bdaee7938a3747e3217d6901ec3c66f1ee3da61
2022-08-29 07:05:23 +00:00
Mohsin Kazmi
8636a32041 libmemif: fix chain buffer support
Type: fix

This patch fixes chain buffer support as transmit side
missing to set the flag to the descriptor in case of
chain buffers.

Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: I73ff11be69a388f14fea39a19272d8eb76148fba
2022-07-25 14:03:48 +00:00
Daniel Béreš
c69655e3bd libmemif: timer causes spin at 100% cpu
In case of timer is set and expires:
1. timer_fd is readable and stay readable.
2. timer_fd is part of epoll_fd set. This makes epoll_pwait()
   calls return immediately instead of sleeping.

Type: fix

Signed-off-by: Daniel Béreš <dberes@cisco.com>
Change-Id: I9b228464fe45b83def9b182c885d6febf428049c
2022-04-26 15:46:00 +00:00
Jakub Grajciar
e74c04fc9f libmemif: refactor examples
- icmp_responder: responds to ICMPv4 and ARP requests
- loopback: connects two interfaces and sends a
  verification packet from master memif to slave memif
  where it is looped back
- loopback (reverse path): reverses direction of packet
  in loopback application (slave memif to master memif)

Type: refactor

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: Ie90aaa3367269408efb6c5d538ad5aa827432238
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
2022-03-28 22:34:33 +00:00
Jakub Grajciar
8caf9ece87 libmemif: reset memif buffer flags
Reset memif_buffer_t flags in memif_buffer_alloc and
memif_rx_burst

Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: If62ba510fad783afb9f7f58411562b6989fa1573
2021-12-07 18:11:47 +00:00
Matthew Giassa
93bca19f1e libmemif: fix gcc strict-proto error
- Changing function prototypes for a couple libmemif functions so that
  gcc will successfully compile with the "-Wstrict-prototypes" flag
  enabled.
- Re-ran unit tests via "make test" locally on Ubuntu 20.04 LTS x64.
  One issue (likely unrelated to patch):
  * Testcase name: Bidirectional Forwarding Detection (BFD)
    ERROR: put session admin-up and admin-down
    [test_bfd.BFD4TestCase.test_admin_up_down]

Type: fix
Change-Id: Ibcb7210873d39aec9348fe8ac7eebc78d089d8e0
Signed-off-by: Matthew Giassa <mgiassa@cisco.com>
2021-10-27 07:59:09 +00:00
Nathan Skrzypczak
8acc5ee907 libmemif: docs md->rst
Type: improvement

Change-Id: Ibebd2d47a4268189f11601d004073e4858548f25
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
2021-10-13 15:30:03 +00:00
Jakub Grajciar
87e90830b8 libmemif: update documentation
Type: refactor

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I0094ea8627cd8bcd5ea119c2fd48f077c8e2e4bb
2021-10-13 15:26:34 +00:00
Nathan Skrzypczak
814eee55fa libmemif: Fix abstract sockets
This fixes size computation when using
abstract sockets with libmemif

Type: fix

Change-Id: I3a686e4ff2132b9fb295bbe30633958dcfec672b
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
2021-09-29 14:49:45 +02:00
Jakub Grajciar
134f1e0225 libmemif: refactor connection establishment
per_thread_ namespace fuctionality replaced by memif socket.
Interfaces are grouped by memif socket which holds interface database.
Each thread can create it's unique memif socket. The path name
can be equal across threads so that the app only uses one
UNIX socket. In case of listener socket, listener fd
can be obtained and set using APIs.

This change allows:
  - No lookup on file descriptor events
    - improves interrupt handling
  - Loopback support (connect two interfaces in one app)
    - usefull for debugging and testing
  - Improves code readability by providing control channel
    abstraction for each interface and listener sockets

Type: refactor

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I1b8261042431c0376646ab4c4c831f6e59dd3eed
2021-09-27 14:35:45 +00:00
Jakub Grajciar
45cf1fc3f5 libmemif: remove per_thread_ namespace
Type: refactor

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: Ib5a88132ad28860553fc82f5aaaf84e0a1b8e8bf
2021-09-27 14:35:45 +00:00
Jakub Grajciar
9f99e9a60e libmemif: remove old examples
Type: refactor

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I2331f6fb43ca533afb32f7d448adda27b19689ac
2021-09-27 14:35:45 +00:00
Jakub Grajciar
24681606b9 libmemif: remove outdated unit tests
Type: refactor

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: Ie42c03980cf2cc0766308043d7d3ea5301a59b75
2021-09-27 14:35:45 +00:00
Andrew Yourtchenko
387a08a8be libmemif: fix the include for ssize_t
Change-Id: I83830e64fb0fc302474837ebfa4f8cb133b1dccf
Type: fix
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
2021-03-15 17:22:56 +00:00
Andrew Yourtchenko
085e8d4027 libmemif: add an include of sys/types.h header file
the ssize_t is defined there.

Change-Id: Ie46d196347ab91d0a92c15f331db14fe3b57061c
Type: fix
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
2021-03-12 09:01:04 +00:00
Jakub Grajciar
cef0cc1a07 libmemif: verify length of transmitted buffers
In memif_tx_burst verify that total buffer size
(data_offset + data_len) does not exceed buffer
size. If not valid returns MEMIF_ERR_INVAL_ARG.

Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: Ifae8f92344a401febbc1efd22c301356ccf83d44
2021-03-04 10:52:59 +00:00
Jakub Grajciar
57084e5408 libmemif: socket filename length 108
Dynamic size array was causing trouble in
strlcpy. LINUX allows for max 108 filename length,
so we can use that to make the array constant size.

Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I76b1fc41f9d93cfbc9ad11bdca0c96a1fc261e84
2021-03-04 09:09:08 +00:00
Andrew Yourtchenko
e5b7ca4bce libmemif: fix insecure uses of strncpy
A calling patterm of "strncpy(dst, src, strlen(src))" invites a lot of troubles.

However, even using the target size may result in a problem if the string is
longer, since then the termination is not done.

Use strlcpy(dst, src, sizeof(dst)), which will always null-terminate
the string.

Change-Id: I8ddaf3dc8380a78af08914e81849279dae7ab24a
Type: fix
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2021-02-08 10:27:06 +00:00
Jakub Grajciar
1421748e3c libmemif: set data offset for memif buffer
Update descriptor offset based on data pointer
in memif_buffer_t.
Slave only, master will not modify the descriptor.

Type: feature

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: Ice1e94cec366face650c58df81795f4dea727010
2021-02-08 10:26:54 +00:00
Jakub Grajciar
0dea94b45a libmemif: fix memif_refill_queue
Fix arithmetic error in memif_refill_queue., where
some of the buffers didn't get properly refilled.

Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I9815a8ac9b899216581452c352e75e2a0454cbce
2021-02-05 16:20:52 +00:00
Jakub Grajciar
47e68de222 libmemif: set next free buffer
Adds memif_set_next_free_buffer - set internal pointer
to next free descriptor for any tx queue.

Type: feature

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: Ia24345a886a52c25c1723c6dbce023f2aed4a42c
2021-02-05 16:20:37 +00:00
Jakub Grajciar
f35fef2446 libmemif: buffer enqueue refactor
Refactored memif_buffer_enq_tx - dequeue buffers from any queue (rx/tx) and
enqueue them to any tx queue.

Added memif_buffer_requeue - swap descriptors of provided buffers.

Type: refactor

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I8482824df920aaaf8325d52a297ed57a815aaba6
2021-01-21 13:33:44 +00:00
Paul Vinciguerra
6223766f96 libmemif: clean up typos
Type: style

Change-Id: I0d25d922312dfd60a665916cf47c3d2faa29ea49
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2020-12-04 22:48:07 +00:00
Nathan Skrzypczak
97158289bc docs: Fix create memif cli
Type: docs

Change-Id: I91a954abf77335e1ddcbd1468633d9d7980bbac2
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
2020-09-09 16:56:28 +00:00
Paul Vinciguerra
f4fbfd692f libmemif: cleanup typos
cleaned up typos in documetation while doing a read through.

Type: style

Change-Id: Id8abbd8d6297ee10490c12a8e62097224f7ec1e1
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2020-05-18 18:21:53 +00:00
Damjan Marion
599efc67e8 build: various improvements
- add option to install only host tools
- add option to specify lib and runtime dir

Type: improvement

Change-Id: I6356b52df459120fc9b0127948bae7679fb10e52
Signed-off-by: Damjan Marion <damarion@cisco.com>
2020-05-08 17:01:32 +00:00
Paul Vinciguerra
b5a575b092 docs: clean up make docs job
Type: docs

Change-Id: I9b5e5137eb4c1e89f6e8d7a278cd11a0fd496471
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
2020-05-06 15:13:09 +00:00
Jan Cavojsky
77a95cdce2 libmemif: don't consume rx queue interrupt, if memif_rx_burst fails
Type: fix

Signed-off-by: Jan Cavojsky <jan.cavojsky@pantheon.tech>
Change-Id: Ic6c15c88c80c4045c290cd78533be6f070c7470a
2020-03-21 12:12:13 +00:00
Jakub Grajciar
6f090fa1fa libmemif: memif_control_fd_update always pass context from libmemif_main
Event polling instance is always identified by libmemif main private context.
Fixes event polling handled by libmemif.

Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I51dcdb279b18f8ce97bad3b2695848e0b25a232d
2020-01-27 19:21:33 +00:00
Jakub Grajciar
718a19b8f9 libmemif: reset number of queues on disconnect
Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: If4df47b1109ac90d4d5834b3aa7d326f6b3761d2
2019-11-05 12:55:51 +00:00
Jakub Grajciar
bdf3ebe358 libmemif: prevent crash in case of invalid connection handle
Type: fix

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I803c86a48e0148ef143026a5cd93e4510c4f0611
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2019-09-09 13:02:13 +02:00
Jakub Grajciar
17f2a7bbf2 libmemif: introduce 'memif_per_thread_' namespace
APIs in 'memif_per_thread_' namespace are used to split the global
database into separate databases, to improve multi-thread use cases.

Using 'memif_per_thread_init' client can create separate libmemif
databases (libmemif_main_t). Client will reference these databases
using memif_per_thread_handle_t. Each database requires unique socket.
Created interface will be stored in the same database as the socket
passed in connection arguments.

Example code: extras/libmemif/examples/icmp_responder_3-1/main.c

Type: feature

Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I261563ecc34761a76e94f20c20015394398ddfd7
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2019-08-21 14:45:43 +00:00
Jakub Grajciar
272e2e456d libmemif: fix autoconnect
Type: fix

Change-Id: I426e210c47869904a01712b765db2356439f706f
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2019-07-26 14:51:59 +00:00
Jakub Grajciar
cbd179cd39 libmemif: fix chained buffer flag
fixes issue: MEMIF_DESC_FLAG_NEXT persisted when enqueueing
stored buffers

Type: fix

Change-Id: I9e973ed6e0339612fe1dd3e3bd80ed7c05093791
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2019-07-25 08:55:17 +00:00
Jakub Grajciar
12df497bb6 libmemif: version 3.0
Add support for multi-thread connection establishment.

- control_fd_update() callback now passes private context
  associated with updated file descriptor. File descriptor
  can belong to memif socket, memif connection or timerfd.
  In case of timerfd the context is NULL.

- memif_create_socket() new API. Creates memif socket
  handle to be passed to memif_create() in memif_conn_args_t.
  This API allows to pass private context whenever the file
  descriptor is updated.

- memif_delete_socket() new API. Deletes memif socket.
  Socket must not be in use by any interface.

Type: feature

Change-Id: I7ca4e4349595d4477195f1c32403d3e3a6eb5361
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2019-07-02 14:06:46 +00:00
Jakub Grajciar
389c82286d libmemif: icmp-responder example buffer management fix
Type: fix

Change-Id: Ieeb763f282ee929a121585747119f458c00056ae
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2019-07-01 15:17:13 +00:00
Benoît Ganne
49ee68443d build: add -Wall and -fno-common, fix reported issues
Type: refactor
Change-Id: I8489ccd54411c2aa9355439c5641dc31012c64a2
Signed-off-by: Benoît Ganne <bganne@cisco.com>
Signed-off-by: Damjan Marion <damarion@cisco.com>
2019-06-07 11:21:59 +00:00
Jim Thompson
f324dec0a3 fixing typos
Change-Id: I215e1e0208a073db80ec6f87695d734cf40fabe3
Signed-off-by: Jim Thompson <jim@netgate.com>
2019-04-08 21:54:17 +00:00
Jakub Grajciar
84b83776d3 libmemif: Connection request APIs
Add APIs that allow changing reconnect timer and request connection.
First connection request is automatically sent once slave interface is created.

Change-Id: Ie3558b7b94a780b046755f7f0ac6c3dcf07633e4
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2019-03-04 14:06:37 +00:00
Koichiro Den
33331edd3a libmemif: fix incorrect write leading to memory corruption
in the worst case scenario this leads to segfault in a hard-to-debug way.

Change-Id: I165adae0bd2dee26af777a2665c8c124d3a49808
Signed-off-by: Koichiro Den <den@klaipeden.com>
2019-01-04 19:55:33 +00:00
Mauro Sardara
ec0cc2cf05 Remove autotools files from extras/libmemif
Change-Id: I6c5f7ab5bb6c0022746d3feedd71b5981f31c7fb
Signed-off-by: Mauro Sardara <msardara+fdio@cisco.com>
2018-12-18 09:35:08 +00:00
Koichiro Den
be420e59e9 libmemif: fix possible segfault on memif_get_details
insufficient buflen does not mean immediate return but
fallthrough by design so assigning values to these
array elements should just be skipped in that case.

Change-Id: Iaa9718db073108e44a9b05e1c8ffb0725147ff1f
Signed-off-by: Koichiro Den <den@klaipeden.com>
2018-12-17 10:52:34 +00:00
msardara
8f554b793c Added CMake building system for libmemif
Added Cpack support for building libmemif DEB/RPM packages
Fixed compilation errors in libmemif test and examples

Change-Id: I59a237a4ca8eb08840857d5b0e666f3a8d74411d
Signed-off-by: msardara <msardara+fdio@cisco.com>
2018-12-17 09:25:18 +00:00
Jakub Grajciar
412e7b64f9 libmemif: external region bugfix
Change-Id: I7dbece80dda917ff78f53f8f4074132895aed316
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2018-09-27 18:32:22 +00:00
Jakub Grajciar
568cc4674e libmemif: slave connecting bugfix
in case first connecting slave fails continue connecting others
add disconnect string to memif details

Change-Id: I9d83db4724de1cab60786dca566e004016cf1e59
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2018-09-07 07:28:17 +00:00
Jakub Grajciar
93a5dd1723 libmemif: external region support
region 0: descriptors
region 1: buffers (external)

Change-Id: Ia728967817b4c78bc00f8eed44606d0c5bc386b0
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
2018-08-30 12:35:46 +00:00
Damjan Marion
20728d40d9 memif: fix max number of rings
Change-Id: Ie7621a38a44e7c692e23e58c43d27d8d2aab43e6
Signed-off-by: Damjan Marion <damarion@cisco.com>
2018-07-11 13:23:03 +00:00
Milan Lenco
f8b43e5421 libmemif: fixing head/tail arithmetics & queue reallocation
Change-Id: Ibc1f01b1cc99e7be77e892e53b7e1283f2a145cf
Signed-off-by: Milan Lenco <milan.lenco@pantheon.tech>
2018-06-28 13:50:28 +00:00