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

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

#include <EtherAppClient.h>

Inheritance diagram for inet::EtherAppClient:
inet::ApplicationBase inet::Ieee8022LlcSocket::ICallback inet::OperationalBase inet::OperationalMixin< cSimpleModule > inet::ILifecycle

Public Member Functions

 EtherAppClient ()
 
virtual ~EtherAppClient ()
 
- 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 ()
 
- Public Member Functions inherited from inet::Ieee8022LlcSocket::ICallback
virtual ~ICallback ()
 

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 (bool start)
 
virtual void cancelNextPacket ()
 
virtual MacAddress resolveDestMacAddress ()
 
virtual void sendPacket ()
 
virtual void socketDataArrived (Ieee8022LlcSocket *, Packet *msg) override
 
virtual void socketClosed (Ieee8022LlcSocket *socket) override
 
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

long seqNum = 0
 
cPar * reqLength = nullptr
 
cPar * respLength = nullptr
 
cPar * sendInterval = nullptr
 
int localSap = -1
 
int remoteSap = -1
 
MacAddress destMacAddress
 
ModuleRefByPar< IInterfaceTableinterfaceTable
 
cMessage * timerMsg = nullptr
 
simtime_t startTime
 
simtime_t stopTime
 
Ieee8022LlcSocket llcSocket
 
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

Enumerator
START 
NEXT 
26 { START = 100, NEXT };

Constructor & Destructor Documentation

◆ EtherAppClient()

inet::EtherAppClient::EtherAppClient ( )
inline
74 {}

◆ ~EtherAppClient()

inet::EtherAppClient::~EtherAppClient ( )
virtual
28 {
29  cancelAndDelete(timerMsg);
30 }

Member Function Documentation

◆ cancelNextPacket()

void inet::EtherAppClient::cancelNextPacket ( )
protectedvirtual
133 {
134  if (timerMsg)
135  cancelEvent(timerMsg);
136 }

Referenced by handleCrashOperation(), and handleStopOperation().

◆ finish()

void inet::EtherAppClient::finish ( )
overrideprotectedvirtual
191 {
192  cancelAndDelete(timerMsg);
193  timerMsg = nullptr;
194 }

◆ handleCrashOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

99 {
101  if (operation->getRootModule() != getContainingNode(this))
102  llcSocket.destroy();
103 }

◆ handleMessageWhenUp()

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

Implements inet::OperationalMixin< cSimpleModule >.

66 {
67  if (msg->isSelfMessage()) {
68  if (msg->getKind() == START) {
69  EV_DEBUG << getFullPath() << " registering DSAP " << localSap << "\n";
70  int interfaceId = CHK(interfaceTable->findInterfaceByName(par("interface")))->getInterfaceId();
71  llcSocket.open(interfaceId, localSap, -1);
72 
74  // if no dest address given, nothing to do
76  return;
77  }
78  sendPacket();
79  scheduleNextPacket(false);
80  }
81  else
83 }

◆ handleStartOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

86 {
87  if (isGenerator())
88  scheduleNextPacket(true);
89 }

◆ handleStopOperation()

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

Implements inet::OperationalMixin< cSimpleModule >.

92 {
94  llcSocket.close();
95  delayActiveOperationFinish(par("stopOperationTimeout"));
96 }

◆ initialize()

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

Reimplemented from inet::OperationalMixin< cSimpleModule >.

33 {
34  if (stage == INITSTAGE_APPLICATION_LAYER && isGenerator())
35  timerMsg = new cMessage("generateNextPacket");
36 
38 
39  if (stage == INITSTAGE_LOCAL) {
40  reqLength = &par("reqLength");
41  respLength = &par("respLength");
42  sendInterval = &par("sendInterval");
43  interfaceTable.reference(this, "interfaceTableModule", true);
44 
45  localSap = par("localSAP");
46  remoteSap = par("remoteSAP");
47 
48  seqNum = 0;
49  WATCH(seqNum);
50 
51  // statistics
53  WATCH(packetsSent);
54  WATCH(packetsReceived);
55 
56  startTime = par("startTime");
57  stopTime = par("stopTime");
58  if (stopTime >= SIMTIME_ZERO && stopTime < startTime)
59  throw cRuntimeError("Invalid startTime/stopTime parameters");
60  llcSocket.setOutputGate(gate("out"));
61  llcSocket.setCallback(this);
62  }
63 }

