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

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

#include <EtherAppCli.h>

Inheritance diagram for inet::EtherAppCli:
inet::ILifecycle

Public Member Functions

 EtherAppCli ()
 
virtual ~EtherAppCli ()
 
- Public Member Functions inherited from inet::ILifecycle
virtual ~ILifecycle ()
 

Protected Types

enum  Kinds { START = 100, NEXT }
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
virtual bool isNodeUp ()
 
virtual bool isGenerator ()
 
virtual void scheduleNextPacket (bool start)
 
virtual void cancelNextPacket ()
 
virtual MACAddress resolveDestMACAddress ()
 
virtual void sendPacket ()
 
virtual void receivePacket (cPacket *msg)
 
virtual void registerDSAP (int dsap)
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Protected Attributes

long seqNum = 0
 
cPar * reqLength = nullptr
 
cPar * respLength = nullptr
 
cPar * sendInterval = nullptr
 
int localSAP = -1
 
int remoteSAP = -1
 
MACAddress destMACAddress
 
NodeStatusnodeStatus = nullptr
 
cMessage * timerMsg = nullptr
 
simtime_t startTime
 
simtime_t stopTime
 
long packetsSent = 0
 
long packetsReceived = 0
 

Static Protected Attributes

static simsignal_t sentPkSignal = registerSignal("sentPk")
 
static simsignal_t rcvdPkSignal = registerSignal("rcvdPk")
 

Detailed Description

Simple traffic generator for the Ethernet model.

Member Enumeration Documentation

enum inet::EtherAppCli::Kinds
protected
Enumerator
START 
NEXT 
35 { START = 100, NEXT };
Definition: EtherAppCli.h:35
Definition: EtherAppCli.h:35

Constructor & Destructor Documentation

inet::EtherAppCli::EtherAppCli ( )
inline
78 {}
inet::EtherAppCli::~EtherAppCli ( )
virtual
37 {
38  cancelAndDelete(timerMsg);
39 }
cMessage * timerMsg
Definition: EtherAppCli.h:49

Member Function Documentation

void inet::EtherAppCli::cancelNextPacket ( )
protectedvirtual

Referenced by handleOperationStage().

146 {
147  if (timerMsg)
148  cancelEvent(timerMsg);
149 }
cMessage * timerMsg
Definition: EtherAppCli.h:49
void inet::EtherAppCli::finish ( )
overrideprotectedvirtual
223 {
224  cancelAndDelete(timerMsg);
225  timerMsg = nullptr;
226 }
cMessage * timerMsg
Definition: EtherAppCli.h:49
void inet::EtherAppCli::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
78 {
79  if (!isNodeUp())
80  throw cRuntimeError("Application is not running");
81  if (msg->isSelfMessage()) {
82  if (msg->getKind() == START) {
83  bool registerSAP = par("registerSAP");
84  if (registerSAP)
86 
88  // if no dest address given, nothing to do
90  return;
91  }
92  sendPacket();
93  scheduleNextPacket(false);
94  }
95  else
96  receivePacket(check_and_cast<cPacket *>(msg));
97 }
MACAddress destMACAddress
Definition: EtherAppCli.h:45
int localSAP
Definition: EtherAppCli.h:43
bool isUnspecified() const
Returns true if all address bytes are zero.
Definition: MACAddress.h:151
virtual bool isNodeUp()
Definition: EtherAppCli.cc:119
virtual void registerDSAP(int dsap)
Definition: EtherAppCli.cc:172
virtual void sendPacket()
Definition: EtherAppCli.cc:184
virtual void scheduleNextPacket(bool start)
Definition: EtherAppCli.cc:129
Definition: EtherAppCli.h:35
virtual void receivePacket(cPacket *msg)
Definition: EtherAppCli.cc:213
virtual MACAddress resolveDestMACAddress()
Definition: EtherAppCli.cc:151
bool inet::EtherAppCli::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
overrideprotectedvirtual

Perform one stage of a lifecycle operation.

Processing may be done entirely within this method, or may be a longer process that involves nonzero simulation time or several events, and is triggered by this method call.

Return value: true = "done"; false = "not yet done, will invoke doneCallback when done"

Implements inet::ILifecycle.

