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

Simple traffic generator for the Ethernet model. More...

#include <EtherTrafGen.h>

Inheritance diagram for inet::EtherTrafGen:
inet::ApplicationBase inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Public Member Functions

 EtherTrafGen ()
 
virtual ~EtherTrafGen ()
 
- Public Member Functions inherited from inet::ApplicationBase
 ApplicationBase ()
 
- Public Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual ~OperationalMixin ()
 }@ More...
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Types

enum  Kinds { START = 100, NEXT }
 
- Protected Types inherited from inet::OperationalMixin< cSimpleModule >
enum  State
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessageWhenUp (cMessage *msg) override
 
virtual void finish () override
 
virtual bool isGenerator ()
 
virtual void scheduleNextPacket (simtime_t previous)
 
virtual void cancelNextPacket ()
 
virtual MacAddress resolveDestMacAddress ()
 
virtual void sendBurstPackets ()
 
virtual void receivePacket (Packet *msg)
 
virtual void handleStartOperation (LifecycleOperation *operation) override
 
virtual void handleStopOperation (LifecycleOperation *operation) override
 
virtual void handleCrashOperation (LifecycleOperation *operation) override
 
- Protected Member Functions inherited from inet::ApplicationBase
virtual bool isInitializeStage (int stage) const override
 
virtual bool isModuleStartStage (int stage) const override
 
virtual bool isModuleStopStage (int stage) const override
 
- Protected Member Functions inherited from inet::OperationalMixin< cSimpleModule >
virtual int numInitStages () const override
 
virtual void refreshDisplay () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void handleMessageWhenDown (cMessage *msg)
 
virtual bool handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual State getInitialOperationalState () const
 Returns initial operational state: OPERATING or NOT_OPERATING. More...
 
virtual void handleActiveOperationTimeout (cMessage *message)
 
virtual bool isUp () const
 utility functions More...
 
virtual bool isDown () const
 
virtual void setOperationalState (State newState)
 
virtual void scheduleOperationTimeout (simtime_t timeout)
 
virtual void setupActiveOperation (LifecycleOperation *operation, IDoneCallback *doneCallback, State)
 
virtual void delayActiveOperationFinish (simtime_t timeout)
 
virtual void startActiveOperationExtraTime (simtime_t delay=SIMTIME_ZERO)
 
virtual void startActiveOperationExtraTimeOrFinish (simtime_t extraTime)
 
virtual void finishActiveOperation ()
 

Protected Attributes

ModuleRefByPar< IInterfaceTableinterfaceTable
 
long seqNum = 0
 
cPar * sendInterval = nullptr
 
cPar * numPacketsPerBurst = nullptr
 
cPar * packetLength = nullptr
 
int ssap = -1
 
int dsap = -1
 
MacAddress destMacAddress
 
int outInterface = -1
 
Ieee8022LlcSocket llcSocket
 
cMessage * timerMsg = nullptr
 
simtime_t startTime
 
simtime_t stopTime
 
long packetsSent = 0
 
long packetsReceived = 0
 
- Protected Attributes inherited from inet::OperationalMixin< cSimpleModule >
State operationalState
 
simtime_t lastChange
 
Operation activeOperation
 
cMessage * activeOperationTimeout
 
cMessage * activeOperationExtraTimer
 

Detailed Description

Simple traffic generator for the Ethernet model.

Member Enumeration Documentation

◆ Kinds

enum inet::EtherTrafGen::Kinds
protected
Enumerator
START 
NEXT 
26 { START = 100, NEXT };

Constructor & Destructor Documentation

◆ EtherTrafGen()

inet::EtherTrafGen::EtherTrafGen ( )
30 {
31  sendInterval = nullptr;
32  numPacketsPerBurst = nullptr;
33  packetLength = nullptr;
34  timerMsg = nullptr;
35 }

◆ ~EtherTrafGen()

inet::EtherTrafGen::~EtherTrafGen ( )
virtual
38 {
39  cancelAndDelete(timerMsg);
40 }

Member Function Documentation

◆ cancelNextPacket()

void inet::EtherTrafGen::cancelNextPacket ( )
protectedvirtual
133 {
134  cancelEvent(timerMsg);
135 }

