INET Framework for OMNeT++/OMNEST
inet::queueing::PacketBuffer Class Reference

#include <PacketBuffer.h>

Inheritance diagram for inet::queueing::PacketBuffer:
inet::queueing::PacketBufferBase inet::queueing::IPacketBuffer inet::queueing::PacketProcessorBase inet::queueing::IPacketCollection inet::queueing::IPacketCollection inet::queueing::IPacketProcessor inet::StringFormat::IDirectiveResolver

Public Member Functions

virtual int getMaxNumPackets () const override
 Returns maximum allowed number of packets in the collection. More...
 
virtual int getNumPackets () const override
 Returns the number of available packets in the collection in the range [0, inf). More...
 
virtual b getMaxTotalLength () const override
 Returns maximum allowed total length of all packets in the collection. More...
 
virtual b getTotalLength () const override
 Returns the total length of all packets in the collection in the range [0, inf). More...
 
virtual PacketgetPacket (int index) const override
 Returns the packet at the given index. More...
 
virtual bool isEmpty () const override
 Returns true if there are no packets available in the collection. More...
 
virtual void addPacket (Packet *packet) override
 Adds the packet to the buffer. More...
 
virtual void removePacket (Packet *packet) override
 Removes the packet from the buffer. More...
 
virtual void removeAllPackets () override
 Removes all packets from the collection. More...
 
virtual bool supportsPacketPushing (cGate *gate) const override
 Returns true if the processor supports pushing packets at the given gate. More...
 
virtual bool supportsPacketPulling (cGate *gate) const override
 Returns true if the processor supports pulling packets at the given gate. More...
 
- Public Member Functions inherited from inet::queueing::PacketProcessorBase
virtual bool supportsPacketSending (cGate *gate) const override
 Returns true if the processor supports sending packets at the given gate. More...
 
virtual bool supportsPacketPassing (cGate *gate) const override
 Returns true if the processor supports passing packets as a whole at the given gate. More...
 
virtual bool supportsPacketStreaming (cGate *gate) const override
 Returns true if the processor supports streaming packets at the given gate. More...
 
- Public Member Functions inherited from inet::queueing::IPacketProcessor
virtual ~IPacketProcessor ()
 
- Public Member Functions inherited from inet::queueing::IPacketBuffer
virtual ~IPacketBuffer ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual IPacketDropperFunctioncreateDropperFunction (const char *dropperClass) const
 
virtual bool isOverloaded () const
 
- Protected Member Functions inherited from inet::queueing::PacketBufferBase
virtual void emit (simsignal_t signal, cObject *object, cObject *details=nullptr) override
 
virtual const char * resolveDirective (char directive) const override
 
- Protected Member Functions inherited from inet::queueing::PacketProcessorBase
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handlePacketProcessed (Packet *packet)
 
virtual void checkPacketOperationSupport (cGate *gate) const
 
virtual void checkPacketOperationSupport (cGate *startGate, cGate *endGate) const
 
virtual void animate (Packet *packet, cGate *gate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacket (Packet *packet, cGate *gate, Action action) const
 
virtual void animatePacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId, Action action) const
 
virtual void animatePacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacketEnd (Packet *packet, cGate *gate, long transmissionId, Action action) const
 
virtual void animatePacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions, Action action) const
 
virtual void animatePacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId, Action action) const
 
virtual void animatePacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions, Action action) const
 
virtual void pushOrSendPacket (Packet *packet, cGate *gate, IPassivePacketSink *consumer)
 
virtual void pushOrSendPacketStart (Packet *packet, cGate *gate, IPassivePacketSink *consumer, bps datarate, int transmissionId)
 
virtual void pushOrSendPacketEnd (Packet *packet, cGate *gate, IPassivePacketSink *consumer, int transmissionId)
 
virtual void pushOrSendPacketProgress (Packet *packet, cGate *gate, IPassivePacketSink *consumer, bps datarate, b position, b extraProcessableLength, int transmissionId)
 
virtual void animatePush (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePushPacket (Packet *packet, cGate *gate) const
 
virtual void animatePushPacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId) const
 
virtual void animatePushPacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions) const
 
virtual void animatePushPacketEnd (Packet *packet, cGate *gate, long transmissionId) const
 
virtual void animatePushPacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId) const
 
virtual void animatePushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions) const
 
