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

#include <PacketSourceBase.h>

Inheritance diagram for inet::queueing::PacketSourceBase:
inet::queueing::PacketProcessorBase inet::queueing::IPacketProcessor inet::StringFormat::IDirectiveResolver inet::queueing::ActivePacketSourceBase inet::queueing::PassivePacketSourceBase inet::ClockUserModuleMixin< ActivePacketSourceBase > inet::queueing::PcapFilePacketProducer inet::ClockUserModuleMixin< PassivePacketSourceBase > inet::queueing::ActivePacketSource inet::queueing::PassivePacketSource

Protected Member Functions

virtual void initialize (int stage) override
 
virtual const char * createPacketName (const Ptr< const Chunk > &data) const
 
virtual Ptr< ChunkcreatePacketContent () const
 
virtual PacketcreatePacket ()
 
virtual const cModule * findContainingApplication () const
 
virtual const cModule * getContainingApplication () const
 
- 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

const char * packetNameFormat = nullptr
 
const char * packetRepresentation = nullptr
 
cPar * packetLengthParameter = nullptr
 
cPar * packetDataParameter = nullptr
 
bool attachCreationTimeTag = false
 
bool attachIdentityTag = false
 
bool attachDirectionTag = false
 
- Protected Attributes inherited from inet::queueing::PacketProcessorBase
const char * displayStringTextFormat = nullptr
 
int numProcessedPackets = -1
 
b processedTotalLength = b(-1)
 

Additional Inherited Members

- 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...
 
virtual const char * resolveDirective (char directive) const override
 
- Public Member Functions inherited from inet::queueing::IPacketProcessor
virtual ~IPacketProcessor ()
 
virtual bool supportsPacketPushing (cGate *gate) const =0
 Returns true if the processor supports pushing packets at the given gate. More...
 
virtual bool supportsPacketPulling (cGate *gate) const =0
 Returns true if the processor supports pulling packets at the given gate. More...
 
- Protected Types inherited from inet::queueing::PacketProcessorBase
enum  Action { PUSH, PULL }
 

Member Function Documentation

◆ createPacket()

Packet * inet::queueing::PacketSourceBase::createPacket ( )
protectedvirtual
147 {
148  auto packetContent = createPacketContent();
150  packetContent->addTag<CreationTimeTag>()->setCreationTime(simTime());
151  if (attachIdentityTag) {
152  auto identityStart = IdentityTag::getNextIdentityStart(packetContent->getChunkLength());
153  packetContent->addTag<IdentityTag>()->setIdentityStart(identityStart);
154  }
155  auto packetName = createPacketName(packetContent);
156  auto packet = new Packet(packetName, packetContent);
157  if (attachDirectionTag)
158  packet->addTagIfAbsent<DirectionTag>()->setDirection(DIRECTION_OUTBOUND);
160  processedTotalLength += packet->getDataLength();
161  emit(packetCreatedSignal, packet);
162  return packet;
163 }

Referenced by inet::queueing::PassivePacketSource::canPullPacket(), inet::queueing::ActivePacketSource::producePacket(), and inet::queueing::PassivePacketSource::providePacket().

◆ createPacketContent()

Ptr< Chunk > inet::queueing::PacketSourceBase::createPacketContent ( ) const
protectedvirtual
100 {
101  auto packetLength = b(packetLengthParameter->intValue());
102  if (!strcmp(packetRepresentation, "bitCount")) {
103  int packetData = packetDataParameter->intValue();
104  return packetData == -1 ? makeShared<BitCountChunk>(packetLength) : makeShared<BitCountChunk>(packetLength, packetData);
105  }
106  else if (!strcmp(packetRepresentation, "bits")) {
107  static int total = 0;
108  const auto& packetContent = makeShared<BitsChunk>();
109  std::vector<bool> bits;
110  bits.resize(b(packetLength).get());
111  for (int i = 0; i < (int)bits.size(); i++) {
112  int packetData = packetDataParameter->intValue();
113  bits[i] = packetData == -1 ? (total + i) % 2 == 0 : packetData;
114  }
115  total += bits.size();
116  packetContent->setBits(bits);
117  return packetContent;
118  }
119  else if (!strcmp(packetRepresentation, "byteCount")) {
120  int packetData = packetDataParameter->intValue();
121  return packetData == -1 ? makeShared<ByteCountChunk>(packetLength) : makeShared<ByteCountChunk>(packetLength, packetData);
122  }
123  else if (!strcmp(packetRepresentation, "bytes")) {
124  static int total = 0;
125  const auto& packetContent = makeShared<BytesChunk>();
126  std::vector<uint8_t> bytes;
127  bytes.resize(B(packetLength).get());
128  for (int i = 0; i < (int)bytes.size(); i++) {
129  int packetData = packetDataParameter->intValue();
130  bytes[i] = packetData == -1 ? (total + i) % 256 : packetData;
131  }
132  total += bytes.size();
133  packetContent->setBytes(bytes);
134  return packetContent;
135  }
136  else if (!strcmp(packetRepresentation, "applicationPacket")) {
137  const auto& packetContent = makeShared<ApplicationPacket>();
138  packetContent->setChunkLength(B(packetLength));
139  packetContent->setSequenceNumber(numProcessedPackets);
140  return packetContent;
141  }
142  else
143  throw cRuntimeError("Unknown representation");
144 }

