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

Ethernet application. More...

#include <EthernetApplication.h>

Inheritance diagram for inet::EthernetApplication:

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 MACAddress resolveDestMACAddress ()
 
virtual void sendPacket ()
 
void sendPacket (cMessage *datapacket, const MACAddress &destAddr)
 
virtual void receivePacket (cMessage *msg)
 

Protected Attributes

long seqNum = 0
 
cPar * reqLength = nullptr
 
cPar * respLength = nullptr
 
cPar * waitTime = nullptr
 
MACAddress destMACAddress
 
long packetsSent = 0
 
long packetsReceived = 0
 

Static Protected Attributes

static simsignal_t sentPkSignal = SIMSIGNAL_NULL
 
static simsignal_t rcvdPkSignal = SIMSIGNAL_NULL
 

Detailed Description

Ethernet application.

Both, server and client side.

Member Function Documentation

void inet::EthernetApplication::finish ( )
overrideprotectedvirtual
158 {
159 }
void inet::EthernetApplication::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
74 {
75  if (msg->isSelfMessage()) {
76  sendPacket();
77  simtime_t d = waitTime->doubleValue();
78  scheduleAt(simTime() + d, msg);
79  }
80  else {
81  receivePacket(msg);
82  }
83 }
cPar * waitTime
Definition: EthernetApplication.h:33
virtual void sendPacket()
Definition: EthernetApplication.cc:85
virtual void receivePacket(cMessage *msg)
Definition: EthernetApplication.cc:111
void inet::EthernetApplication::initialize ( int  stage)
overrideprotectedvirtual
24 {
25  // we can only initialize in the 2nd stage (stage==1), because
26  // assignment of "auto" MAC addresses takes place in stage 0
27  if (stage == INITSTAGE_APPLICATION_LAYER) {
28  reqLength = &par("reqLength");
29  respLength = &par("respLength");
30  waitTime = &par("waitTime");
31 
32  seqNum = 0;
33  WATCH(seqNum);
34 
35  // statistics
37  sentPkSignal = registerSignal("sentPk");
38  rcvdPkSignal = registerSignal("rcvdPk");
39  WATCH(packetsSent);
40  WATCH(packetsReceived);
41 
43 
44  // if no dest address is given, nothing to do
46  return;
47 
48  cMessage *timermsg = new cMessage("generateNextPacket");
49  simtime_t d = par("startTime").doubleValue();
50  scheduleAt(simTime() + d, timermsg);
51  }
52 }
static simsignal_t sentPkSignal
Definition: EthernetApplication.h:41
cPar * waitTime
Definition: EthernetApplication.h:33
bool isUnspecified() const
Returns true if all address bytes are zero.
Definition: MACAddress.h:151
long packetsReceived
Definition: EthernetApplication.h:39
static simsignal_t rcvdPkSignal
Definition: EthernetApplication.h:42
long packetsSent
Definition: EthernetApplication.h:38
cPar * respLength
Definition: EthernetApplication.h:32
MACAddress destMACAddress
Definition: EthernetApplication.h:35
long seqNum
Definition: EthernetApplication.h:30
cPar * reqLength
Definition: EthernetApplication.h:31
virtual MACAddress resolveDestMACAddress()
Definition: EthernetApplication.cc:54
Initialization of applications.
Definition: InitStages.h:106
virtual int inet::EthernetApplication::numInitStages ( ) const
inlineoverrideprotectedvirtual
47 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::EthernetApplication::receivePacket ( cMessage *  msg)
protectedvirtual

Referenced by handleMessage().

