Documentation ¶
Overview ¶
Package libmemif is a Golang adapter for the libmemif library (extras/libmemif in the VPP repository). To differentiate between the adapter and the underlying C-written library, labels "Go-libmemif" and "C-libmemif" are used in the documentation.
Index ¶
- Variables
- func Cleanup() error
- func Init(appName string) error
- func SetLogger(l *logger.Logger)
- type CPacketBuffers
- type ConnUpdateCallback
- type Context
- type IfMode
- type Memif
- func (memif *Memif) Close() error
- func (memif *Memif) GetDetails() (details *MemifDetails, err error)
- func (memif *Memif) GetInterruptChan() (ch <-chan uint8)
- func (memif *Memif) GetInterruptErrorChan() (ch <-chan error)
- func (memif *Memif) GetQueueInterruptChan(queueID uint8) (ch <-chan struct{}, err error)
- func (memif *Memif) NewPacketHandle(queueId uint8, rxCount uint16) *MemifPacketHandle
- func (memif *Memif) RxBurst(queueID uint8, count uint16) (packets []RawPacketData, err error)
- func (memif *Memif) SetRxMode(queueID uint8, rxMode RxMode) (err error)
- func (memif *Memif) TxBurst(queueID uint8, packets []RawPacketData) (count uint16, err error)
- type MemifCallbacks
- type MemifConfig
- type MemifConnDetails
- type MemifDetails
- type MemifError
- type MemifMeta
- type MemifPacketHandle
- type MemifQueueDetails
- type MemifShmSpecs
- type RawPacketData
- type RxMode
Constants ¶
This section is empty.
Variables ¶
var ( ErrSyscall = newMemifError(1) ErrConnRefused = newMemifError(2) ErrAccess = newMemifError(3) ErrNoFile = newMemifError(4) ErrFileLimit = newMemifError(5) ErrProcFileLimit = newMemifError(6) ErrAlready = newMemifError(7) ErrAgain = newMemifError(8) ErrBadFd = newMemifError(9) ErrNoMem = newMemifError(10) ErrInvalArgs = newMemifError(11) ErrNoConn = newMemifError(12) ErrConn = newMemifError(13) ErrClbFDUpdate = newMemifError(14) ErrFileNotSock = newMemifError(15) ErrNoShmFD = newMemifError(16) ErrCookie = newMemifError(17) // Not thrown, instead properly handled inside the golang adapter: ErrNoBufRing = newMemifError(18) ErrNoBuf = newMemifError(19) ErrNoBufDetails = newMemifError(20) ErrIntWrite = newMemifError(21) ErrMalformedMsg = newMemifError(22) ErrQueueID = newMemifError(23) ErrProto = newMemifError(24) ErrIfID = newMemifError(25) ErrAcceptSlave = newMemifError(26) ErrAlreadyConn = newMemifError(27) ErrMode = newMemifError(28) ErrSecret = newMemifError(29) ErrNoSecret = newMemifError(30) ErrMaxRegion = newMemifError(31) ErrMaxRing = newMemifError(32) ErrNotIntFD = newMemifError(33) ErrDisconnect = newMemifError(34) ErrDisconnected = newMemifError(35) ErrUnknownMsg = newMemifError(36) ErrPollCanceled = newMemifError(37) // Errors added by the adapter: ErrNotInit = newMemifError(100, "libmemif is not initialized") ErrAlreadyInit = newMemifError(101, "libmemif is already initialized") ErrUnsupported = newMemifError(102, "the feature is not supported by C-libmemif") // Received unrecognized error code from C-libmemif. ErrUnknown = newMemifError(-1, "unknown error") )
List of errors thrown by go-libmemif. Error handling code should compare returned error by value against these variables.
Functions ¶
func Init ¶
Init initializes the libmemif library. Must by called exactly once and before any libmemif functions. Do not forget to call Cleanup() before exiting your application. <appName> should be a human-readable string identifying your application. For example, VPP returns the version information ("show version" from VPP CLI).
Types ¶
type CPacketBuffers ¶
type CPacketBuffers struct {
// contains filtered or unexported fields
}
CPacketBuffers stores an array of memif buffers for use with TxBurst or RxBurst.
type ConnUpdateCallback ¶
ConnUpdateCallback is a callback type declaration used with callbacks related to connection status changes.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a global Go-libmemif runtime context.
type IfMode ¶
type IfMode int
IfMode represents the mode (layer/behaviour) in which the interface operates.
type Memif ¶
type Memif struct { MemifMeta // contains filtered or unexported fields }
Memif represents a single memif interface. It provides methods to send/receive packets in bursts in either the polling mode or in the interrupt mode with the help of golang channels.
func CreateInterface ¶
func CreateInterface(config *MemifConfig, callbacks *MemifCallbacks) (memif *Memif, err error)
CreateInterface creates a new memif interface with the given configuration. The same callbacks can be used with multiple memifs. The first callback input argument (*Memif) can be used to tell which memif the callback was triggered for. The method is thread-safe.
func (*Memif) Close ¶
Close removes the memif interface. If the memif is in the connected state, the connection is first properly closed. Do not access memif after it is closed, let garbage collector to remove it.
func (*Memif) GetDetails ¶
func (memif *Memif) GetDetails() (details *MemifDetails, err error)
GetDetails returns a detailed runtime information about this memif. The method is thread-safe.
func (*Memif) GetInterruptChan ¶
GetInterruptChan returns a channel which is continuously being filled with IDs of queues with data ready to be received. Since there is only one interrupt signal sent for an entire burst of packets, an interrupt handling routine should repeatedly call RxBurst() until the function returns an empty slice of packets. This way it is ensured that there are no packets left on the queue unread when the interrupt signal is cleared. The method is thread-safe.
func (*Memif) GetInterruptErrorChan ¶
GetInterruptErrorChan returns an Error channel which fires if there are errors occurred while read data.
func (*Memif) GetQueueInterruptChan ¶
GetQueueInterruptChan returns an empty-data channel which fires every time there are data to read on a given queue. It is only valid to call this function if memif is in the connected state. Channel is automatically closed when the connection goes down (but after the user provided callback OnDisconnect has executed). Since there is only one interrupt signal sent for an entire burst of packets, an interrupt handling routine should repeatedly call RxBurst() until the function returns an empty slice of packets. This way it is ensured that there are no packets left on the queue unread when the interrupt signal is cleared. The method is thread-safe.
func (*Memif) NewPacketHandle ¶
func (memif *Memif) NewPacketHandle(queueId uint8, rxCount uint16) *MemifPacketHandle
Create new GoPacket packet handle from libmemif queue. rxCount determines how many packets will be read at once, minimum value is 1
func (*Memif) RxBurst ¶
func (memif *Memif) RxBurst(queueID uint8, count uint16) (packets []RawPacketData, err error)
RxBurst is used to receive multiple packets in one call from a selected queue. <count> is the number of packets to receive. The actual number of packets received may be smaller. <count> effectively limits the maximum number of packets to receive in one burst (for a flat, predictable memory usage). The method is non-blocking even if there are no packets to receive. It is only valid to call this function if memif is in the connected state. Multiple RxBurst-s can run concurrently provided that each targets a different Rx queue.
func (*Memif) SetRxMode ¶
SetRxMode allows to switch between the interrupt and the polling mode for Rx. The method is thread-safe.
func (*Memif) TxBurst ¶
func (memif *Memif) TxBurst(queueID uint8, packets []RawPacketData) (count uint16, err error)
TxBurst is used to send multiple packets in one call into a selected queue. The actual number of packets sent may be smaller and is returned as <count>. The method is non-blocking even if the ring is full and no packet can be sent. It is only valid to call this function if memif is in the connected state. Multiple TxBurst-s can run concurrently provided that each targets a different TX queue.
type MemifCallbacks ¶
type MemifCallbacks struct { // OnConnect is triggered when a connection for a given memif was established. OnConnect ConnUpdateCallback // OnDisconnect is triggered when a connection for a given memif was lost. OnDisconnect ConnUpdateCallback }
MemifCallbacks is a container for all callbacks provided by memif. Any callback can be nil, in which case it will be simply skipped. Important: Do not call CreateInterface() or Memif.Close() from within a callback or a deadlock will occur. Instead send signal through a channel to another go routine which will be able to create/remove memif interface(s).
type MemifConfig ¶
type MemifConfig struct { MemifMeta MemifShmSpecs }
MemifConfig is the memif configuration. Used as the input argument to CreateInterface(). It is the slave's config that mostly decides the parameters of the connection, but master may limit some of the quantities if needed (based on the memif protocol or master's configuration)
type MemifConnDetails ¶
type MemifConnDetails struct { // RemoteIfName is the name of the memif on the opposite side. RemoteIfName string // RemoteInstanceName is the name of the endpoint on the opposite side. RemoteInstanceName string // HasLink is true if the connection has link (= is established and functional). HasLink bool // RxQueues contains details for each Rx queue. RxQueues []MemifQueueDetails // TxQueues contains details for each Tx queue. TxQueues []MemifQueueDetails }
MemifConnDetails provides a detailed runtime information about a memif connection.
type MemifDetails ¶
type MemifDetails struct { MemifMeta MemifConnDetails }
MemifDetails provides a detailed runtime information about a memif interface.
type MemifError ¶
type MemifError struct {
// contains filtered or unexported fields
}
MemifError implements and extends the error interface with the method Code(), which returns the integer error code as returned by C-libmemif.
func (*MemifError) Code ¶
func (e *MemifError) Code() int
Code returns the integer error code as returned by C-libmemif.
type MemifMeta ¶
type MemifMeta struct { // IfName is the interface name. Has to be unique across all created memifs. // Interface name is truncated if needed to have no more than 32 characters. IfName string // InstanceName identifies the endpoint. If omitted, the application // name passed to Init() will be used instead. // Instance name is truncated if needed to have no more than 32 characters. InstanceName string // ConnID is a connection ID used to match opposite sides of the memif // connection. ConnID uint32 // SocketFilename is the filename of the AF_UNIX socket through which // the connection is established. // The string is truncated if neede to fit into sockaddr_un.sun_path // (108 characters on Linux). SocketFilename string // Secret must be the same on both sides for the authentication to succeed. // Empty string is allowed. // The secret is truncated if needed to have no more than 24 characters. Secret string // IsMaster is set to true if memif operates in the Master mode. IsMaster bool // Mode is the mode (layer/behaviour) in which the memif operates. Mode IfMode }
MemifMeta is used to store a basic memif metadata needed for identification and connection establishment.
type MemifPacketHandle ¶
type MemifPacketHandle struct {
// contains filtered or unexported fields
}
func (*MemifPacketHandle) Close ¶
func (handle *MemifPacketHandle) Close()
Waits for all read and write operations to finish and then prevents more from occurring. Handle can be closed only once and then can never be opened again.
func (*MemifPacketHandle) ReadPacketData ¶
func (handle *MemifPacketHandle) ReadPacketData() (data []byte, ci gopacket.CaptureInfo, err error)
Reads packet data from memif in bursts, based on previously configured rxCount parameter. Then caches the resulting packets and returns them 1 by 1 from this method until queue is empty then tries to call new rx burst to read more data. If no data is returned, io.EOF error is thrown and caller should stop reading.
func (*MemifPacketHandle) WritePacketData ¶
func (handle *MemifPacketHandle) WritePacketData(data []byte) (err error)
Writes packet data to memif in burst of 1 packet. In case no packet is sent, this method throws io.EOF error and called should stop trying to write packets.
type MemifQueueDetails ¶
type MemifQueueDetails struct { // QueueID is the ID of the queue. QueueID uint8 // RingSize is the number of slots in the ring (not logarithmic). RingSize uint32 // BufferSize is the size of each buffer pointed to from the ring slots. BufferSize uint16 }
MemifQueueDetails provides a detailed runtime information about a memif queue. Queue = Ring + the associated buffers (one directional).
type MemifShmSpecs ¶
type MemifShmSpecs struct { // NumRxQueues is the number of Rx queues. // Default is 1 (used if the value is 0). NumRxQueues uint8 // NumTxQueues is the number of Tx queues. // Default is 1 (used if the value is 0). NumTxQueues uint8 // BufferSize is the size of the buffer to hold one packet, or a single // fragment of a jumbo frame. Default is 2048 (used if the value is 0). BufferSize uint16 // Log2RingSize is the number of items in the ring represented through // the logarithm base 2. // Default is 10 (used if the value is 0). Log2RingSize uint8 }
MemifShmSpecs is used to store the specification of the shared memory segment used by memif to send/receive packets.
type RawPacketData ¶
type RawPacketData []byte
RawPacketData represents raw packet data. libmemif doesn't care what the actual content is, it only manipulates with raw bytes.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
gopacket
gopacket is a simple example showing how to answer APR and ICMP echo requests through a memif interface.
|
gopacket is a simple example showing how to answer APR and ICMP echo requests through a memif interface. |
icmp-responder
icmp-responder is a simple example showing how to answer APR and ICMP echo requests through a memif interface.
|
icmp-responder is a simple example showing how to answer APR and ICMP echo requests through a memif interface. |
jumbo-frames
jumbo-frames is simple example how to send larger and larger jumbo packets with libmemif adapter.
|
jumbo-frames is simple example how to send larger and larger jumbo packets with libmemif adapter. |
raw-data
raw-data is a basic example showing how to create a memif interface, handle events through callbacks and perform Rx/Tx of raw data.
|
raw-data is a basic example showing how to create a memif interface, handle events through callbacks and perform Rx/Tx of raw data. |