Referenced by createPacket().

◆ createPacketName()

const char * inet::queueing::PacketSourceBase::createPacketName ( const Ptr< const Chunk > &  data) const
protectedvirtual
39 {
40  return StringFormat::formatString(packetNameFormat, [&] (char directive) {
41  static std::string result;
42  switch (directive) {
43  case 'a': {
44  auto application = findContainingApplication();
45  if (application != nullptr)
46  result = application->getDisplayName() != nullptr ? application->getDisplayName() : application->getFullName();
47  else
48  result = getDisplayName() != nullptr ? getDisplayName() : getFullName();
49  break;
50  }
51  case 'n':
52  result = getDisplayName() != nullptr ? getDisplayName() : getFullName();
53  break;
54  case 'm': {
55  auto application = getContainingApplication();
56  result = application->getDisplayName() != nullptr ? application->getDisplayName() : application->getFullName();
57  break;
58  }
59  case 'M': {
60  auto networkNode = getContainingNode(this);
61  result = networkNode->getDisplayName() != nullptr ? networkNode->getDisplayName() : networkNode->getFullName();
62  break;
63  }
64  case 'p':
65 
66  result = getFullPath();
67  break;
68  case 'h':
69  result = getContainingApplication()->getFullPath();
70  break;
71  case 'H':
72  result = getContainingNode(this)->getFullPath();
73  break;
74  case 'c':
75  result = std::to_string(numProcessedPackets);
76  break;
77  case 'l':
78  result = data->getChunkLength().str();
79  break;
80  case 'd':
81  if (auto byteCountChunk = dynamicPtrCast<const ByteCountChunk>(data))
82  result = std::to_string(byteCountChunk->getData());
83  else if (auto bitCountChunk = dynamicPtrCast<const BitCountChunk>(data))
84  result = std::to_string(bitCountChunk->getData());
85  break;
86  case 't':
87  result = simTime().str();
88  break;
89  case 'e':
90  result = std::to_string(getSimulation()->getEventNumber());
91  break;
92  default:
93  throw cRuntimeError("Unknown directive: %c", directive);
94  }
95  return result.c_str();
96  });
97 }

Referenced by createPacket().

◆ findContainingApplication()

const cModule * inet::queueing::PacketSourceBase::findContainingApplication ( ) const
protectedvirtual
172 {
173  for (const cModule *module = this; module != nullptr; module = module->getParentModule()) {
174  if (isApplication(module))
175  return module;
176  }
177  return nullptr;
178 }

Referenced by createPacketName(), and getContainingApplication().

◆ getContainingApplication()

const cModule * inet::queueing::PacketSourceBase::getContainingApplication ( ) const
protectedvirtual
181 {
182  auto application = findContainingApplication();
183  if (application == nullptr)
184  throw cRuntimeError("Application not found");
185  else
186  return application;
187 }

Referenced by createPacketName().

◆ initialize()

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

Reimplemented from inet::queueing::PacketProcessorBase.

Reimplemented in inet::queueing::PassivePacketSource, inet::queueing::PassivePacketSourceBase, inet::queueing::ActivePacketSource, inet::queueing::ActivePacketSourceBase, and inet::queueing::PcapFilePacketProducer.