virtual void animatePull (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePullPacket (Packet *packet, cGate *gate) const
 
virtual void animatePullPacketStart (Packet *packet, cGate *gate, bps datarate, long transmissionId) const
 
virtual void animatePullPacketStart (Packet *packet, cGate *gate, bps datarate, const SendOptions &sendOptions) const
 
virtual void animatePullPacketEnd (Packet *packet, cGate *gate, long transmissionId) const
 
virtual void animatePullPacketEnd (Packet *packet, cGate *gate, const SendOptions &sendOptions) const
 
virtual void animatePullPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, long transmissionId) const
 
virtual void animatePullPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength, const SendOptions &sendOptions) const
 
virtual void dropPacket (Packet *packet, PacketDropReason reason, int limit=-1)
 
virtual void updateDisplayString () const
 

Protected Attributes

int packetCapacity = -1
 
b dataCapacity = b(-1)
 
std::vector< Packet * > packets
 
IPacketDropperFunctionpacketDropperFunction = nullptr
 
- Protected Attributes inherited from inet::queueing::PacketBufferBase
int numAddedPackets = -1
 
int numRemovedPackets = -1
 
int numDroppedPackets = -1
 
- Protected Attributes inherited from inet::queueing::PacketProcessorBase
const char * displayStringTextFormat = nullptr
 
int numProcessedPackets = -1
 
b processedTotalLength = b(-1)
 

Additional Inherited Members

- Protected Types inherited from inet::queueing::PacketProcessorBase
enum  Action { PUSH, PULL }
 

Member Function Documentation

◆ addPacket()

void inet::queueing::PacketBuffer::addPacket ( Packet packet)
overridevirtual

Adds the packet to the buffer.

Implements inet::queueing::IPacketBuffer.

57 {
58  Enter_Method("addPacket");
59  EV_INFO << "Adding packet" << EV_FIELD(packet) << EV_ENDL;
60  emit(packetAddedSignal, packet);
61  packets.push_back(packet);
62  if (isOverloaded()) {
63  if (packetDropperFunction != nullptr) {
64  while (!isEmpty() && isOverloaded()) {
65  auto packet = packetDropperFunction->selectPacket(this);
66  EV_INFO << "Dropping packet" << EV_FIELD(packet) << EV_ENDL;
67  packets.erase(find(packets, packet));
68  auto queue = dynamic_cast<cPacketQueue *>(packet->getOwner());
69  if (queue != nullptr) {
70  ICallback *callback = dynamic_cast<ICallback *>(queue->getOwner());
71  if (callback != nullptr)
72  callback->handlePacketRemoved(packet);
73  }
74  // TODO maybe the buffer should take ownership and queues should be aware of it
75  take(packet);
76  dropPacket(packet, QUEUE_OVERFLOW);
77  }
78  }
79  else
80  throw cRuntimeError("Buffer is overloaded but packet dropper function is not specified");
81  }
83 }

◆ createDropperFunction()

IPacketDropperFunction * inet::queueing::PacketBuffer::createDropperFunction ( const char *  dropperClass) const
protectedvirtual
35 {
36  if (strlen(dropperClass) == 0)
37  return nullptr;
38  else
39  return check_and_cast<IPacketDropperFunction *>(createOne(dropperClass));
40 }

Referenced by initialize().

◆ getMaxNumPackets()

virtual int inet::queueing::PacketBuffer::getMaxNumPackets ( ) const
inlineoverridevirtual

Returns maximum allowed number of packets in the collection.

The value -1 means no such limit.

Implements inet::queueing::IPacketCollection.

35 { return packetCapacity; }

◆ getMaxTotalLength()

virtual b inet::queueing::PacketBuffer::getMaxTotalLength ( ) const
inlineoverridevirtual

Returns maximum allowed total length of all packets in the collection.

The value -1 means no such limit.

Implements inet::queueing::IPacketCollection.

38 { return dataCapacity; }

◆ getNumPackets()

virtual int inet::queueing::PacketBuffer::getNumPackets ( ) const
inlineoverridevirtual

Returns the number of available packets in the collection in the range [0, inf).

Implements inet::queueing::IPacketCollection.

36 { return packets.size(); }

Referenced by isOverloaded().

◆ getPacket()

Packet * inet::queueing::PacketBuffer::getPacket ( int  index) const
overridevirtual

Returns the packet at the given index.

Throws error when the index is out of range.

Implements inet::queueing::IPacketCollection.

119 {
120  if (index < 0 || (size_t)index >= packets.size())
121  throw cRuntimeError("index %i out of range", index);
122  return packets[index];
123 }

