#include <TCPGenericCliAppBase.h>
Protected Member Functions | |
| virtual void | initialize () |
| virtual void | handleMessage (cMessage *msg) |
| virtual void | finish () |
| virtual void | handleTimer (cMessage *msg)=0 |
Utility functions | |
| virtual void | connect () |
| virtual void | close () |
| virtual void | sendPacket (int numBytes, int expectedReplyBytes, bool serverClose=false) |
| virtual void | setStatusString (const char *s) |
TCPSocket::CallbackInterface callback methods | |
| virtual void | socketEstablished (int connId, void *yourPtr) |
| virtual void | socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent) |
| virtual void | socketPeerClosed (int connId, void *yourPtr) |
| virtual void | socketClosed (int connId, void *yourPtr) |
| virtual void | socketFailure (int connId, void *yourPtr, int code) |
| virtual void | socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status) |
Protected Attributes | |
| TCPSocket | socket |
| int | numSessions |
| int | numBroken |
| int | packetsSent |
| int | packetsRcvd |
| int | bytesSent |
| int | bytesRcvd |
Base class for clients app for TCP-based request-reply protocols or apps. Handles a single session (and TCP connection) at a time.
It needs the following NED parameters: address, port, connectAddress, connectPort.
Generally used together with GenericAppMsg and TCPGenericSrvApp.
Definition at line 29 of file TCPGenericCliAppBase.h.
| void TCPGenericCliAppBase::close | ( | ) | [protected, virtual] |
Issues CLOSE command
Definition at line 67 of file TCPGenericCliAppBase.cc.
Referenced by TelnetApp::handleTimer(), TCPBasicClientApp::socketDataArrived(), and socketPeerClosed().
{
setStatusString("closing");
EV << "issuing CLOSE command\n";
socket.close();
}
| void TCPGenericCliAppBase::connect | ( | ) | [protected, virtual] |
Issues an active OPEN to the address/port given as module parameters
Definition at line 50 of file TCPGenericCliAppBase.cc.
Referenced by TelnetApp::handleTimer(), and TCPBasicClientApp::handleTimer().
{
// we need a new connId if this is not the first connection
socket.renewSocket();
// connect
const char *connectAddress = par("connectAddress");
int connectPort = par("connectPort");
EV << "issuing OPEN command\n";
setStatusString("connecting");
socket.connect(IPAddressResolver().resolve(connectAddress), connectPort);
numSessions++;
}
| void TCPGenericCliAppBase::finish | ( | ) | [protected, virtual] |
Records basic statistics: numSessions, packetsSent, packetsRcvd, bytesSent, bytesRcvd. Redefine to record different or more statistics at the end of the simulation.
Definition at line 136 of file TCPGenericCliAppBase.cc.
{
EV << getFullPath() << ": opened " << numSessions << " sessions\n";
EV << getFullPath() << ": sent " << bytesSent << " bytes in " << packetsSent << " packets\n";
EV << getFullPath() << ": received " << bytesRcvd << " bytes in " << packetsRcvd << " packets\n";
recordScalar("number of sessions", numSessions);
recordScalar("packets sent", packetsSent);
recordScalar("packets rcvd", packetsRcvd);
recordScalar("bytes sent", bytesSent);
recordScalar("bytes rcvd", bytesRcvd);
}
| void TCPGenericCliAppBase::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
For self-messages it invokes handleTimer(); messages arriving from TCP will get dispatched to the socketXXX() functions.
Definition at line 42 of file TCPGenericCliAppBase.cc.
{
if (msg->isSelfMessage())
handleTimer(msg);
else
socket.processMessage(msg);
}
| virtual void TCPGenericCliAppBase::handleTimer | ( | cMessage * | msg | ) | [protected, pure virtual] |
Invoked from handleMessage(). Should be redefined to handle self-messages.
Implemented in TCPBasicClientApp, and TelnetApp.
Referenced by handleMessage().
| void TCPGenericCliAppBase::initialize | ( | ) | [protected, virtual] |
Initialization. Should be redefined to perform or schedule a connect().
Reimplemented in TCPBasicClientApp, and TelnetApp.
Definition at line 21 of file TCPGenericCliAppBase.cc.
{
numSessions = numBroken = packetsSent = packetsRcvd = bytesSent = bytesRcvd = 0;
WATCH(numSessions);
WATCH(numBroken);
WATCH(packetsSent);
WATCH(packetsRcvd);
WATCH(bytesSent);
WATCH(bytesRcvd);
// parameters
const char *address = par("address");
int port = par("port");
socket.bind(*address ? IPvXAddress(address) : IPvXAddress(), port);
socket.setCallbackObject(this);
socket.setOutputGate(gate("tcpOut"));
setStatusString("waiting");
}
| void TCPGenericCliAppBase::sendPacket | ( | int | numBytes, | |
| int | expectedReplyBytes, | |||
| bool | serverClose = false | |||
| ) | [protected, virtual] |
Sends a GenericAppMsg of the given length
Definition at line 74 of file TCPGenericCliAppBase.cc.
Referenced by TelnetApp::handleTimer(), and TCPBasicClientApp::sendRequest().
{
EV << "sending " << numBytes << " bytes, expecting " << expectedReplyBytes << (serverClose ? ", and server should close afterwards\n" : "\n");
GenericAppMsg *msg = new GenericAppMsg("data");
msg->setByteLength(numBytes);
msg->setExpectedReplyLength(expectedReplyBytes);
msg->setServerClose(serverClose);
socket.send(msg);
packetsSent++;
bytesSent+=numBytes;
}
| void TCPGenericCliAppBase::setStatusString | ( | const char * | s | ) | [protected, virtual] |
When running under GUI, it displays the given string next to the icon
Definition at line 89 of file TCPGenericCliAppBase.cc.
Referenced by close(), connect(), initialize(), socketClosed(), socketEstablished(), and socketFailure().
{
if (ev.isGUI()) getDisplayString().setTagArg("t", 0, s);
}
| void TCPGenericCliAppBase::socketClosed | ( | int | connId, | |
| void * | yourPtr | |||
| ) | [protected, virtual] |
Does nothing but update statistics/status. Redefine if you want to do something else, such as opening a new connection.
Reimplemented from TCPSocket::CallbackInterface.
Reimplemented in TCPBasicClientApp, and TelnetApp.
Definition at line 120 of file TCPGenericCliAppBase.cc.
{
// *redefine* to start another session etc.
EV << "connection closed\n";
setStatusString("closed");
}
| void TCPGenericCliAppBase::socketDataArrived | ( | int | connId, | |
| void * | yourPtr, | |||
| cPacket * | msg, | |||
| bool | urgent | |||
| ) | [protected, virtual] |
Does nothing but update statistics/status. Redefine to perform or schedule next sending. Beware: this funcion deletes the incoming message, which might not be what you want.
Implements TCPSocket::CallbackInterface.
Reimplemented in TCPBasicClientApp, and TelnetApp.
Definition at line 101 of file TCPGenericCliAppBase.cc.
{
// *redefine* to perform or schedule next sending
packetsRcvd++;
bytesRcvd+=msg->getByteLength();
delete msg;
}
| void TCPGenericCliAppBase::socketEstablished | ( | int | connId, | |
| void * | yourPtr | |||
| ) | [protected, virtual] |
Does nothing but update statistics/status. Redefine to perform or schedule first sending.
Reimplemented from TCPSocket::CallbackInterface.
Reimplemented in TCPBasicClientApp, and TelnetApp.
Definition at line 94 of file TCPGenericCliAppBase.cc.
{
// *redefine* to perform or schedule first sending
EV << "connected\n";
setStatusString("connected");
}
| void TCPGenericCliAppBase::socketFailure | ( | int | connId, | |
| void * | yourPtr, | |||
| int | code | |||
| ) | [protected, virtual] |
Does nothing but update statistics/status. Redefine if you want to try reconnecting after a delay.
Reimplemented from TCPSocket::CallbackInterface.
Reimplemented in TCPBasicClientApp, and TelnetApp.
Definition at line 127 of file TCPGenericCliAppBase.cc.
{
// subclasses may override this function, and add code try to reconnect after a delay.
EV << "connection broken\n";
setStatusString("broken");
numBroken++;
}
| void TCPGenericCliAppBase::socketPeerClosed | ( | int | connId, | |
| void * | yourPtr | |||
| ) | [protected, virtual] |
Since remote TCP closed, invokes close(). Redefine if you want to do something else.
Reimplemented from TCPSocket::CallbackInterface.
Definition at line 110 of file TCPGenericCliAppBase.cc.
| virtual void TCPGenericCliAppBase::socketStatusArrived | ( | int | connId, | |
| void * | yourPtr, | |||
| TCPStatusInfo * | status | |||
| ) | [inline, protected, virtual] |
Redefine to handle incoming TCPStatusInfo.
Reimplemented from TCPSocket::CallbackInterface.
Definition at line 100 of file TCPGenericCliAppBase.h.
{delete status;}
int TCPGenericCliAppBase::bytesRcvd [protected] |
Definition at line 40 of file TCPGenericCliAppBase.h.
Referenced by finish(), initialize(), and socketDataArrived().
int TCPGenericCliAppBase::bytesSent [protected] |
Definition at line 39 of file TCPGenericCliAppBase.h.
Referenced by finish(), initialize(), and sendPacket().
int TCPGenericCliAppBase::numBroken [protected] |
Definition at line 36 of file TCPGenericCliAppBase.h.
Referenced by initialize(), and socketFailure().
int TCPGenericCliAppBase::numSessions [protected] |
Definition at line 35 of file TCPGenericCliAppBase.h.
Referenced by connect(), finish(), and initialize().
int TCPGenericCliAppBase::packetsRcvd [protected] |
Definition at line 38 of file TCPGenericCliAppBase.h.
Referenced by finish(), initialize(), and socketDataArrived().
int TCPGenericCliAppBase::packetsSent [protected] |
Definition at line 37 of file TCPGenericCliAppBase.h.
Referenced by finish(), initialize(), and sendPacket().
TCPSocket TCPGenericCliAppBase::socket [protected] |
Definition at line 32 of file TCPGenericCliAppBase.h.
Referenced by close(), connect(), handleMessage(), initialize(), sendPacket(), and socketPeerClosed().
1.7.1