25 {
27  if (stage == INITSTAGE_LOCAL) {
28  packetNameFormat = par("packetNameFormat");
29  packetRepresentation = par("packetRepresentation");
30  packetLengthParameter = &par("packetLength");
31  packetDataParameter = &par("packetData");
32  attachCreationTimeTag = par("attachCreationTimeTag");
33  attachIdentityTag = par("attachIdentityTag");
34  attachDirectionTag = par("attachDirectionTag");
35  }
36 }

Referenced by inet::queueing::ActivePacketSourceBase::initialize(), and inet::queueing::PassivePacketSourceBase::initialize().

Member Data Documentation

◆ attachCreationTimeTag

bool inet::queueing::PacketSourceBase::attachCreationTimeTag = false
protected

Referenced by createPacket(), and initialize().

◆ attachDirectionTag

bool inet::queueing::PacketSourceBase::attachDirectionTag = false
protected

Referenced by createPacket(), and initialize().

◆ attachIdentityTag

bool inet::queueing::PacketSourceBase::attachIdentityTag = false
protected

Referenced by createPacket(), and initialize().

◆ packetDataParameter

cPar* inet::queueing::PacketSourceBase::packetDataParameter = nullptr
protected

Referenced by createPacketContent(), and initialize().

◆ packetLengthParameter

cPar* inet::queueing::PacketSourceBase::packetLengthParameter = nullptr
protected

Referenced by createPacketContent(), and initialize().

◆ packetNameFormat

const char* inet::queueing::PacketSourceBase::packetNameFormat = nullptr
protected

Referenced by createPacketName(), and initialize().

◆ packetRepresentation

const char* inet::queueing::PacketSourceBase::packetRepresentation = nullptr
protected

Referenced by createPacketContent(), and initialize().


The documentation for this class was generated from the following files:
inet::queueing::PacketProcessorBase::initialize
virtual void initialize(int stage) override
Definition: PacketProcessorBase.cc:16
inet::DIRECTION_OUTBOUND
@ DIRECTION_OUTBOUND
Definition: DirectionTag_m.h:58
inet::queueing::PacketSourceBase::getContainingApplication
virtual const cModule * getContainingApplication() const
Definition: PacketSourceBase.cc:180
inet::queueing::isApplication
bool isApplication(const cModule *mod)
Definition: PacketSourceBase.cc:165
inet::queueing::PacketSourceBase::createPacketContent
virtual Ptr< Chunk > createPacketContent() const
Definition: PacketSourceBase.cc:99
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::queueing::PacketSourceBase::packetDataParameter
cPar * packetDataParameter
Definition: PacketSourceBase.h:22
inet::queueing::PacketSourceBase::packetLengthParameter
cPar * packetLengthParameter
Definition: PacketSourceBase.h:21
inet::queueing::PacketSourceBase::packetNameFormat
const char * packetNameFormat
Definition: PacketSourceBase.h:19
inet::queueing::PacketProcessorBase::processedTotalLength
b processedTotalLength
Definition: PacketProcessorBase.h:31
inet::queueing::PacketSourceBase::attachCreationTimeTag
bool attachCreationTimeTag
Definition: PacketSourceBase.h:23
inet::queueing::PacketSourceBase::findContainingApplication
virtual const cModule * findContainingApplication() const
Definition: PacketSourceBase.cc:171
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::IdentityTag::getNextIdentityStart
static int64_t getNextIdentityStart(b length)
Definition: IdentityTag_m.h:92
inet::queueing::PacketSourceBase::attachIdentityTag
bool attachIdentityTag
Definition: PacketSourceBase.h:24
inet::queueing::PacketSourceBase::packetRepresentation
const char * packetRepresentation
Definition: PacketSourceBase.h:20
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::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::packetCreatedSignal
simsignal_t packetCreatedSignal
Definition: Simsignals.cc:82
inet::queueing::PacketSourceBase::attachDirectionTag
bool attachDirectionTag
Definition: PacketSourceBase.h:25
inet::StringFormat::formatString
const char * formatString(IDirectiveResolver *resolver) const
Definition: StringFormat.cc:17
inet::queueing::PacketSourceBase::createPacketName
virtual const char * createPacketName(const Ptr< const Chunk > &data) const
Definition: PacketSourceBase.cc:38