◆ isGenerator()

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

Referenced by handleStartOperation(), and initialize().

◆ numInitStages()

virtual int inet::EtherAppClient::numInitStages ( ) const
inlineoverrideprotectedvirtual
52 { return NUM_INIT_STAGES; }

◆ resolveDestMacAddress()

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

Referenced by handleMessageWhenUp().

◆ scheduleNextPacket()

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

Referenced by handleMessageWhenUp(), and handleStartOperation().

◆ sendPacket()

void inet::EtherAppClient::sendPacket ( )
protectedvirtual
150 {
151  seqNum++;
152 
153  char msgname[30];
154  sprintf(msgname, "req-%d-%ld", getId(), seqNum);
155  EV_INFO << "Generating packet `" << msgname << "'\n";
156 
157  Packet *datapacket = new Packet(msgname);
158  const auto& data = makeShared<EtherAppReq>();
159 
160  long len = *reqLength;
161  data->setChunkLength(B(len));
162  data->setRequestId(seqNum);
163 
164  long respLen = *respLength;
165  data->setResponseBytes(respLen);
166 
167  data->addTag<CreationTimeTag>()->setCreationTime(simTime());
168 
169  datapacket->insertAtBack(data);
170 
171  datapacket->addTag<MacAddressReq>()->setDestAddress(destMacAddress);
172  auto ieee802SapReq = datapacket->addTag<Ieee802SapReq>();
173  ieee802SapReq->setSsap(localSap);
174  ieee802SapReq->setDsap(remoteSap);
175 
176  emit(packetSentSignal, datapacket);
177  llcSocket.send(datapacket);
178  packetsSent++;
179 }

Referenced by handleMessageWhenUp().

◆ socketClosed()

void inet::EtherAppClient::socketClosed ( inet::Ieee8022LlcSocket socket)
overrideprotectedvirtual

Implements inet::Ieee8022LlcSocket::ICallback.

106 {
107  if (operationalState == State::STOPPING_OPERATION && !llcSocket.isOpen())
108  startActiveOperationExtraTimeOrFinish(par("stopOperationExtraTime"));
109 }

◆ socketDataArrived()

void inet::EtherAppClient::socketDataArrived ( Ieee8022LlcSocket ,
Packet msg 
)
overrideprotectedvirtual

Implements inet::Ieee8022LlcSocket::ICallback.

182 {
183  EV_INFO << "Received packet `" << msg->getName() << "'\n";
184 
185  packetsReceived++;
186  emit(packetReceivedSignal, msg);
187  delete msg;
188 }

Member Data Documentation

◆ destMacAddress

MacAddress inet::EtherAppClient::destMacAddress
protected

◆ interfaceTable

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

Referenced by handleMessageWhenUp(), and initialize().

◆ llcSocket

◆ localSap

int inet::EtherAppClient::localSap = -1
protected

◆ packetsReceived

long inet::EtherAppClient::packetsReceived = 0
protected

Referenced by initialize(), and socketDataArrived().

◆ packetsSent

long inet::EtherAppClient::packetsSent = 0
protected

Referenced by initialize(), and sendPacket().

◆ remoteSap

int inet::EtherAppClient::remoteSap = -1
protected

Referenced by initialize(), and sendPacket().

◆ reqLength

cPar* inet::EtherAppClient::reqLength = nullptr
protected

Referenced by initialize(), and sendPacket().

◆ respLength

cPar* inet::EtherAppClient::respLength = nullptr
protected

Referenced by initialize(), and sendPacket().

◆ sendInterval

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

Referenced by initialize(), and scheduleNextPacket().

◆ seqNum

long inet::EtherAppClient::seqNum = 0
protected

Referenced by initialize(), and sendPacket().

◆ startTime

simtime_t inet::EtherAppClient::startTime
protected

Referenced by initialize(), and scheduleNextPacket().

◆ stopTime

simtime_t inet::EtherAppClient::stopTime
protected

Referenced by initialize(), and scheduleNextPacket().

◆ timerMsg

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