100 {
101  Enter_Method_Silent();
102  if (dynamic_cast<NodeStartOperation *>(operation)) {
104  scheduleNextPacket(true);
105  }
106  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
109  }
110  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
113  }
114  else
115  throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName());
116  return true;
117 }
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
virtual void scheduleNextPacket(bool start)
Definition: EtherAppCli.cc:129
virtual void cancelNextPacket()
Definition: EtherAppCli.cc:145
Stage
Definition: NodeOperations.h:46
Definition: NodeOperations.h:127
virtual bool isGenerator()
Definition: EtherAppCli.cc:124
void inet::EtherAppCli::initialize ( int  stage)
overrideprotectedvirtual
42 {
43  cSimpleModule::initialize(stage);
44 
45  if (stage == INITSTAGE_LOCAL) {
46  reqLength = &par("reqLength");
47  respLength = &par("respLength");
48  sendInterval = &par("sendInterval");
49 
50  localSAP = par("localSAP");
51  remoteSAP = par("remoteSAP");
52 
53  seqNum = 0;
54  WATCH(seqNum);
55 
56  // statistics
58  WATCH(packetsSent);
59  WATCH(packetsReceived);
60 
61  startTime = par("startTime");
62  stopTime = par("stopTime");
63  if (stopTime >= SIMTIME_ZERO && stopTime < startTime)
64  throw cRuntimeError("Invalid startTime/stopTime parameters");
65  }
66  else if (stage == INITSTAGE_APPLICATION_LAYER) {
67  if (isGenerator())
68  timerMsg = new cMessage("generateNextPacket");
69 
70  nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
71 
72  if (isNodeUp() && isGenerator())
73  scheduleNextPacket(true);
74  }
75 }
cPar * reqLength
Definition: EtherAppCli.h:39
int localSAP
Definition: EtherAppCli.h:43
long seqNum
Definition: EtherAppCli.h:38
simtime_t stopTime
Definition: EtherAppCli.h:51
virtual bool isNodeUp()
Definition: EtherAppCli.cc:119
cPar * sendInterval
Definition: EtherAppCli.h:41
cPar * respLength
Definition: EtherAppCli.h:40
simtime_t startTime
Definition: EtherAppCli.h:50
virtual void scheduleNextPacket(bool start)
Definition: EtherAppCli.cc:129
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
long packetsSent
Definition: EtherAppCli.h:54
long packetsReceived
Definition: EtherAppCli.h:55
int remoteSAP
Definition: EtherAppCli.h:44
cMessage * timerMsg
Definition: EtherAppCli.h:49
NodeStatus * nodeStatus
Definition: EtherAppCli.h:46
Initialization of applications.
Definition: InitStages.h:106
virtual bool isGenerator()
Definition: EtherAppCli.cc:124
bool inet::EtherAppCli::isGenerator ( )
protectedvirtual

Referenced by handleOperationStage(), and initialize().

125 {
126  return par("destAddress").stringValue()[0];
127 }
bool inet::EtherAppCli::isNodeUp ( )
protectedvirtual

Referenced by handleMessage(), and initialize().

120 {
121  return !nodeStatus || nodeStatus->getState() == NodeStatus::UP;
122 }
NodeStatus * nodeStatus
Definition: EtherAppCli.h:46
virtual State getState() const
Definition: NodeStatus.h:48
Definition: NodeStatus.h:40
virtual int inet::EtherAppCli::numInitStages ( ) const
inlineoverrideprotectedvirtual
61 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::EtherAppCli::receivePacket ( cPacket *  msg)
protectedvirtual

Referenced by handleMessage().

214 {
215  EV_INFO << "Received packet `" << msg->getName() << "'\n";
216 
217  packetsReceived++;
218  emit(rcvdPkSignal, msg);
219  delete msg;
220 }
static simsignal_t rcvdPkSignal
Definition: EtherAppCli.h:57
long packetsReceived
Definition: EtherAppCli.h:55
void inet::EtherAppCli::registerDSAP ( int  dsap)
protectedvirtual

Referenced by handleMessage().

173 {
174  EV_DEBUG << getFullPath() << " registering DSAP " << dsap << "\n";
175 
176  Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
177  etherctrl->setDsap(dsap);
178  cMessage *msg = new cMessage("register_DSAP", IEEE802CTRL_REGISTER_DSAP);
179  msg->setControlInfo(etherctrl);
180 
181  send(msg, "out");
182 }
Definition: Ieee802Ctrl_m.h:55
MACAddress inet::EtherAppCli::resolveDestMACAddress ( )
protectedvirtual

Referenced by handleMessage().

