INET Framework for OMNeT++/OMNEST
inet::ReorderBuffer Class Reference

This class provides functionality for reordering out of order data chunks for reliable connection oriented protocols. More...

#include <ReorderBuffer.h>

Inheritance diagram for inet::ReorderBuffer:
inet::ChunkBuffer

Public Member Functions

 ReorderBuffer (b expectedOffset=b(-1))
 
 ReorderBuffer (const ReorderBuffer &other)
 
b getExpectedOffset () const
 Returns the offset of the next expected data chunk. More...
 
void setExpectedOffset (b expectedOffset)
 Changes the offset of the next expected data chunk. More...
 
b getAvailableDataLength () const
 Returns the length of the largest next available data chunk starting at the expected offset. More...
 
const Ptr< const ChunkpopAvailableData (b length=b(-1))
 Returns the largest next available data chunk starting at the expected offset. More...
 
- Public Member Functions inherited from inet::ChunkBuffer
 ChunkBuffer (const char *name=nullptr)
 
 ChunkBuffer (const ChunkBuffer &other)
 
virtual ChunkBufferdup () const override
 
bool isEmpty () const
 Returns true if the buffer is completely empty. More...
 
int getNumRegions () const
 Returns the number non-overlapping, non-connecting but continuous regions. More...
 
b getRegionLength (int index) const
 Returns the length of the given region. More...
 
b getRegionStartOffset (int index) const
 Returns the start offset of the given region. More...
 
b getRegionEndOffset (int index) const
 Returns the end offset of the given region. More...
 
const Ptr< const Chunk > & getRegionData (int index) const
 Returns the data of the given region in its current representation. More...
 
void replace (b offset, const Ptr< const Chunk > &chunk)
 Replaces the stored data at the provided offset with the data in the chunk. More...
 
void clear (b offset, b length)
 Erases the stored data at the provided offset and length. More...
 
void clear ()
 Erases all of the stored data. More...
 
virtual std::string str () const override
 Returns a human readable string representation. More...
 

Protected Attributes

b expectedOffset
 The offset of the next expected data chunk. More...
 
- Protected Attributes inherited from inet::ChunkBuffer
std::vector< Regionregions
 The list of non-overlapping, non-connecting but continuous regions. More...
 

Additional Inherited Members

- Protected Member Functions inherited from inet::ChunkBuffer
RegiongetRegion (int i) const
 
void eraseEmptyRegions (std::vector< Region >::iterator begin, std::vector< Region >::iterator end)
 
void sliceRegions (Region &newRegion)
 
void mergeRegions (Region &previousRegion, Region &nextRegion)
 

Detailed Description

This class provides functionality for reordering out of order data chunks for reliable connection oriented protocols.

The reordering algorithm takes the expected offset of the next data chunk. It provides reordered data as a continuous data chunk at the expected offset as soon as it becomes available.

Constructor & Destructor Documentation

◆ ReorderBuffer() [1/2]

inet::ReorderBuffer::ReorderBuffer ( b  expectedOffset = b(-1))
inline

◆ ReorderBuffer() [2/2]

inet::ReorderBuffer::ReorderBuffer ( const ReorderBuffer other)
inline
31 : ChunkBuffer(other), expectedOffset(other.expectedOffset) {}

Member Function Documentation

◆ getAvailableDataLength()

b inet::ReorderBuffer::getAvailableDataLength ( ) const

Returns the length of the largest next available data chunk starting at the expected offset.

13 {
14  if (regions.size() > 0 && regions[0].offset == expectedOffset)
15  return regions[0].data->getChunkLength();
16  else
17  return b(0);
18 }

◆ getExpectedOffset()

b inet::ReorderBuffer::getExpectedOffset ( ) const
inline

◆ popAvailableData()

const Ptr< const Chunk > inet::ReorderBuffer::popAvailableData ( b  length = b(-1))

Returns the largest next available data chunk starting at the expected offset.

The returned data chunk is automatically removed from the buffer. If there's no available data at the expected offset, then it returns a nullptr and the buffer is not modified.

21 {
22  if (regions.size() > 0 && regions[0].offset == expectedOffset) {
23  auto data = regions[0].data;
24  b dataLength = data->getChunkLength();
25  if (length != b(-1)) {
26  data = data->peek(Chunk::ForwardIterator(b(0)), length);
27  dataLength = length;
28  }
29  clear(expectedOffset, dataLength);
30  expectedOffset += dataLength;
31  return data;
32  }
33  else
34  return nullptr;
35 }

Referenced by inet::tcp::TcpReceiveQueue::extractBytesUpTo().

◆ setExpectedOffset()

void inet::ReorderBuffer::setExpectedOffset ( b  expectedOffset)
inline

Changes the offset of the next expected data chunk.

41 { this->expectedOffset = expectedOffset; }

Referenced by inet::tcp::TcpReceiveQueue::init().

Member Data Documentation

◆ expectedOffset

b inet::ReorderBuffer::expectedOffset
protected

The offset of the next expected data chunk.

Referenced by getAvailableDataLength(), and popAvailableData().


The documentation for this class was generated from the following files:
inet::ChunkBuffer::ChunkBuffer
ChunkBuffer(const char *name=nullptr)
Definition: ChunkBuffer.cc:17
inet::ReorderBuffer::expectedOffset
b expectedOffset
The offset of the next expected data chunk.
Definition: ReorderBuffer.h:27
inet::ChunkBuffer::clear
void clear()
Erases all of the stored data.
Definition: ChunkBuffer.h:133
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::ChunkBuffer::regions
std::vector< Region > regions
The list of non-overlapping, non-connecting but continuous regions.
Definition: ChunkBuffer.h:66