Referenced by handleCrashOperation(), and handleStopOperation().

◆ finish()

void inet::EtherTrafGen::finish ( )
overrideprotectedvirtual
184 {
185  cancelAndDelete(timerMsg);
186  timerMsg = nullptr;
187 }

◆ handleCrashOperation()

void inet::EtherTrafGen::handleCrashOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

106 {
108  if (operation->getRootModule() != getContainingNode(this)) // closes socket when the application crashed only
109  llcSocket.destroy(); // TODO in real operating systems, program crash detected by OS and OS closes sockets of crashed programs.
110 }

◆ handleMessageWhenUp()

void inet::EtherTrafGen::handleMessageWhenUp ( cMessage *  msg)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

76 {
77  if (msg->isSelfMessage()) {
78  if (msg->getKind() == START) {
79  llcSocket.open(-1, ssap, -1);
81  // if no dest address given, nothing to do
83  return;
84  }
86  scheduleNextPacket(simTime());
87  }
88  else
89  receivePacket(check_and_cast<Packet *>(msg));
90 }

◆ handleStartOperation()

void inet::EtherTrafGen::handleStartOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

93 {
94  if (isGenerator()) {
96  }
97 }

◆ handleStopOperation()

void inet::EtherTrafGen::handleStopOperation ( LifecycleOperation operation)
overrideprotectedvirtual

Implements inet::OperationalMixin< cSimpleModule >.

100 {
102  llcSocket.close(); // TODO return false and waiting socket close
103 }

◆ initialize()

void inet::EtherTrafGen::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::OperationalMixin< cSimpleModule >.

43 {
44  if (stage == INITSTAGE_APPLICATION_LAYER && isGenerator()) {
45  timerMsg = new cMessage("generateNextPacket");
46  outInterface = CHK(interfaceTable->findInterfaceByName(par("interface")))->getInterfaceId();
47  }
48 
50 
51  if (stage == INITSTAGE_LOCAL) {
52  interfaceTable.reference(this, "interfaceTableModule", true);
53  sendInterval = &par("sendInterval");
54  numPacketsPerBurst = &par("numPacketsPerBurst");
55  packetLength = &par("packetLength");
56  ssap = par("ssap");
57  dsap = par("dsap");
58 
59  seqNum = 0;
60  WATCH(seqNum);
61 
62  // statistics
64  WATCH(packetsSent);
65  WATCH(packetsReceived);
66 
67  startTime = par("startTime");
68  stopTime = par("stopTime");
69  if (stopTime >= SIMTIME_ZERO && stopTime < startTime)
70  throw cRuntimeError("Invalid startTime/stopTime parameters");
71  llcSocket.setOutputGate(gate("out"));
72  }
73 }

◆ isGenerator()

bool inet::EtherTrafGen::isGenerator ( )
protectedvirtual
113 {
114  return par("destAddress").stringValue()[0];
115 }

Referenced by handleStartOperation(), and initialize().

◆ numInitStages()

virtual int inet::EtherTrafGen::numInitStages ( ) const
inlineoverrideprotectedvirtual
53 { return NUM_INIT_STAGES; }

◆ receivePacket()

void inet::EtherTrafGen::receivePacket ( Packet msg)
protectedvirtual
175 {
176  EV_INFO << "Received packet `" << msg->getName() << "' length= " << msg->getByteLength() << "B\n";
177 
178  packetsReceived++;
179  emit(packetReceivedSignal, msg);
180  delete msg;
181 }

Referenced by handleMessageWhenUp().

◆ resolveDestMacAddress()

MacAddress inet::EtherTrafGen::resolveDestMacAddress ( )
protectedvirtual
138 {
139  MacAddress destMacAddress;
140  const char *destAddress = par("destAddress");
141  if (destAddress[0])
142  destMacAddress = L3AddressResolver().resolve(destAddress, L3AddressResolver::ADDR_MAC).toMac();
143  return destMacAddress;
144 }

Referenced by handleMessageWhenUp().

◆ scheduleNextPacket()

