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

#include <PacketBasedTokenGenerator.h>

Inheritance diagram for inet::queueing::PacketBasedTokenGenerator:
inet::queueing::PassivePacketSinkBase inet::queueing::PacketSinkBase inet::queueing::IPassivePacketSink inet::queueing::PacketProcessorBase inet::queueing::IPacketProcessor inet::StringFormat::IDirectiveResolver

Public Member Functions

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...
 
virtual bool canPushSomePacket (cGate *gate) const override
 Returns false if the packet sink is full at the given gate and no more packets can be pushed into it without raising an error. More...
 
virtual bool canPushPacket (Packet *packet, cGate *gate) const override
 Returns true if the given packet can be pushed at the given gate into the packet sink without raising an error. More...
 
virtual void pushPacket (Packet *packet, cGate *gate) override
 Pushes the packet into the packet sink at the given gate. More...
 
virtual const char * resolveDirective (char directive) const override
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, double value, cObject *details) override
 
- Public Member Functions inherited from inet::queueing::PassivePacketSinkBase
virtual void pushPacketStart (Packet *packet, cGate *gate, bps datarate) override
 Starts pushing the packet into the packet sink at the given gate. More...
 
virtual void pushPacketEnd (Packet *packet, cGate *gate) override
 Ends pushing the packet into the packet sink at the given gate. More...
 
virtual void pushPacketProgress (Packet *packet, cGate *gate, bps datarate, b position, b extraProcessableLength=b(0)) override
 Progresses pushing the packet into the packet sink 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::IPassivePacketSink
virtual ~IPassivePacketSink ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
- Protected Member Functions inherited from inet::queueing::PassivePacketSinkBase
virtual void handleMessage (cMessage *message) 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

cPar * numTokensPerPacketParameter = nullptr
 
cPar * numTokensPerBitParameter = nullptr
 
cGate * inputGate = nullptr
 
opp_component_ptr< IActivePacketSourceproducer
 
ModuleRefByPar< ITokenStoragestorage
 
int numTokensGenerated = -1
 
- Protected Attributes inherited from inet::queueing::PassivePacketSinkBase
cGate * inputGate = nullptr
 
IActivePacketSourceproducer = nullptr
 
- 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

◆ canPushPacket()

virtual bool inet::queueing::PacketBasedTokenGenerator::canPushPacket ( Packet packet,
cGate *  gate 
) const
inlineoverridevirtual

Returns true if the given packet can be pushed at the given gate into the packet sink without raising an error.

The packet must not be nullptr. The gate must be a valid gate of this module and it must support pushing packets.

Reimplemented from inet::queueing::PassivePacketSinkBase.

38 { return storage->getNumTokens() == 0; }

◆ canPushSomePacket()

virtual bool inet::queueing::PacketBasedTokenGenerator::canPushSomePacket ( cGate *  gate) const
inlineoverridevirtual

Returns false if the packet sink is full at the given gate and no more packets can be pushed into it without raising an error.

The gate must be a valid gate of this module and it must support pushing packets.

Reimplemented from inet::queueing::PassivePacketSinkBase.

37 { return storage->getNumTokens() == 0; }

◆ initialize()

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

Reimplemented from inet::queueing::PassivePacketSinkBase.

19 {
21  if (stage == INITSTAGE_LOCAL) {
22  numTokensPerPacketParameter = &par("numTokensPerPacket");
23  numTokensPerBitParameter = &par("numTokensPerBit");
24  inputGate = gate("in");
25  producer = getConnectedModule<IActivePacketSource>(inputGate);
26  storage.reference(this, "storageModule", true);
27  getModuleFromPar<cModule>(par("storageModule"), this)->subscribe(tokensDepletedSignal, this);
29  WATCH(numTokensGenerated);
30  }
31  else if (stage == INITSTAGE_QUEUEING) {
32  if (producer != nullptr)
33  producer->handleCanPushPacketChanged(inputGate->getPathStartGate());
34  }
35 }

◆ pushPacket()

void inet::queueing::PacketBasedTokenGenerator::pushPacket ( Packet packet,
cGate *  gate 
)
overridevirtual

Pushes the packet into the packet sink at the given gate.

This operation pushes the packet as a whole. The onwership of the packet is transferred to the sink.

This method is called, for example, when a packet source module pushes a packet into a queue module.

The sink must not be full at the gate. The packet must not be nullptr. The gate must be a valid gate of this module and it must support pushing and passing packets.

Implements inet::queueing::IPassivePacketSink.

38 {
39  Enter_Method("pushPacket");
40  take(packet);
41  auto numTokens = numTokensPerPacketParameter->doubleValue() + numTokensPerBitParameter->doubleValue() * packet->getTotalLength().get();
42  numTokensGenerated += numTokens;
44  storage->addTokens(numTokens);
46  processedTotalLength += packet->getDataLength();
48  delete packet;
49 }

