4. Memif Poll Mode Driver¶
Shared memory packet interface (memif) PMD allows for CNDP 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 CNDP memif implementation.
Memif works in two roles: server and client. Client connects to server 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. Server creates the socket and listens for any client connection requests. The socket may already exist on the system. Be sure to remove any such sockets, if you are creating a server interface, or you will see an “Address already in use” error.
The method to enable one or more interfaces is to use the json file configuration by adding client or server to the lport configuration. Memif uses unix domain socket to transmit control messages.
Connection establishment
In order to create memif connection, two memif interfaces, each in separate
process, are needed. One interface in server
role and other in
client
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. If socket is used by server
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 client
and server
interfaces at the same time, provided each role
is assigned unique socket.
For detailed information on memif control messages, see: net/memif/memif.h.
Client 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. Client 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 server interface, and assigns the control channel to this
interface. If such interface is found, ‘ack’ message (MEMIF_MSG_TYPE_ACK
) is
sent. Client interface sends ‘add region’ message (MEMIF_MSG_TYPE_ADD_REGION
) for
every region allocated. Server responds to each of these messages with ‘ack’
message. Same behavior applies to rings. Client sends ‘add ring’ message
(MEMIF_MSG_TYPE_ADD_RING
) for every initialized ring. Server again responds to
each message with ‘ack’ message. To finalize the connection, client interface
sends ‘connect’ message (MEMIF_MSG_TYPE_CONNECT
). Upon receiving this message
server 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 server and client 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