Vanetza
 
Loading...
Searching...
No Matches
vanetza::geonet::CbfPacketBuffer Class Reference

#include <cbf_packet_buffer.hpp>

Classes

struct  Timer
 

Public Types

using TimerCallback = std::function< void(PendingPacket< GbcPdu > &&)>
 
using Identifier = CbfPacketIdentifier
 

Public Member Functions

 CbfPacketBuffer (Runtime &rt, TimerCallback cb, std::unique_ptr< CbfCounter > cnt, std::size_t bytes)
 
void add (CbfPacket &&packet, Clock::duration timeout)
 
bool remove (const Identifier &id)
 
void update (const Identifier &id, Clock::duration timeout)
 
boost::optional< CbfPacketfetch (const Identifier &id)
 
const CbfPacketfind (const Identifier &id) const
 
std::size_t counter (const Identifier &packet) const
 

Private Types

using timer_bimap = boost::bimaps::bimap< boost::bimaps::multiset_of< Timer >, boost::bimaps::unordered_set_of< Identifier, std::hash< Identifier > >, boost::bimaps::with_info< std::list< CbfPacket >::iterator > >
 

Private Member Functions

void flush ()
 
void remove_timer (typename timer_bimap::left_map::iterator)
 
void schedule_timer ()
 
bool reduce_lifetime (const Timer &, CbfPacket &) const
 

Private Attributes

std::list< CbfPacketm_packets
 
timer_bimap m_timers
 
Runtimem_runtime
 
std::unique_ptr< CbfCounterm_counter
 
const std::size_t m_capacity_bytes
 
std::size_t m_stored_bytes
 
TimerCallback m_timer_callback
 

Detailed Description

CbfPacketBuffer facilitates implementation of contention based forwarding

Definition at line 84 of file cbf_packet_buffer.hpp.

Member Typedef Documentation

◆ Identifier

using vanetza::geonet::CbfPacketBuffer::Identifier = CbfPacketIdentifier

Definition at line 88 of file cbf_packet_buffer.hpp.

◆ timer_bimap

using vanetza::geonet::CbfPacketBuffer::timer_bimap = boost::bimaps::bimap< boost::bimaps::multiset_of<Timer>, boost::bimaps::unordered_set_of<Identifier, std::hash<Identifier> >, boost::bimaps::with_info<std::list<CbfPacket>::iterator> >
private

Definition at line 160 of file cbf_packet_buffer.hpp.

◆ TimerCallback

using vanetza::geonet::CbfPacketBuffer::TimerCallback = std::function<void(PendingPacket<GbcPdu>&&)>

Definition at line 87 of file cbf_packet_buffer.hpp.

Constructor & Destructor Documentation

◆ CbfPacketBuffer()

vanetza::geonet::CbfPacketBuffer::CbfPacketBuffer ( Runtime rt,
TimerCallback  cb,
std::unique_ptr< CbfCounter cnt,
std::size_t  bytes 
)

Create CBF packet buffer with bounded capacity

Parameters
rtRuntime instance used for internal timers
cbCallback invoked for each packet on expiry
cntCBF counter implementation
bytesBuffer can hold at most this number of bytes

Definition at line 51 of file cbf_packet_buffer.cpp.

◆ ~CbfPacketBuffer()

vanetza::geonet::CbfPacketBuffer::~CbfPacketBuffer ( )

Definition at line 58 of file cbf_packet_buffer.cpp.

Member Function Documentation

◆ add()

void vanetza::geonet::CbfPacketBuffer::add ( CbfPacket &&  packet,
Clock::duration  timeout 
)

Enqueue a packet and start an associated timer expiring after timeout

Parameters
packetBuffer this packet
timeoutCBF timer expiration for this packet

Definition at line 92 of file cbf_packet_buffer.cpp.

◆ counter()

std::size_t vanetza::geonet::CbfPacketBuffer::counter ( const Identifier &  packet) const

