Tip

This is the documentation for the 19.12 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 master or slave. In most TNSR applications, it will be the master and the other endpoint will be a slave. A single socket may only be associated with one role type.

Memif Configuration

Creating a memif Socket

The interface memif socket command requires an identifier number and a filename, both of which must be unique to this socket. The full form of the command is: interface memif socket id <id> filename <socket-filename>

In this command, the available parameters are:

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 master or slave interfaces, but not both. A socket can have more than one master, or it can have more than one slave.

Creating a memif interface

Next, the interface memif interface <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 command enters config-memif mode, where the following commands are available:

socket-id <id>:

The socket ID for the associated memif socket created previously. This value is required.

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 master and this is the most common role for TNSR. The following modes and options are available:

master:

Master role. The master does not expose its memory to the slave peer.

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

Slave role. Allocates and shares memory with the master to transfer data. When operating in slave 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.

After creating the interface, it will be available in TNSR. The name of this interface is composed of the socket ID and the interface ID: interface memif<socket id>/<interface id>.

Memif Example

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

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

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

tnsr(config)# interface memif interface 100
tnsr(config-memif)# socket-id 23
tnsr(config-memif)# role master
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

memif id: 100
    Memif name: memif23/100
    Interface: memif23/100
    Role: master
    Mode: ethernet
    MAC address: 02:fe:8c:e5:ce:06
    Socket id: 23
    Ring size: 0
    Buffer size: 0
    Admin up: false
    Link up: false