SatCat5
multi_buffer.h File Reference

Detailed Description

Multi-source, multi-sink packet buffer.

The MultiBuffer class implements a multithreaded buffer for packet data, with multiple source and sink ports that operate concurrently. Each port is first-in / first-out, but the aggregate is non-blocking. It is suitable for use in software-defined switches and routers.

To write to the MultiBuffer, instantiate a MultiWriter and use the usual io::Writeable API. To read from the MultiBuffer, instantiate a MultiReader and use the usual io::Readable API. Each MultiBuffer can have any number of attached read or write ports.

By default, each written packet is sent to every attached read port. Child classes can change this by overriding the "deliver" method.

The MultiBuffer operates using a single large pool, allocated separately, that is subdivided into many fine-grained "chunks" (typically ~60 bytes). Internal allocators assign chunks to each port as they write incoming data. A packet is a linked list of such chunks, along with a reference-counter for write-once, read-many operations and garbage collection.

Example supporting two read/write ports:

u8 raw_buffer[16384];
MultiBuffer multi_buff(raw_buffer, sizeof(raw_buffer));
MultiWriter port1_wr(&multi_buff);
MultiWriter port2_wr(&multi_buff);
MultiReaderSimple port1_rd(&multi_buff);
MultiReaderSimple port2_rd(&multi_buff);

Definition in file multi_buffer.h.

#include <satcat5/io_readable.h>
#include <satcat5/io_writeable.h>
#include <satcat5/list.h>
#include <satcat5/types.h>
Include dependency graph for multi_buffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  satcat5::io::MultiChunk
 Data-structure representing a single fine-grained memory block. More...
 
struct  satcat5::io::MultiPacket
 A packet is a linked-list of memory blocks, plus metadata. More...
 
class  satcat5::io::MultiPacket::Reader
 Barebones class for reading data from a MultiPacket. More...
 
class  satcat5::io::MultiPacket::Overwriter
 Barebones class for overwriting contents of a MultiPacket. More...
 
class  satcat5::io::MultiBuffer
 A multi-source, multi-sink packet buffer. More...
 
class  satcat5::io::MultiReader
 A port for reading from a MultiBuffer object. More...
 
class  satcat5::io::MultiReaderSimple
 A variant of MultiReader with a simple first-in, first-out queue. More...
 
class  satcat5::io::MultiReaderPriority
 A variant of MultiReader that follows priority ordering. More...
 
class  satcat5::io::MultiWriter
 A port for writing to a MultiBuffer object. More...
 
class  satcat5::io::MultiWriterBypass
 MultiWriter adapter for bypass mode. More...
 

Macros

#define SATCAT5_MBUFF_CHUNK   (64 - sizeof(uintptr_t))
 
#define SATCAT5_MBUFF_PKTLEN   2048
 
#define SATCAT5_MBUFF_RXPKT   32
 
#define SATCAT5_MBUFF_TIMEOUT   1500
 
#define SATCAT5_MBUFF_USER   8