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

Server-side process EtherAppCli. More...

#include <EtherAppSrv.h>

Inheritance diagram for inet::EtherAppSrv:
inet::ILifecycle

Protected Member Functions

virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void startApp ()
 
virtual void stopApp ()
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 
virtual bool isNodeUp ()
 
void registerDSAP (int dsap)
 
void sendPacket (cPacket *datapacket, const MACAddress &destAddr, int destSap)
 

Protected Attributes

int localSAP = 0
 
NodeStatusnodeStatus = nullptr
 
long packetsSent = 0
 
long packetsReceived = 0
 

Static Protected Attributes

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

Additional Inherited Members

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

Detailed Description

Server-side process EtherAppCli.

Member Function Documentation

void inet::EtherAppSrv::finish ( )
overrideprotectedvirtual
157 {
158 }
void inet::EtherAppSrv::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
76 {
77  if (!isNodeUp())
78  throw cRuntimeError("Application is not running");
79 
80  EV_INFO << "Received packet `" << msg->getName() << "'\n";
81  EtherAppReq *req = check_and_cast<EtherAppReq *>(msg);
83  emit(rcvdPkSignal, req);
84 
85  Ieee802Ctrl *ctrl = check_and_cast<Ieee802Ctrl *>(req->removeControlInfo());
86  MACAddress srcAddr = ctrl->getSrc();
87  int srcSap = ctrl->getSsap();
88  long requestId = req->getRequestId();
89  long replyBytes = req->getResponseBytes();
90  delete ctrl;
91 
92  // send back packets asked by EtherAppCli side
93  for (int k = 0; replyBytes > 0; k++) {
94  int l = replyBytes > MAX_REPLY_CHUNK_SIZE ? MAX_REPLY_CHUNK_SIZE : replyBytes;
95  replyBytes -= l;
96 
97  std::ostringstream s;
98  s << msg->getName() << "-resp-" << k;
99 
100  EtherAppResp *datapacket = new EtherAppResp(s.str().c_str(), IEEE802CTRL_DATA);
101  datapacket->setRequestId(requestId);
102  datapacket->setByteLength(l);
103 
104  EV_INFO << "Send response `" << datapacket->getName() << "' to " << srcAddr << " ssap=" << localSAP << " dsap=" << srcSap << " length=" << l << "B requestId=" << requestId << "\n";
105 
106  sendPacket(datapacket, srcAddr, srcSap);
107  }
108 
109  delete msg;
110 }
Definition: Ieee802Ctrl_m.h:54
int localSAP
Definition: EtherAppSrv.h:38
long packetsReceived
Definition: EtherAppSrv.h:43
#define MAX_REPLY_CHUNK_SIZE
Definition: EtherAppSrv.h:30
void sendPacket(cPacket *datapacket, const MACAddress &destAddr, int destSap)
Definition: EtherAppSrv.cc:112
virtual bool isNodeUp()
Definition: EtherAppSrv.cc:57
value< double, units::s > s
Definition: Units.h:1049
static simsignal_t rcvdPkSignal
Definition: EtherAppSrv.h:45
const double k
Definition: QAM16Modulation.cc:24
bool inet::EtherAppSrv::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.

137 {
138  Enter_Method_Silent();
139  if (dynamic_cast<NodeStartOperation *>(operation)) {
141  startApp();
142  }
143  else if (dynamic_cast<NodeShutdownOperation *>(operation)) {
145  stopApp();
146  }
147  else if (dynamic_cast<NodeCrashOperation *>(operation)) {
149  stopApp();
150  }
151  else
152  throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName());
153  return true;
154 }
Stage
Definition: NodeOperations.h:71
Stage
Definition: NodeOperations.h:126
Stage
Definition: NodeOperations.h:46
virtual void stopApp()
Definition: EtherAppSrv.cc:70
Definition: NodeOperations.h:127
virtual void startApp()
Definition: EtherAppSrv.cc:62
void inet::EtherAppSrv::initialize ( int  stage)
overrideprotectedvirtual
37 {
38  cSimpleModule::initialize(stage);
39 
40  if (stage == INITSTAGE_LOCAL) {
41  localSAP = par("localSAP");
42 
43  // statistics
45 
46  WATCH(packetsSent);
47  WATCH(packetsReceived);
48  }
49  else if (stage == INITSTAGE_APPLICATION_LAYER) {
50  nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
51 
52  if (isNodeUp())
53  startApp();
54  }
55 }
int localSAP
Definition: EtherAppSrv.h:38
long packetsReceived
Definition: EtherAppSrv.h:43
long packetsSent
Definition: EtherAppSrv.h:42
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
virtual bool isNodeUp()
Definition: EtherAppSrv.cc:57
NodeStatus * nodeStatus
Definition: EtherAppSrv.h:39
virtual void startApp()
Definition: EtherAppSrv.cc:62
Initialization of applications.
Definition: InitStages.h:106
bool inet::EtherAppSrv::isNodeUp ( )
protectedvirtual

Referenced by handleMessage(), and initialize().

58 {
60 }
NodeStatus * nodeStatus
Definition: EtherAppSrv.h:39
virtual State getState() const
Definition: NodeStatus.h:48
Definition: NodeStatus.h:40
virtual int inet::EtherAppSrv::numInitStages ( ) const
inlineoverrideprotectedvirtual
49 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::EtherAppSrv::registerDSAP ( int  dsap)
protected

Referenced by startApp().

125 {
126  EV_DEBUG << getFullPath() << " registering DSAP " << dsap << "\n";
127 
128  Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
129  etherctrl->setDsap(dsap);
130  cMessage *msg = new cMessage("register_DSAP", IEEE802CTRL_REGISTER_DSAP);
131  msg->setControlInfo(etherctrl);
132 
133  send(msg, "out");
134 }
Definition: Ieee802Ctrl_m.h:55
void inet::EtherAppSrv::sendPacket ( cPacket *  datapacket,
const MACAddress destAddr,
int  destSap 
)
protected

Referenced by handleMessage().

113 {
114  Ieee802Ctrl *etherctrl = new Ieee802Ctrl();
115  etherctrl->setSsap(localSAP);
116  etherctrl->setDsap(destSap);
117  etherctrl->setDest(destAddr);
118  datapacket->setControlInfo(etherctrl);
119  emit(sentPkSignal, datapacket);
120  send(datapacket, "out");
121  packetsSent++;
122 }
static simsignal_t sentPkSignal
Definition: EtherAppSrv.h:44
int localSAP
Definition: EtherAppSrv.h:38
long packetsSent
Definition: EtherAppSrv.h:42
void inet::EtherAppSrv::startApp ( )
protectedvirtual

Referenced by handleOperationStage(), and initialize().

63 {
64  EV_INFO << "Starting application\n";
65  bool registerSAP = par("registerSAP");
66  if (registerSAP)
68 }
int localSAP
Definition: EtherAppSrv.h:38
void registerDSAP(int dsap)
Definition: EtherAppSrv.cc:124
void inet::EtherAppSrv::stopApp ( )
protectedvirtual

Referenced by handleOperationStage().

71 {
72  EV_INFO << "Stop the application\n";
73 }

Member Data Documentation

int inet::EtherAppSrv::localSAP = 0
protected
NodeStatus* inet::EtherAppSrv::nodeStatus = nullptr
protected

Referenced by initialize(), and isNodeUp().

long inet::EtherAppSrv::packetsReceived = 0
protected

Referenced by handleMessage(), and initialize().

long inet::EtherAppSrv::packetsSent = 0
protected

Referenced by initialize(), and sendPacket().

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

Referenced by handleMessage().

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

Referenced by sendPacket().


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