TCPGenericCliAppBase Class Reference

#include <TCPGenericCliAppBase.h>

Inheritance diagram for TCPGenericCliAppBase:

TCPSocket::CallbackInterface TCPBasicClientApp TelnetApp List of all members.

Detailed Description

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.


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, cMessage *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


Member Function Documentation

void TCPGenericCliAppBase::close (  )  [protected, virtual]

Issues CLOSE command

00068 {
00069     setStatusString("closing");
00070     EV << "issuing CLOSE command\n";
00071     socket.close();
00072 }

void TCPGenericCliAppBase::connect (  )  [protected, virtual]

Issues an active OPEN to the address/port given as module parameters

00051 {
00052     // we need a new connId if this is not the first connection
00053     socket.renewSocket();
00054 
00055     // connect
00056     const char *connectAddress = par("connectAddress");
00057     int connectPort = par("connectPort");
00058 
00059     EV << "issuing OPEN command\n";
00060     setStatusString("connecting");
00061 
00062     socket.connect(IPAddressResolver().resolve(connectAddress), connectPort);
00063 
00064     numSessions++;
00065 }

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.

00137 {
00138     EV << fullPath() << ": opened " << numSessions << " sessions\n";
00139     EV << fullPath() << ": sent " << bytesSent << " bytes in " << packetsSent << " packets\n";
00140     EV << fullPath() << ": received " << bytesRcvd << " bytes in " << packetsRcvd << " packets\n";
00141 
00142     recordScalar("number of sessions", numSessions);
00143     recordScalar("packets sent", packetsSent);
00144     recordScalar("packets rcvd", packetsRcvd);
00145     recordScalar("bytes sent", bytesSent);
00146     recordScalar("bytes rcvd", bytesRcvd);
00147 }

void TCPGenericCliAppBase::handleMessage ( cMessage *  msg  )  [protected, virtual]

For self-messages it invokes handleTimer(); messages arriving from TCP will get dispatched to the socketXXX() functions.

00043 {
00044     if (msg->isSelfMessage())
00045         handleTimer(msg);
00046     else
00047         socket.processMessage(msg);
00048 }

virtual void TCPGenericCliAppBase::handleTimer ( cMessage *  msg  )  [protected, pure virtual]

Invoked from handleMessage(). Should be redefined to handle self-messages.

Implemented in TCPBasicClientApp, and TelnetApp.

void TCPGenericCliAppBase::initialize (  )  [protected, virtual]

Initialization. Should be redefined to perform or schedule a connect().

Reimplemented in TCPBasicClientApp, and TelnetApp.

00022 {
00023     numSessions = numBroken = packetsSent = packetsRcvd = bytesSent = bytesRcvd = 0;
00024     WATCH(numSessions);
00025     WATCH(numBroken);
00026     WATCH(packetsSent);
00027     WATCH(packetsRcvd);
00028     WATCH(bytesSent);
00029     WATCH(bytesRcvd);
00030 
00031     // parameters
00032     const char *address = par("address");
00033     int port = par("port");
00034     socket.bind(*address ? IPvXAddress(address) : IPvXAddress(), port);
00035 
00036     socket.setCallbackObject(this);
00037     socket.setOutputGate(gate("tcpOut"));
00038 
00039     setStatusString("waiting");
00040 }

void TCPGenericCliAppBase::sendPacket ( int  numBytes,
int  expectedReplyBytes,
bool  serverClose = false 
) [protected, virtual]

Sends a GenericAppMsg of the given length

00075 {
00076     EV << "sending " << numBytes << " bytes, expecting " << expectedReplyBytes << (serverClose ? ", and server should close afterwards\n" : "\n");
00077 
00078     GenericAppMsg *msg = new GenericAppMsg("data");
00079     msg->setByteLength(numBytes);
00080     msg->setExpectedReplyLength(expectedReplyBytes);
00081     msg->setClose(serverClose);
00082 
00083     socket.send(msg);
00084 
00085     packetsSent++;
00086     bytesSent+=numBytes;
00087 }

void TCPGenericCliAppBase::setStatusString ( const char *  s  )  [protected, virtual]

When running under GUI, it displays the given string next to the icon

00090 {
00091     if (ev.isGUI()) displayString().setTagArg("t", 0, s);
00092 }

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.

00121 {
00122     // *redefine* to start another session etc.
00123     EV << "connection closed\n";
00124     setStatusString("closed");
00125 }

void TCPGenericCliAppBase::socketDataArrived ( int  connId,
void *  yourPtr,
cMessage *  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.

00102 {
00103     // *redefine* to perform or schedule next sending
00104     packetsRcvd++;
00105     bytesRcvd+=msg->byteLength();
00106 
00107     delete msg;
00108 }

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.

00095 {
00096     // *redefine* to perform or schedule first sending
00097     EV << "connected\n";
00098     setStatusString("connected");
00099 }

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.

00128 {
00129     // subclasses may override this function, and add code try to reconnect after a delay.
00130     EV << "connection broken\n";
00131     setStatusString("broken");
00132 
00133     numBroken++;
00134 }

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.

00111 {
00112     // close the connection (if not already closed)
00113     if (socket.state()==TCPSocket::PEER_CLOSED)
00114     {
00115         EV << "remote TCP closed, closing here as well\n";
00116         close();
00117     }
00118 }

virtual void TCPGenericCliAppBase::socketStatusArrived ( int  connId,
void *  yourPtr,
TCPStatusInfo status 
) [inline, protected, virtual]

Redefine to handle incoming TCPStatusInfo.

Reimplemented from TCPSocket::CallbackInterface.

00100 {delete status;}


Member Data Documentation

int TCPGenericCliAppBase::bytesRcvd [protected]

int TCPGenericCliAppBase::bytesSent [protected]

int TCPGenericCliAppBase::numBroken [protected]

int TCPGenericCliAppBase::numSessions [protected]

int TCPGenericCliAppBase::packetsRcvd [protected]

int TCPGenericCliAppBase::packetsSent [protected]

TCPSocket TCPGenericCliAppBase::socket [protected]


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:20:24 2007 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.7