The documentation for this class was generated from the following files:
CHK
#define CHK(x)
Definition: INETDefs.h:87
inet::Ieee8022LlcSocket::setCallback
void setCallback(ICallback *callback)
Sets a callback object, to be used with processMessage().
Definition: Ieee8022LlcSocket.h:49
inet::OperationalMixin< cSimpleModule >::operationalState
State operationalState
Definition: OperationalMixin.h:23
inet::EtherAppClient::sendInterval
cPar * sendInterval
Definition: EtherAppClient.h:32
inet::SocketBase::setOutputGate
void setOutputGate(cGate *gate)
Sets the gate on which to send messages.
Definition: SocketBase.h:36
inet::MacAddress::tryParse
bool tryParse(const char *hexstr)
Sets the address and returns true if the syntax of the string is correct.
Definition: MacAddress.cc:39
inet::EtherAppClient::isGenerator
virtual bool isGenerator()
Definition: EtherAppClient.cc:111
inet::EtherAppClient::respLength
cPar * respLength
Definition: EtherAppClient.h:31
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
inet::EtherAppClient::NEXT
@ NEXT
Definition: EtherAppClient.h:26
inet::EtherAppClient::reqLength
cPar * reqLength
Definition: EtherAppClient.h:30
inet::packetSentSignal
simsignal_t packetSentSignal
Definition: Simsignals.cc:96
inet::L3AddressResolver::ADDR_MAC
@ ADDR_MAC
Definition: L3AddressResolver.h:72
inet::EtherAppClient::interfaceTable
ModuleRefByPar< IInterfaceTable > interfaceTable
Definition: EtherAppClient.h:37
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::EtherAppClient::destMacAddress
MacAddress destMacAddress
Definition: EtherAppClient.h:36
inet::packetReceivedSignal
simsignal_t packetReceivedSignal
Definition: Simsignals.cc:97
inet::EtherAppClient::llcSocket
Ieee8022LlcSocket llcSocket
Definition: EtherAppClient.h:44
inet::EtherAppClient::packetsSent
long packetsSent
Definition: EtherAppClient.h:47
inet::EtherAppClient::cancelNextPacket
virtual void cancelNextPacket()
Definition: EtherAppClient.cc:132
inet::EtherAppClient::startTime
simtime_t startTime
Definition: EtherAppClient.h:41
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::EtherAppClient::localSap
int localSap
Definition: EtherAppClient.h:34
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::SocketBase::isOpen
virtual bool isOpen() const override
Returns true if the socket is open.
Definition: SocketBase.h:55
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::SocketBase::send
virtual void send(Packet *packet) override
Sends a data packet to the address and port specified previously in a connect() call.
Definition: SocketBase.cc:36
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::OperationalMixin< cSimpleModule >::delayActiveOperationFinish
virtual void delayActiveOperationFinish(simtime_t timeout)
Definition: OperationalMixinImpl.h:161
inet::OperationalMixin< cSimpleModule >::startActiveOperationExtraTimeOrFinish
virtual void startActiveOperationExtraTimeOrFinish(simtime_t extraTime)
Definition: OperationalMixinImpl.h:179
inet::EtherAppClient::seqNum
long seqNum
Definition: EtherAppClient.h:29
inet::EtherAppClient::sendPacket
virtual void sendPacket()
Definition: EtherAppClient.cc:149
inet::EtherAppClient::remoteSap
int remoteSap
Definition: EtherAppClient.h:35
inet::EtherAppClient::timerMsg
cMessage * timerMsg
Definition: EtherAppClient.h:40
inet::EtherAppClient::packetsReceived
long packetsReceived
Definition: EtherAppClient.h:48
inet::EtherAppClient::stopTime
simtime_t stopTime
Definition: EtherAppClient.h:42
inet::Ieee8022LlcSocket::processMessage
virtual void processMessage(cMessage *msg) override
Examines the message, takes ownership, and updates socket state.
Definition: Ieee8022LlcSocket.cc:57
inet::EtherAppClient::scheduleNextPacket
virtual void scheduleNextPacket(bool start)
Definition: EtherAppClient.cc:116
inet::EtherAppClient::resolveDestMacAddress
virtual MacAddress resolveDestMacAddress()
Definition: EtherAppClient.cc:138
inet::EtherAppClient::START
@ START
Definition: EtherAppClient.h:26
inet::SocketBase::destroy
virtual void destroy() override
Notify the protocol that the owner of ISocket has destroyed the socket.
Definition: SocketBase.cc:52