Tip

This is the documentation for the 21.07 version. Looking for the documentation of the latest version? Have a look here.

Shared Memory Packet Interfaces (memif)

A Shared Memory Packet Interface (memif) has two components: A socket and an interface. A memif also requires a role, either server or client. In most TNSR applications, it will be the server and the other endpoint will be a client. A single socket may only be associated with one role type.

Memif Configuration

The interface memif socket command has two forms, both of which are required in most cases. The first creates an association between a socket ID and a filename. The second creates a memif interface using a specific socket.

Creating a memif Socket

To create the socket-filename association, use: interface memif socket <socket-id> filename <socket-filename>.

Note

An exception to this is socket 0 which is special and locked to /run/vpp/memif.sock. It cannot be changed to another file. This entry is always present and does not need to be manually configured.

When defining a filename for a socket, the available parameters are:

socket-id:

A required identifier unique to this memif instance. This is an integer in the range 1..4294967294.

socket-filename:

The full path to a socket file used for establishing memif connections. A socket can be used for either server or client interfaces, but not both. A socket can have more than one server, or it can have more than one client.

Warning

Sockets cannot be edited or deleted if they are in use by a memif. To change or remove a socket, first remove the associated memif.

Creating a memif interface

Next, the interface memif socket <socket-id> interface <if-id> command creates a memif object. This command requires its own interface identifier, and it must be tied to the socket using the same ID from the previous command. This results in a new TNSR interface named memif<socket-id>/<if-id>.

Note

The combination of socket ID and interface ID must be unique, but multiple sockets may use the same interface ID. For example, memif0/0 and memif1/0.

Warning

Each socket can only be used by a single memif.

This command enters config-memif mode, where the following commands are available:

buffer-size <size>:

The size of the buffer allocated for each ring entry. Default 2048.

mac-address <mac>:

MAC address for the memif interface.

mode <mode>:

Sets the mode for the memif interface. Mode must be one of:

ethernet:

Ethernet (L2) mode.

Note

When ethernet mode is active and a mac-address is not set, TNSR will generate a random MAC for the interface.

ip:

IP (L3) mode.

punt/inject:

Reserved for future use. Not yet implemented.

ring-size <size>:

Number of entries in receive and transmit rings. Value is 8..32 and is used as a power of 2. Default value is 10 for 1024 (2^10) entries.

role <role> [<options>]:

Sets the role of the memif interface. The default role is server and this is the most common role for TNSR. The following modes and options are available:

server:

Server role. The server does not expose its memory to the client peer.

client [(rx-queues|tx-queues) <num-queues>]:

Client role. Allocates and shares memory with the server to transfer data. When operating in client mode, the number of receive or transmit queues may be set as an option:

rx-queues <n-rx-qs>:

Number of receive queues. May be between 1..255.

tx-queues <n-tx-qs>:

Number of transmit queues. May be between 1..255.

secret <sec-str>:

A quoted secret string, up to 24 characters.

Memif Example

First, create a socket with an ID of 23, using a socket file of /tmp/memif23.sock:

tnsr(config)# interface memif socket 23 filename /tmp/memif23.sock

Next, run commands to create a memif interface with an interface ID of 100 taking on the role server on the socket created previously:

tnsr(config)# interface memif socket 23 interface 100
tnsr(config-memif)# role server
tnsr(config-memif)# exit

Now the interface will be available to TNSR. In this example with a socket ID of 23 and an interface ID of 100, the full interface name is memif23/100.

Memif status

For a list of all current memif entries, along with their names and configuration, use the show interface memif command:

tnsr# show interface memif

Socket Id  Filename
---------- --------------------------------------------------
0          /run/vpp/memif.sock
23         /tmp/memif23.sock

memif23/100:
    Socket id: 23
    Interface id: 100
    Interface: memif23/100
    Role: server
    Mode: ethernet
    MAC address: 02:fe:2d:e2:87:a8
    Ring size: 0
    Buffer size: 0
    Admin up: false
    Link up: false