152 {
153  MACAddress destMACAddress;
154  const char *destAddress = par("destAddress");
155  if (destAddress[0]) {
156  // try as mac address first, then as a module
157  if (!destMACAddress.tryParse(destAddress)) {
158  cModule *destStation = getModuleByPath(destAddress);
159  if (!destStation)
160  throw cRuntimeError("cannot resolve MAC address '%s': not a 12-hex-digit MAC address or a valid module path name", destAddress);
161 
162  cModule *destMAC = destStation->getSubmodule("mac");
163  if (!destMAC)
164  throw cRuntimeError("module '%s' has no 'mac' submodule", destAddress);
165 
166  destMACAddress.setAddress(destMAC->par("address"));
167  }
168  }
169  return destMACAddress;
170 }
MACAddress destMACAddress
Definition: EtherAppCli.h:45
void inet::EtherAppCli::scheduleNextPacket ( bool  start)
protectedvirtual

Referenced by handleMessage(), handleOperationStage(), and initialize().

130 {
131  simtime_t cur = simTime();
132  simtime_t next;
133  if (start) {
134  next = cur <= startTime ? startTime : cur;
135  timerMsg->setKind(START);
136  }
137  else {
138  next = cur + sendInterval->doubleValue();
139  timerMsg->setKind(NEXT);
140  }
141  if (stopTime < SIMTIME_ZERO || next < stopTime)
142  scheduleAt(next, timerMsg);
143 }
simtime_t stopTime
Definition: EtherAppCli.h:51
Definition: EtherAppCli.h:35
cPar * sendInterval
Definition: EtherAppCli.h:41
simtime_t startTime
Definition: EtherAppCli.h:50
Definition: EtherAppCli.h:35
cMessage * timerMsg
Definition: EtherAppCli.h:49
void inet::EtherAppCli::sendPacket ( )
protectedvirtual

Referenced by handleMessage().

185 {
186  seqNum++;
187 
188  char msgname[30];
189  sprintf(msgname, "req-%d-%ld", getId(), seqNum);
190  EV_INFO << "Generating packet `" << msgname << "'\n";
191 
192  EtherAppReq *datapacket = new EtherAppReq(msgname, IEEE802CTRL_DATA);
193 
194  datapacket->setRequestId(seqNum);
195 
196  long len = reqLength->longValue();
197  datapacket->setByteLength(len);
198 
199  long respLen = respLength->longValue();
200  datapacket->setResponseBytes(respLen);
201 
202  Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
203  etherctrl->setSsap(localSAP);
204  etherctrl->setDsap(remoteSAP);
205  etherctrl->setDest(destMACAddress);
206  datapacket->setControlInfo(etherctrl);
207 
208  emit(sentPkSignal, datapacket);
209  send(datapacket, "out");
210  packetsSent++;
211 }
cPar * reqLength
Definition: EtherAppCli.h:39
Definition: Ieee802Ctrl_m.h:54
MACAddress destMACAddress
Definition: EtherAppCli.h:45
int localSAP
Definition: EtherAppCli.h:43
long seqNum
Definition: EtherAppCli.h:38
uint16_t len
Definition: TCP_NSC.cc:85
static simsignal_t sentPkSignal
Definition: EtherAppCli.h:56
cPar * respLength
Definition: EtherAppCli.h:40
long packetsSent
Definition: EtherAppCli.h:54
int remoteSAP
Definition: EtherAppCli.h:44

Member Data Documentation

MACAddress inet::EtherAppCli::destMACAddress
protected
int inet::EtherAppCli::localSAP = -1
protected
NodeStatus* inet::EtherAppCli::nodeStatus = nullptr
protected

Referenced by initialize(), and isNodeUp().

long inet::EtherAppCli::packetsReceived = 0
protected

Referenced by initialize(), and receivePacket().

long inet::EtherAppCli::packetsSent = 0
protected

Referenced by initialize(), and sendPacket().

simsignal_t inet::EtherAppCli::rcvdPkSignal = registerSignal("rcvdPk")
staticprotected

Referenced by receivePacket().

int inet::EtherAppCli::remoteSAP = -1
protected

Referenced by initialize(), and sendPacket().

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

Referenced by initialize(), and sendPacket().

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

Referenced by initialize(), and sendPacket().

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

Referenced by initialize(), and scheduleNextPacket().

simsignal_t inet::EtherAppCli::sentPkSignal = registerSignal("sentPk")
staticprotected

Referenced by sendPacket().

long inet::EtherAppCli::seqNum = 0
protected

Referenced by initialize(), and sendPacket().

simtime_t inet::EtherAppCli::startTime
protected

Referenced by initialize(), and scheduleNextPacket().

simtime_t inet::EtherAppCli::stopTime
protected

Referenced by initialize(), and scheduleNextPacket().

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

The documentation for this class was generated from the following files: