INET Framework for OMNeT++/OMNEST
TCPGenericCliAppBase Class Reference

#include <TCPGenericCliAppBase.h>

Inheritance diagram for TCPGenericCliAppBase:
TCPSocket::CallbackInterface TCPBasicClientApp TelnetApp

List of all members.

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

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.


Member Function Documentation

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

Issues CLOSE command

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

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.

{
    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.

{
    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.

{
    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

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

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.

{
    // *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.

{
    // *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.

{
    // *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.

{
    // 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.

{
    // close the connection (if not already closed)
    if (socket.getState()==TCPSocket::PEER_CLOSED)
    {
        EV << "remote TCP closed, closing here as well\n";
        close();
    }
}
virtual void TCPGenericCliAppBase::socketStatusArrived ( int  connId,
void *  yourPtr,
TCPStatusInfo *  status 
) [inline, protected, virtual]

Redefine to handle incoming TCPStatusInfo.

Reimplemented from TCPSocket::CallbackInterface.

{delete status;}

Member Data Documentation

Referenced by finish(), initialize(), and sendPacket().

Referenced by initialize(), and socketFailure().

Referenced by connect(), finish(), and initialize().


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