Referenced by removeAllPackets().

◆ getTotalLength()

b inet::queueing::PacketBuffer::getTotalLength ( ) const
overridevirtual

Returns the total length of all packets in the collection in the range [0, inf).

Implements inet::queueing::IPacketCollection.

49 {
50  b totalLength = b(0);
51  for (auto packet : packets)
52  totalLength += packet->getTotalLength();
53  return totalLength;
54 }

Referenced by isOverloaded().

◆ initialize()

void inet::queueing::PacketBuffer::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::queueing::PacketBufferBase.

22 {
24  if (stage == INITSTAGE_LOCAL) {
25  displayStringTextFormat = par("displayStringTextFormat");
26  packetCapacity = par("packetCapacity");
27  dataCapacity = b(par("dataCapacity"));
28  packetDropperFunction = createDropperFunction(par("dropperClass"));
29  }
30  else if (stage == INITSTAGE_LAST)
32 }

◆ isEmpty()

virtual bool inet::queueing::PacketBuffer::isEmpty ( ) const
inlineoverridevirtual

Returns true if there are no packets available in the collection.

Implements inet::queueing::IPacketCollection.

42 { return packets.size() == 0; }

Referenced by addPacket(), and removeAllPackets().

◆ isOverloaded()

bool inet::queueing::PacketBuffer::isOverloaded ( ) const
protectedvirtual
43 {
44  return (packetCapacity != -1 && getNumPackets() > packetCapacity) ||
45  (dataCapacity != b(-1) && getTotalLength() > dataCapacity);
46 }

Referenced by addPacket().

◆ removeAllPackets()

void inet::queueing::PacketBuffer::removeAllPackets ( )
overridevirtual

Removes all packets from the collection.

Implements inet::queueing::IPacketCollection.

101 {
102  Enter_Method("removeAllPacket");
103  EV_INFO << "Removing all packets" << EV_ENDL;
104  while (!isEmpty()) {
105  auto packet = getPacket(0);
106  emit(packetRemovedSignal, packet);
107  packets.erase(packets.begin());
108  auto queue = dynamic_cast<cPacketQueue *>(packet->getOwner());
109  if (queue != nullptr) {
110  ICallback *callback = dynamic_cast<ICallback *>(queue->getOwner());
111  if (callback != nullptr)
112  callback->handlePacketRemoved(packet);
113  }
114  }
116 }

◆ removePacket()

void inet::queueing::PacketBuffer::removePacket ( Packet packet)
overridevirtual

Removes the packet from the buffer.

Implements inet::queueing::IPacketBuffer.

86 {
87  Enter_Method("removePacket");
88  EV_INFO << "Removing packet" << EV_FIELD(packet) << EV_ENDL;
89  emit(packetRemovedSignal, packet);
90  packets.erase(find(packets, packet));
92  auto queue = dynamic_cast<cPacketQueue *>(packet->getOwner());
93  if (queue != nullptr) {
94  ICallback *callback = dynamic_cast<ICallback *>(queue->getOwner());
95  if (callback != nullptr)
96  callback->handlePacketRemoved(packet);
97  }
98 }

◆ supportsPacketPulling()

virtual bool inet::queueing::PacketBuffer::supportsPacketPulling ( cGate *  gate) const
inlineoverridevirtual

Returns true if the processor supports pulling packets at the given gate.

Pulling a packet is a synchronous operation that is initiated by the sink module. A pulled packet can be passed as a whole using pullPacket(), or it can be streamed from the source to the sink using pullPacketStart(), pullPacketEnd(), and pullPacketProgress().

For output gates, true means that the connected module can pull packets from this module. For input gates, true means that this module can pull packets from the connected module. For example, a packet server module can pull packets from a queue module.

Connecting incompatible gates raises an error during initialize. The gate parameter must be a valid gate of this module. The gate should be marked with @labels(pull) in the NED file.

Implements inet::queueing::IPacketProcessor.

49 { return false; }

◆ supportsPacketPushing()

virtual bool inet::queueing::PacketBuffer::supportsPacketPushing ( cGate *  gate) const
inlineoverridevirtual

Returns true if the processor supports pushing packets at the given gate.

Pushing a packet is a synchronous operation that is initiated by the source module. A pushed packet can be passed as a whole using pushPacket(), or it can be streamed from the source to the sink using pushPacketStart(), pushPacketEnd(), and pushPacketProgress().

