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

Generic server application. More...

#include <TCPGenericSrvApp.h>

Inheritance diagram for inet::TCPGenericSrvApp:
inet::ILifecycle

Protected Member Functions

virtual void sendBack (cMessage *msg)
 
virtual void sendOrSchedule (cMessage *msg, simtime_t delay)
 
virtual void initialize (int stage) override
 
virtual int numInitStages () const override
 
virtual void handleMessage (cMessage *msg) override
 
virtual void finish () override
 
virtual void refreshDisplay () const override
 
virtual bool handleOperationStage (LifecycleOperation *operation, int stage, IDoneCallback *doneCallback) override
 Perform one stage of a lifecycle operation. More...
 

Protected Attributes

simtime_t delay
 
simtime_t maxMsgDelay
 
long msgsRcvd
 
long msgsSent
 
long bytesRcvd
 
long bytesSent
 

Static Protected Attributes

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

Additional Inherited Members

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

Detailed Description

Generic server application.

It serves requests coming in GenericAppMsg request messages. Clients are usually subclassed from TCPAppBase.

See also
GenericAppMsg, TCPAppBase

Member Function Documentation

void inet::TCPGenericSrvApp::finish ( )
overrideprotectedvirtual
166 {
167  EV_INFO << getFullPath() << ": sent " << bytesSent << " bytes in " << msgsSent << " packets\n";
168  EV_INFO << getFullPath() << ": received " << bytesRcvd << " bytes in " << msgsRcvd << " packets\n";
169 }
long msgsSent
Definition: TCPGenericSrvApp.h:40
long msgsRcvd
Definition: TCPGenericSrvApp.h:39
long bytesSent
Definition: TCPGenericSrvApp.h:42
long bytesRcvd
Definition: TCPGenericSrvApp.h:41
void inet::TCPGenericSrvApp::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
94 {
95  if (msg->isSelfMessage()) {
96  sendBack(msg);
97  }
98  else if (msg->getKind() == TCP_I_PEER_CLOSED) {
99  // we'll close too, but only after there's surely no message
100  // pending to be sent back in this connection
101  msg->setName("close");
102  msg->setKind(TCP_C_CLOSE);
104  }
105  else if (msg->getKind() == TCP_I_DATA || msg->getKind() == TCP_I_URGENT_DATA) {
106  GenericAppMsg *appmsg = dynamic_cast<GenericAppMsg *>(msg);
107  if (!appmsg)
108  throw cRuntimeError("Message (%s)%s is not a GenericAppMsg -- "
109  "probably wrong client app, or wrong setting of TCP's "
110  "dataTransferMode parameters "
111  "(try \"object\")",
112  msg->getClassName(), msg->getName());
113 
114  msgsRcvd++;
115  bytesRcvd += appmsg->getByteLength();
116  emit(rcvdPkSignal, appmsg);
117 
118  long requestedBytes = appmsg->getExpectedReplyLength();
119 
120  simtime_t msgDelay = appmsg->getReplyDelay();
121  if (msgDelay > maxMsgDelay)
122  maxMsgDelay = msgDelay;
123 
124  bool doClose = appmsg->getServerClose();
125  int connId = check_and_cast<TCPCommand *>(appmsg->getControlInfo())->getConnId();
126 
127  if (requestedBytes == 0) {
128  delete msg;
129  }
130  else {
131  delete appmsg->removeControlInfo();
132  TCPSendCommand *cmd = new TCPSendCommand();
133  cmd->setConnId(connId);
134  appmsg->setControlInfo(cmd);
135 
136  // set length and send it back
137  appmsg->setKind(TCP_C_SEND);
138  appmsg->setByteLength(requestedBytes);
139  sendOrSchedule(appmsg, delay + msgDelay);
140  }
141 
142  if (doClose) {
143  cMessage *msg = new cMessage("close");
144  msg->setKind(TCP_C_CLOSE);
145  TCPCommand *cmd = new TCPCommand();
146  cmd->setConnId(connId);
147  msg->setControlInfo(cmd);
149  }
150  }
151  else {
152  // some indication -- ignore
153  EV_WARN << "drop msg: " << msg->getName() << ", kind:" << msg->getKind() << "(" << cEnum::get("inet::TcpStatusInd")->getStringFor(msg->getKind()) << ")\n";
154  delete msg;
155  }
156 }
az accept haszálja pcb új connId
Definition: lwip_tcp.txt:38
Definition: TCPCommand_m.h:101
Definition: TCPCommand_m.h:99
Definition: TCPCommand_m.h:63
long msgsRcvd
Definition: TCPGenericSrvApp.h:39
static simsignal_t rcvdPkSignal
Definition: TCPGenericSrvApp.h:45
virtual void sendBack(cMessage *msg)
Definition: TCPGenericSrvApp.cc:75
Definition: TCPCommand_m.h:64
long bytesRcvd
Definition: TCPGenericSrvApp.h:41
simtime_t delay
Definition: TCPGenericSrvApp.h:36
Definition: TCPCommand_m.h:98
simtime_t maxMsgDelay
Definition: TCPGenericSrvApp.h:37
virtual void sendOrSchedule(cMessage *msg, simtime_t delay)
Definition: TCPGenericSrvApp.cc:67
virtual bool inet::TCPGenericSrvApp::handleOperationStage ( LifecycleOperation operation,
int  stage,
IDoneCallback doneCallback 
)
inlineoverrideprotectedvirtual

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.

59  { Enter_Method_Silent(); throw cRuntimeError("Unsupported lifecycle operation '%s'", operation->getClassName()); return true; }
void inet::TCPGenericSrvApp::initialize ( int  stage)
overrideprotectedvirtual
35 {
36  cSimpleModule::initialize(stage);
37 
38  if (stage == INITSTAGE_LOCAL) {
39  delay = par("replyDelay");
40  maxMsgDelay = 0;
41 
42  //statistics
44 
45  WATCH(msgsRcvd);
46  WATCH(msgsSent);
47  WATCH(bytesRcvd);
48  WATCH(bytesSent);
49  }
50  else if (stage == INITSTAGE_APPLICATION_LAYER) {
51  const char *localAddress = par("localAddress");
52  int localPort = par("localPort");
53  TCPSocket socket;
54  socket.setOutputGate(gate("tcpOut"));
55  socket.setDataTransferMode(TCP_TRANSFER_OBJECT);
56  socket.bind(localAddress[0] ? L3AddressResolver().resolve(localAddress) : L3Address(), localPort);
57  socket.listen();
58 
59  bool isOperational;
60  NodeStatus *nodeStatus = dynamic_cast<NodeStatus *>(findContainingNode(this)->getSubmodule("status"));
61  isOperational = (!nodeStatus) || nodeStatus->getState() == NodeStatus::UP;
62  if (!isOperational)
63  throw cRuntimeError("This module doesn't support starting in node DOWN state");
64  }
65 }
long msgsSent
Definition: TCPGenericSrvApp.h:40
long msgsRcvd
Definition: TCPGenericSrvApp.h:39
long bytesSent
Definition: TCPGenericSrvApp.h:42
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
Definition: TCPCommand_m.h:256
long bytesRcvd
Definition: TCPGenericSrvApp.h:41
simtime_t delay
Definition: TCPGenericSrvApp.h:36
simtime_t maxMsgDelay
Definition: TCPGenericSrvApp.h:37
Initialization of applications.
Definition: InitStages.h:106
Definition: NodeStatus.h:40
virtual int inet::TCPGenericSrvApp::numInitStages ( ) const
inlineoverrideprotectedvirtual
53 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
void inet::TCPGenericSrvApp::refreshDisplay ( ) const
overrideprotectedvirtual
159 {
160  char buf[64];
161  sprintf(buf, "rcvd: %ld pks %ld bytes\nsent: %ld pks %ld bytes", msgsRcvd, bytesRcvd, msgsSent, bytesSent);
162  getDisplayString().setTagArg("t", 0, buf);
163 }
long msgsSent
Definition: TCPGenericSrvApp.h:40
long msgsRcvd
Definition: TCPGenericSrvApp.h:39
long bytesSent
Definition: TCPGenericSrvApp.h:42
long bytesRcvd
Definition: TCPGenericSrvApp.h:41
void inet::TCPGenericSrvApp::sendBack ( cMessage *  msg)
protectedvirtual

Referenced by handleMessage(), and sendOrSchedule().

76 {
77  cPacket *packet = dynamic_cast<cPacket *>(msg);
78 
79  if (packet) {
80  msgsSent++;
81  bytesSent += packet->getByteLength();
82  emit(sentPkSignal, packet);
83 
84  EV_INFO << "sending \"" << packet->getName() << "\" to TCP, " << packet->getByteLength() << " bytes\n";
85  }
86  else {
87  EV_INFO << "sending \"" << msg->getName() << "\" to TCP\n";
88  }
89 
90  send(msg, "tcpOut");
91 }
long msgsSent
Definition: TCPGenericSrvApp.h:40
long bytesSent
Definition: TCPGenericSrvApp.h:42
static simsignal_t sentPkSignal
Definition: TCPGenericSrvApp.h:46
void inet::TCPGenericSrvApp::sendOrSchedule ( cMessage *  msg,
simtime_t  delay 
)
protectedvirtual

Referenced by handleMessage().

68 {
69  if (delay == 0)
70  sendBack(msg);
71  else
72  scheduleAt(simTime() + delay, msg);
73 }
virtual void sendBack(cMessage *msg)
Definition: TCPGenericSrvApp.cc:75
simtime_t delay
Definition: TCPGenericSrvApp.h:36

Member Data Documentation

long inet::TCPGenericSrvApp::bytesRcvd
protected
long inet::TCPGenericSrvApp::bytesSent
protected
simtime_t inet::TCPGenericSrvApp::delay
protected

Referenced by handleMessage(), and initialize().

simtime_t inet::TCPGenericSrvApp::maxMsgDelay
protected

Referenced by handleMessage(), and initialize().

long inet::TCPGenericSrvApp::msgsRcvd
protected
long inet::TCPGenericSrvApp::msgsSent
protected
simsignal_t inet::TCPGenericSrvApp::rcvdPkSignal = registerSignal("rcvdPk")
staticprotected

Referenced by handleMessage().

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

Referenced by sendBack().


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