void inet::EtherTrafGen::scheduleNextPacket ( simtime_t  previous)
protectedvirtual
118 {
119  simtime_t next;
120  if (previous == -1) {
121  next = simTime() <= startTime ? startTime : simTime();
122  timerMsg->setKind(START);
123  }
124  else {
125  next = previous + *sendInterval;
126  timerMsg->setKind(NEXT);
127  }
128  if (stopTime < SIMTIME_ZERO || next < stopTime)
129  scheduleAt(next, timerMsg);
130 }

Referenced by handleMessageWhenUp(), and handleStartOperation().

◆ sendBurstPackets()

void inet::EtherTrafGen::sendBurstPackets ( )
protectedvirtual
147 {
148  int n = *numPacketsPerBurst;
149  for (int i = 0; i < n; i++) {
150  seqNum++;
151 
152  char msgname[40];
153  sprintf(msgname, "pk-%d-%ld", getId(), seqNum);
154 
155  Packet *datapacket = new Packet(msgname, SOCKET_C_DATA);
156  long len = *packetLength;
157  const auto& payload = makeShared<ByteCountChunk>(B(len));
158  payload->addTag<CreationTimeTag>()->setCreationTime(simTime());
159  datapacket->insertAtBack(payload);
160  datapacket->addTag<DispatchProtocolReq>()->setProtocol(&Protocol::ieee8022llc);
161  datapacket->addTag<MacAddressReq>()->setDestAddress(destMacAddress);
162  datapacket->addTag<InterfaceReq>()->setInterfaceId(outInterface);
163  auto sapTag = datapacket->addTag<Ieee802SapReq>();
164  sapTag->setSsap(ssap);
165  sapTag->setDsap(dsap);
166 
167  EV_INFO << "Send packet `" << msgname << "' dest=" << destMacAddress << " length=" << len << "B ssap/dsap=" << ssap << "/" << dsap << "\n";
168  emit(packetSentSignal, datapacket);
169  send(datapacket, "out");
170  packetsSent++;
171  }
172 }

Referenced by handleMessageWhenUp().

Member Data Documentation

◆ destMacAddress

MacAddress inet::EtherTrafGen::destMacAddress
protected

◆ dsap

int inet::EtherTrafGen::dsap = -1
protected

Referenced by initialize(), and sendBurstPackets().

◆ interfaceTable

ModuleRefByPar<IInterfaceTable> inet::EtherTrafGen::interfaceTable
protected

Referenced by initialize().

◆ llcSocket

Ieee8022LlcSocket inet::EtherTrafGen::llcSocket
protected

◆ numPacketsPerBurst

cPar* inet::EtherTrafGen::numPacketsPerBurst = nullptr
protected

◆ outInterface

int inet::EtherTrafGen::outInterface = -1
protected

Referenced by initialize(), and sendBurstPackets().

◆ packetLength

cPar* inet::EtherTrafGen::packetLength = nullptr
protected

◆ packetsReceived

long inet::EtherTrafGen::packetsReceived = 0
protected

Referenced by initialize(), and receivePacket().

◆ packetsSent

long inet::EtherTrafGen::packetsSent = 0
protected

Referenced by initialize(), and sendBurstPackets().

◆ sendInterval

cPar* inet::EtherTrafGen::sendInterval = nullptr
protected

◆ seqNum

long inet::EtherTrafGen::seqNum = 0
protected

Referenced by initialize(), and sendBurstPackets().

◆ ssap

int inet::EtherTrafGen::ssap = -1
protected

◆ startTime

simtime_t inet::EtherTrafGen::startTime
protected

Referenced by initialize(), and scheduleNextPacket().

◆ stopTime

simtime_t inet::EtherTrafGen::stopTime
protected

Referenced by initialize(), and scheduleNextPacket().

◆ timerMsg

cMessage* inet::EtherTrafGen::timerMsg = nullptr
protected

The documentation for this class was generated from the following files:
CHK
#define CHK(x)
Definition: INETDefs.h:87
inet::EtherTrafGen::packetLength
cPar * packetLength
Definition: EtherTrafGen.h:35
inet::EtherTrafGen::ssap
int ssap
Definition: EtherTrafGen.h:36
inet::SocketBase::setOutputGate
void setOutputGate(cGate *gate)
Sets the gate on which to send messages.
Definition: SocketBase.h:36
inet::EtherTrafGen::scheduleNextPacket
virtual void scheduleNextPacket(simtime_t previous)
Definition: EtherTrafGen.cc:117
inet::getContainingNode
cModule * getContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:40
inet::OperationalMixin< cSimpleModule >::initialize
virtual void initialize(int stage) override
Definition: OperationalMixinImpl.h:26
InterfaceReq
removed InterfaceReq
Definition: IUdp-gates.txt:11
inet::EtherTrafGen::dsap
int dsap
Definition: EtherTrafGen.h:37
DispatchProtocolReq
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down DispatchProtocolReq
Definition: IUdp-gates.txt:25
inet::EtherTrafGen::destMacAddress
MacAddress destMacAddress
Definition: EtherTrafGen.h:38
inet::EtherTrafGen::resolveDestMacAddress
virtual MacAddress resolveDestMacAddress()
Definition: EtherTrafGen.cc:137
inet::packetSentSignal
simsignal_t packetSentSignal
Definition: Simsignals.cc:96
inet::EtherTrafGen::startTime
simtime_t startTime
Definition: EtherTrafGen.h:44
inet::L3AddressResolver::ADDR_MAC
@ ADDR_MAC
Definition: L3AddressResolver.h:72
inet::EtherTrafGen::packetsReceived
long packetsReceived
Definition: EtherTrafGen.h:49
inet::Protocol::ieee8022llc
static const Protocol ieee8022llc
Definition: Protocol.h:88
inet::EtherTrafGen::numPacketsPerBurst
cPar * numPacketsPerBurst
Definition: EtherTrafGen.h:34
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::packetReceivedSignal
simsignal_t packetReceivedSignal
Definition: Simsignals.cc:97
inet::EtherTrafGen::seqNum
long seqNum
Definition: EtherTrafGen.h:30
inet::EtherTrafGen::cancelNextPacket
virtual void cancelNextPacket()
Definition: EtherTrafGen.cc:132
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::EtherTrafGen::interfaceTable
ModuleRefByPar< IInterfaceTable > interfaceTable
Definition: EtherTrafGen.h:28
inet::EtherTrafGen::packetsSent
long packetsSent
Definition: EtherTrafGen.h:48
inet::EtherTrafGen::stopTime
simtime_t stopTime
Definition: EtherTrafGen.h:45
inet::SOCKET_C_DATA
@ SOCKET_C_DATA
Definition: SocketCommand_m.h:64
inet::SocketBase::close
virtual void close() override
Unbinds the socket.
Definition: SocketBase.cc:43
inet::MacAddress::isUnspecified
bool isUnspecified() const
Returns true if all address bytes are zero.
Definition: MacAddress.h:136
inet::INITSTAGE_APPLICATION_LAYER
INET_API InitStage INITSTAGE_APPLICATION_LAYER
Initialization of applications.
inet::Ieee8022LlcSocket::open
virtual void open(int interfaceId, int localSap, int remoteSap)
Definition: Ieee8022LlcSocket.cc:40
inet::EtherTrafGen::sendInterval
cPar * sendInterval
Definition: EtherTrafGen.h:33
inet::EtherTrafGen::timerMsg
cMessage * timerMsg
Definition: EtherTrafGen.h:43
inet::EtherTrafGen::NEXT
@ NEXT
Definition: EtherTrafGen.h:26
inet::EtherTrafGen::llcSocket
Ieee8022LlcSocket llcSocket
Definition: EtherTrafGen.h:41
inet::EtherTrafGen::sendBurstPackets
virtual void sendBurstPackets()
Definition: EtherTrafGen.cc:146
inet::EtherTrafGen::receivePacket
virtual void receivePacket(Packet *msg)
Definition: EtherTrafGen.cc:174
inet::SocketBase::destroy
virtual void destroy() override
Notify the protocol that the owner of ISocket has destroyed the socket.
Definition: SocketBase.cc:52
inet::EtherTrafGen::isGenerator
virtual bool isGenerator()
Definition: EtherTrafGen.cc:112
inet::EtherTrafGen::outInterface
int outInterface
Definition: EtherTrafGen.h:39
inet::EtherTrafGen::START
@ START
Definition: EtherTrafGen.h:26