For output gates, true means that this module can push packets into the connected module. For input gates, true means that the connected module can push packets into this module. For example, a packet generator module can push packets into a queue module.

Connecting incompatible gates raises an error during initialize. The gate parameter must be a valid gate of this module. The gate should be marked with @labels(push) in the NED file.

Implements inet::queueing::IPacketProcessor.

48 { return false; }

Member Data Documentation

◆ dataCapacity

b inet::queueing::PacketBuffer::dataCapacity = b(-1)
protected

Referenced by initialize(), and isOverloaded().

◆ packetCapacity

int inet::queueing::PacketBuffer::packetCapacity = -1
protected

Referenced by initialize(), and isOverloaded().

◆ packetDropperFunction

IPacketDropperFunction* inet::queueing::PacketBuffer::packetDropperFunction = nullptr
protected

Referenced by addPacket(), and initialize().

◆ packets

std::vector<Packet *> inet::queueing::PacketBuffer::packets
protected

The documentation for this class was generated from the following files:
inet::INITSTAGE_LAST
INET_API InitStage INITSTAGE_LAST
Operations that no other initializations can depend on, e.g.
inet::queueing::PacketBuffer::packetDropperFunction
IPacketDropperFunction * packetDropperFunction
Definition: PacketBuffer.h:27
inet::queueing::PacketBuffer::getTotalLength
virtual b getTotalLength() const override
Returns the total length of all packets in the collection in the range [0, inf).
Definition: PacketBuffer.cc:48
inet::find
std::vector< T >::iterator find(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:44
inet::packetRemovedSignal
simsignal_t packetRemovedSignal
Definition: Simsignals.cc:84
inet::queueing::PacketBuffer::dataCapacity
b dataCapacity
Definition: PacketBuffer.h:23
inet::queueing::PacketBuffer::isOverloaded
virtual bool isOverloaded() const
Definition: PacketBuffer.cc:42
inet::utils::createOne
cObject * createOne(const char *className, const char *defaultNamespace)
Like cObjectFactory::createOne(), except it starts searching for the class in the given namespace.
Definition: INETUtils.cc:147
inet::queueing::PacketBuffer::getPacket
virtual Packet * getPacket(int index) const override
Returns the packet at the given index.
Definition: PacketBuffer.cc:118
inet::QUEUE_OVERFLOW
@ QUEUE_OVERFLOW
Definition: Simsignals_m.h:77
inet::queueing::PacketBuffer::isEmpty
virtual bool isEmpty() const override
Returns true if there are no packets available in the collection.
Definition: PacketBuffer.h:42
EV_FIELD
#define EV_FIELD(...)
Definition: INETDefs.h:112
inet::queueing::PacketProcessorBase::dropPacket
virtual void dropPacket(Packet *packet, PacketDropReason reason, int limit=-1)
Definition: PacketProcessorBase.cc:390
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::queueing::PacketBuffer::packetCapacity
int packetCapacity
Definition: PacketBuffer.h:22
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::packetAddedSignal
simsignal_t packetAddedSignal
Definition: Simsignals.cc:83
inet::queueing::IPacketDropperFunction::selectPacket
virtual Packet * selectPacket(IPacketCollection *collection) const =0
Returns a packet to be dropped from the collection.
inet::queueing::PacketProcessorBase::updateDisplayString
virtual void updateDisplayString() const
Definition: PacketProcessorBase.cc:399
inet::queueing::PacketBufferBase::initialize
virtual void initialize(int stage) override
Definition: PacketBufferBase.cc:16
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::queueing::PacketBuffer::getNumPackets
virtual int getNumPackets() const override
Returns the number of available packets in the collection in the range [0, inf).
Definition: PacketBuffer.h:36
inet::queueing::PacketBufferBase::emit
virtual void emit(simsignal_t signal, cObject *object, cObject *details=nullptr) override
Definition: PacketBufferBase.cc:30
inet::queueing::PacketBuffer::packets
std::vector< Packet * > packets
Definition: PacketBuffer.h:25
inet::queueing::PacketProcessorBase::displayStringTextFormat
const char * displayStringTextFormat
Definition: PacketProcessorBase.h:29
inet::queueing::PacketBuffer::createDropperFunction
virtual IPacketDropperFunction * createDropperFunction(const char *dropperClass) const
Definition: PacketBuffer.cc:34
EV_ENDL
#define EV_ENDL
Definition: INETDefs.h:114