Get counter associated with given packet

Note
packet counter is incremented at each timer update
Parameters
idpacket identification
Returns
0 if packet has never been buffered before

Definition at line 168 of file cbf_packet_buffer.cpp.

◆ fetch()

boost::optional< CbfPacket > vanetza::geonet::CbfPacketBuffer::fetch ( const Identifier &  id)

Fetch a packet from buffer.

Associated timer is automatically stopped and packet removed from buffer. Packet lifetime is reduced by queueing time at return.

Parameters
idpacket identification
Returns
packet if found in buffer

Definition at line 139 of file cbf_packet_buffer.cpp.

◆ find()

const CbfPacket * vanetza::geonet::CbfPacketBuffer::find ( const Identifier &  id) const

Find packet in buffer.

Parameters
idpacket identification
Returns
read-only pointer to packet, nullptr if not found

Definition at line 161 of file cbf_packet_buffer.cpp.

◆ flush()

void vanetza::geonet::CbfPacketBuffer::flush ( )
private

Flush all expired packets

Definition at line 173 of file cbf_packet_buffer.cpp.

◆ reduce_lifetime()

bool vanetza::geonet::CbfPacketBuffer::reduce_lifetime ( const Timer timer,
CbfPacket packet 
) const
private

Reduce packet lifetime by queueing time

Parameters
timercontains queueing start time
packetassociated packet
Returns
true if packet remains valid, false if end of lifetime is reached

Definition at line 199 of file cbf_packet_buffer.cpp.

◆ remove()

bool vanetza::geonet::CbfPacketBuffer::remove ( const Identifier &  id)

Try to remove a packet from buffer.

Parameters
idpacket identification
Returns
true if packet existed before removal

Definition at line 63 of file cbf_packet_buffer.cpp.

◆ remove_timer()

void vanetza::geonet::CbfPacketBuffer::remove_timer ( typename timer_bimap::left_map::iterator  timer_it)
private

Remove timer from map and reschedule timer event if necessary

Definition at line 82 of file cbf_packet_buffer.cpp.

◆ schedule_timer()

void vanetza::geonet::CbfPacketBuffer::schedule_timer ( )
private

Schedule next timer event at runtime

Definition at line 205 of file cbf_packet_buffer.cpp.

◆ update()

void vanetza::geonet::CbfPacketBuffer::update ( const Identifier &  id,
Clock::duration  timeout 
)

Update associated packet timer

Parameters
idpacket identification
timeoutCBF timer expiration

Definition at line 126 of file cbf_packet_buffer.cpp.

Member Data Documentation

◆ m_capacity_bytes

const std::size_t vanetza::geonet::CbfPacketBuffer::m_capacity_bytes
private

Definition at line 193 of file cbf_packet_buffer.hpp.

◆ m_counter

std::unique_ptr<CbfCounter> vanetza::geonet::CbfPacketBuffer::m_counter
private

Definition at line 192 of file cbf_packet_buffer.hpp.

◆ m_packets

std::list<CbfPacket> vanetza::geonet::CbfPacketBuffer::m_packets
private

Definition at line 189 of file cbf_packet_buffer.hpp.

◆ m_runtime

Runtime& vanetza::geonet::CbfPacketBuffer::m_runtime
private

Definition at line 191 of file cbf_packet_buffer.hpp.

◆ m_stored_bytes

std::size_t vanetza::geonet::CbfPacketBuffer::m_stored_bytes
private

Definition at line 194 of file cbf_packet_buffer.hpp.

◆ m_timer_callback

TimerCallback vanetza::geonet::CbfPacketBuffer::m_timer_callback
private

Definition at line 195 of file cbf_packet_buffer.hpp.

◆ m_timers

timer_bimap vanetza::geonet::CbfPacketBuffer::m_timers
private

Definition at line 190 of file cbf_packet_buffer.hpp.


The documentation for this class was generated from the following files: