30. Memif Poll Mode Driver
Shared memory packet interface (memif) PMD allows for DPDK and any other client using memif (DPDK, VPP, libmemif) to communicate using shared memory. Memif is Linux only.
The created device transmits packets in a raw format. It can be used with Ethernet mode, IP mode, or Punt/Inject. At this moment, only Ethernet mode is supported in DPDK memif implementation.
Memif works in two roles: master and slave. Slave connects to master over an
existing socket. It is also a producer of shared memory file and initializes
the shared memory. Each interface can be connected to one peer interface
at same time. The peer interface is identified by id parameter. Master
creates the socket and listens for any slave connection requests. The socket
may already exist on the system. Be sure to remove any such sockets, if you
are creating a master interface, or you will see an “Address already in use”
error. Function rte_pmd_memif_remove()
, which removes memif interface,
will also remove a listener socket, if it is not being used by any other
interface.
The method to enable one or more interfaces is to use the
--vdev=net_memif0
option on the DPDK application command line. Each
--vdev=net_memif1
option given will create an interface named net_memif0,
net_memif1, and so on. Memif uses unix domain socket to transmit control
messages. Each memif has a unique id per socket. This id is used to identify
peer interface. If you are connecting multiple
interfaces using same socket, be sure to specify unique ids id=0
, id=1
,
etc. Note that if you assign a socket to a master interface it becomes a
listener socket. Listener socket can not be used by a slave interface on same
client.
Option | Description | Default | Valid value |
---|---|---|---|
id=0 | Used to identify peer interface | 0 | uint32_t |
role=master | Set memif role | slave | master|slave |
bsize=1024 | Size of single packet buffer | 2048 | uint16_t |
rsize=11 | Log2 of ring size. If rsize is 10, actual ring size is 1024 | 10 | 1-14 |
socket=/tmp/memif.sock | Socket filename | /tmp/memif.sock | string len 256 |
mac=01:23:45:ab:cd:ef | Mac address | 01:ab:23:cd:45:ef | |
secret=abc123 | Secret is an optional security option, which if specified, must be matched by peer | string len 24 | |
zero-copy=yes | Enable/disable zero-copy slave mode | no | yes|no |
Connection establishment
In order to create memif connection, two memif interfaces, each in separate
process, are needed. One interface in master
role and other in
slave
role. It is not possible to connect two interfaces in a single
process. Each interface can be connected to one interface at same time,
identified by matching id parameter.
Memif driver uses unix domain socket to exchange required information between
memif interfaces. Socket file path is specified at interface creation see
Memif configuration options table above. If socket is used by master
interface, it’s marked as listener socket (in scope of current process) and
listens to connection requests from other processes. One socket can be used by
multiple interfaces. One process can have slave
and master
interfaces
at the same time, provided each role is assigned unique socket.
For detailed information on memif control messages, see: net/memif/memif.h.
Slave interface attempts to make a connection on assigned socket. Process
listening on this socket will extract the connection request and create a new
connected socket (control channel). Then it sends the ‘hello’ message
(MEMIF_MSG_TYPE_HELLO
), containing configuration boundaries. Slave interface
adjusts its configuration accordingly, and sends ‘init’ message
(MEMIF_MSG_TYPE_INIT
). This message among others contains interface id. Driver
uses this id to find master interface, and assigns the control channel to this
interface. If such interface is found, ‘ack’ message (MEMIF_MSG_TYPE_ACK
) is
sent. Slave interface sends ‘add region’ message (MEMIF_MSG_TYPE_ADD_REGION
) for
every region allocated. Master responds to each of these messages with ‘ack’
message. Same behavior applies to rings. Slave sends ‘add ring’ message
(MEMIF_MSG_TYPE_ADD_RING
) for every initialized ring. Master again responds to
each message with ‘ack’ message. To finalize the connection, slave interface
sends ‘connect’ message (MEMIF_MSG_TYPE_CONNECT
). Upon receiving this message
master maps regions to its address space, initializes rings and responds with
‘connected’ message (MEMIF_MSG_TYPE_CONNECTED
). Disconnect
(MEMIF_MSG_TYPE_DISCONNECT
) can be sent by both master and slave interfaces at
any time, due to driver error or if the interface is being deleted.
Files
- net/memif/memif.h - control messages definitions
- net/memif/memif_socket.h
- net/memif/memif_socket.c