112 {
113  EV << "Received packet `" << msg->getName() << "'\n";
114 
115  packetsReceived++;
116  // simtime_t lastEED = simTime() - msg->getCreationTime();
117 
118  if (dynamic_cast<EtherAppReq *>(msg)) {
119  EtherAppReq *req = check_and_cast<EtherAppReq *>(msg);
120  emit(rcvdPkSignal, req);
121  Ieee802Ctrl *ctrl = check_and_cast<Ieee802Ctrl *>(req->removeControlInfo());
122  MACAddress srcAddr = ctrl->getSrc();
123  long requestId = req->getRequestId();
124  long replyBytes = req->getResponseBytes();
125  delete ctrl;
126 
127  // send back packets asked by EthernetApplication Client side
128  for (int k = 0; replyBytes > 0; k++) {
129  int l = replyBytes > MAX_REPLY_CHUNK_SIZE ? MAX_REPLY_CHUNK_SIZE : replyBytes;
130  replyBytes -= l;
131 
132  std::ostringstream s;
133  s << msg->getName() << "-resp-" << k;
134 
135  EV << "Generating packet `" << s.str().c_str() << "'\n";
136 
137  EtherAppResp *datapacket = new EtherAppResp(s.str().c_str(), IEEE802CTRL_DATA);
138  datapacket->setRequestId(requestId);
139  datapacket->setByteLength(l);
140  sendPacket(datapacket, srcAddr);
141  packetsSent++;
142  }
143  }
144 
145  delete msg;
146 }
Definition: Ieee802Ctrl_m.h:54
#define MAX_REPLY_CHUNK_SIZE
Definition: EtherAppSrv.h:30
virtual void sendPacket()
Definition: EthernetApplication.cc:85
long packetsReceived
Definition: EthernetApplication.h:39
static simsignal_t rcvdPkSignal
Definition: EthernetApplication.h:42
long packetsSent
Definition: EthernetApplication.h:38
value< double, units::s > s
Definition: Units.h:1049
const double k
Definition: QAM16Modulation.cc:24
MACAddress inet::EthernetApplication::resolveDestMACAddress ( )
protectedvirtual

Referenced by initialize().

55 {
56  MACAddress destMACAddress;
57  const char *destAddress = par("destAddress");
58  if (destAddress[0]) {
59  // try as mac address first, then as a module
60  if (!destMACAddress.tryParse(destAddress)) {
61  cModule *destStation = getModuleByPath(destAddress);
62  if (!destStation)
63  throw cRuntimeError("cannot resolve MAC address '%s': not a 12-hex-digit MAC address or a valid module path name", destAddress);
64  cModule *destMAC = destStation->getSubmodule("mac");
65  if (!destMAC)
66  throw cRuntimeError("module '%s' has no 'mac' submodule", destAddress);
67  destMACAddress.setAddress(destMAC->par("address"));
68  }
69  }
70  return destMACAddress;
71 }
MACAddress destMACAddress
Definition: EthernetApplication.h:35
void inet::EthernetApplication::sendPacket ( )
protectedvirtual

Referenced by handleMessage(), and receivePacket().

86 {
87  seqNum++;
88 
89  char msgname[30];
90  sprintf(msgname, "req-%d-%ld", getId(), seqNum);
91  EV << "Generating packet `" << msgname << "'\n";
92 
93  EtherAppReq *datapacket = new EtherAppReq(msgname, IEEE802CTRL_DATA);
94 
95  datapacket->setRequestId(seqNum);
96 
97  long len = reqLength->longValue();
98  datapacket->setByteLength(len);
99 
100  long respLen = respLength->longValue();
101  datapacket->setResponseBytes(respLen);
102 
103  Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
104  etherctrl->setDest(destMACAddress);
105  datapacket->setControlInfo(etherctrl);
106 
107  send(datapacket, "out");
108  packetsSent++;
109 }
Definition: Ieee802Ctrl_m.h:54
uint16_t len
Definition: TCP_NSC.cc:85
long packetsSent
Definition: EthernetApplication.h:38
cPar * respLength
Definition: EthernetApplication.h:32
MACAddress destMACAddress
Definition: EthernetApplication.h:35
long seqNum
Definition: EthernetApplication.h:30
cPar * reqLength
Definition: EthernetApplication.h:31
void inet::EthernetApplication::sendPacket ( cMessage *  datapacket,
const MACAddress destAddr 
)
protected
149 {
150  Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
151  etherctrl->setDest(destAddr);
152  datapacket->setControlInfo(etherctrl);
153  emit(sentPkSignal, datapacket);
154  send(datapacket, "out");
155 }
static simsignal_t sentPkSignal
Definition: EthernetApplication.h:41

Member Data Documentation

MACAddress inet::EthernetApplication::destMACAddress
protected
long inet::EthernetApplication::packetsReceived = 0
protected

Referenced by initialize(), and receivePacket().

long inet::EthernetApplication::packetsSent = 0
protected
simsignal_t inet::EthernetApplication::rcvdPkSignal = SIMSIGNAL_NULL
staticprotected

Referenced by initialize(), and receivePacket().

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

Referenced by initialize(), and sendPacket().

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

Referenced by initialize(), and sendPacket().

simsignal_t inet::EthernetApplication::sentPkSignal = SIMSIGNAL_NULL
staticprotected

Referenced by initialize(), and sendPacket().

long inet::EthernetApplication::seqNum = 0
protected

Referenced by initialize(), and sendPacket().

cPar* inet::EthernetApplication::waitTime = nullptr
protected

Referenced by handleMessage(), and initialize().


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