◆ receiveSignal()

void inet::queueing::PacketBasedTokenGenerator::receiveSignal ( cComponent *  source,
simsignal_t  signal,
double  value,
cObject *  details 
)
overridevirtual
72 {
73  Enter_Method("%s", cComponent::getSignalName(signal));
74 
75  if (signal == tokensDepletedSignal) {
76  Enter_Method("tokensDepleted");
77  producer->handleCanPushPacketChanged(inputGate->getPathStartGate());
78  }
79  else
80  throw cRuntimeError("Unknown signal");
81 }

◆ resolveDirective()

const char * inet::queueing::PacketBasedTokenGenerator::resolveDirective ( char  directive) const
overridevirtual

Reimplemented from inet::queueing::PacketProcessorBase.

52 {
53  static std::string result;
54  switch (directive) {
55  case 's': {
56  result = par("storageModule").stringValue();
57  break;
58  }
59  case 't': {
60  std::stringstream stream;
61  stream << numTokensGenerated;
62  result = stream.str();
63  break;
64  }
65  default:
67  }
68  return result.c_str();
69 }

◆ supportsPacketPulling()

virtual bool inet::queueing::PacketBasedTokenGenerator::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.

Reimplemented from inet::queueing::PassivePacketSinkBase.

35 { return false; }

◆ supportsPacketPushing()

virtual bool inet::queueing::PacketBasedTokenGenerator::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.

Reimplemented from inet::queueing::PassivePacketSinkBase.

34 { return true; }

Member Data Documentation

◆ inputGate

cGate* inet::queueing::PacketBasedTokenGenerator::inputGate = nullptr
protected

Referenced by initialize(), and receiveSignal().

◆ numTokensGenerated

int inet::queueing::PacketBasedTokenGenerator::numTokensGenerated = -1
protected

◆ numTokensPerBitParameter

cPar* inet::queueing::PacketBasedTokenGenerator::numTokensPerBitParameter = nullptr
protected

Referenced by initialize(), and pushPacket().

◆ numTokensPerPacketParameter

cPar* inet::queueing::PacketBasedTokenGenerator::numTokensPerPacketParameter = nullptr
protected

Referenced by initialize(), and pushPacket().

◆ producer

opp_component_ptr<IActivePacketSource> inet::queueing::PacketBasedTokenGenerator::producer
protected

Referenced by initialize(), and receiveSignal().

◆ storage

ModuleRefByPar<ITokenStorage> inet::queueing::PacketBasedTokenGenerator::storage
protected

Referenced by initialize(), and pushPacket().


The documentation for this class was generated from the following files:
inet::queueing::PacketBasedTokenGenerator::producer
opp_component_ptr< IActivePacketSource > producer
Definition: PacketBasedTokenGenerator.h:25
inet::queueing::PacketBasedTokenGenerator::numTokensGenerated
int numTokensGenerated
Definition: PacketBasedTokenGenerator.h:28
inet::INITSTAGE_QUEUEING
INET_API InitStage INITSTAGE_QUEUEING
Initialization of queueing modules.
inet::queueing::PacketBasedTokenGenerator::numTokensPerBitParameter
cPar * numTokensPerBitParameter
Definition: PacketBasedTokenGenerator.h:22
inet::queueing::PacketProcessorBase::processedTotalLength
b processedTotalLength
Definition: PacketProcessorBase.h:31
inet::queueing::PacketProcessorBase::resolveDirective
virtual const char * resolveDirective(char directive) const override
Definition: PacketProcessorBase.cc:407
inet::queueing::PassivePacketSinkBase::initialize
virtual void initialize(int stage) override
Definition: PassivePacketSinkBase.cc:15
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::queueing::PacketProcessorBase::numProcessedPackets
int numProcessedPackets
Definition: PacketProcessorBase.h:30
inet::tokensDepletedSignal
simsignal_t tokensDepletedSignal
Definition: Simsignals.cc:124
inet::queueing::PacketProcessorBase::updateDisplayString
virtual void updateDisplayString() const
Definition: PacketProcessorBase.cc:399
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::queueing::PacketBasedTokenGenerator::storage
ModuleRefByPar< ITokenStorage > storage
Definition: PacketBasedTokenGenerator.h:26
inet::queueing::PacketBasedTokenGenerator::inputGate
cGate * inputGate
Definition: PacketBasedTokenGenerator.h:24
inet::queueing::PacketBasedTokenGenerator::numTokensPerPacketParameter
cPar * numTokensPerPacketParameter
Definition: PacketBasedTokenGenerator.h:21
inet::queueing::TokenGeneratorBase::tokensCreatedSignal
static simsignal_t tokensCreatedSignal
Definition: TokenGeneratorBase.h:22