OverSim
TCPExampleApp Class Reference

A simple TCP example application. More...

#include <TCPExampleApp.h>

Inheritance diagram for TCPExampleApp:
BaseApp BaseRpc BaseTcpSupport RpcListener

Public Member Functions

 TCPExampleApp ()
 ~TCPExampleApp ()
- Public Member Functions inherited from BaseApp
 BaseApp ()
virtual ~BaseApp ()
 virtual destructor
- Public Member Functions inherited from BaseRpc
 BaseRpc ()
const NodeHandlegetThisNode ()
 Returns the NodeHandle of this node.
simtime_t getUdpTimeout ()
- Public Member Functions inherited from RpcListener
virtual ~RpcListener ()
 destructor
- Public Member Functions inherited from BaseTcpSupport
virtual void socketDataArrived (int connId, void *yourPtr, cPacket *msg, bool urgent)
virtual void socketEstablished (int connId, void *yourPtr)
virtual void socketPeerClosed (int connId, void *yourPtr)
virtual void socketFailure (int connId, void *yourPtr, int code)
virtual void socketStatusArrived (int connId, void *yourPtr, TCPStatusInfo *status)

Private Member Functions

void initializeApp (int stage)
void finishApp ()
void handleTimerEvent (cMessage *msg)
void handleDataReceived (TransportAddress address, cPacket *msg, bool urgent)
void handleConnectionEvent (EvCode code, TransportAddress address)

Private Attributes

simtime_t sendPeriod
int numSent
int numReceived
cMessage * timerMsg

Additional Inherited Members

- Public Types inherited from BaseTcpSupport
enum  EvCode {
  NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED,
  CONNECTION_RESET, CONNECTION_SUCC_ClOSED
}
- Protected Member Functions inherited from BaseApp
int numInitStages () const
 method to set InitStage
void initialize (int stage)
 initializes base class-attributes
virtual void initializeApp (int stage)
 initializes derived class-attributes
void handleMessage (cMessage *msg)
 checks for message type and calls corresponding method
virtual void receiveChangeNotification (int category, const cPolymorphic *details)
 callback-method for events at the NotificationBoard
virtual void handleTransportAddressChangedNotification ()
 This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.
virtual void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.
virtual void handleNodeGracefulLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.
void finish ()
 collects statistical data
virtual void finishApp ()
 collects statistical data of derived app
void callRoute (const OverlayKey &key, cPacket *msg, const TransportAddress &hint=TransportAddress::UNSPECIFIED_NODE, RoutingType routingType=DEFAULT_ROUTING)
 Common API function: calls route-method in overlay.
void callRoute (const OverlayKey &key, cPacket *msg, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType=DEFAULT_ROUTING)
virtual void deliver (OverlayKey &key, cMessage *msg)
 Common API function: handles delivered messages from overlay.
virtual void forward (OverlayKey *key, cPacket **msg, NodeHandle *nextHopNode)
 Common API function: handles messages from overlay to be forwarded.
virtual void update (const NodeHandle &node, bool joined)
 Common API function: informs application about neighbors and own nodeID.
NodeVectorcallLocalLookup (const OverlayKey &key, int num, bool safe)
 Common API function: produces a list of nodes that can be used as next hops towards key.
NodeVectorcallNeighborSet (int num)
 Common API function: produces a list of neighbor nodes.
bool isSiblingFor (const NodeHandle &node, const OverlayKey &key, int numSiblings, bool *err)
 Query if a node is among the siblings for a given key.
virtual void handleLowerMessage (cMessage *msg)
 processes self-messages
virtual void handleUpperMessage (cMessage *msg)
 handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)
virtual void handleUDPMessage (cMessage *msg)
 method to handle messages that come directly from the UDP gate
virtual void handleReadyMessage (CompReadyMessage *msg)
 method to handle ready messages from the overlay
virtual void bindToPort (int port)
 Tells UDP we want to get all packets arriving on the given port.
virtual void sendMessageToUDP (const TransportAddress &destAddr, cPacket *msg, simtime_t delay=SIMTIME_ZERO)
 Sends a packet over UDP.
virtual void handleTraceMessage (cMessage *msg)
 handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.
void sendMessageToLowerTier (cPacket *msg)
 sends non-commonAPI message to the lower tier
bool internalHandleRpcCall (BaseCallMessage *msg)
 Handles internal rpc requests.
void internalHandleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 Handles rpc responses internal in base classes

void internalSendRouteRpc (BaseRpcMessage *message, const OverlayKey &destKey, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType)
virtual CompType getThisCompType ()
 Return the component type of this module.
void sendReadyMessage (bool ready=true, const OverlayKey &nodeId=OverlayKey::UNSPECIFIED_KEY)
- Protected Attributes inherited from BaseApp
UnderlayConfiguratorunderlayConfigurator
 pointer to UnderlayConfigurator in this node
GlobalNodeListglobalNodeList
 pointer to GlobalNodeList in this node
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
NotificationBoard * notificationBoard
 pointer to NotificationBoard in this node
bool debugOutput
 debug output yes/no?
int numOverlaySent
 number of sent packets to overlay
int bytesOverlaySent
 number of sent bytes to overlay
int numOverlayReceived
 number of received packets from overlay
int bytesOverlayReceived
 number of received bytes from overlay
int numUdpSent
 number of sent packets to UDP
int bytesUdpSent
 number of sent bytes to UDP
int numUdpReceived
 number of received packets from UDP
int bytesUdpReceived
 number of received bytes from UDP
simtime_t creationTime
 simTime when the App has been created

Detailed Description

A simple TCP example application.

This is a simple TCP example application. It periodically establishes TCP connections to random nodes, sends PING and receives PONG messages.

Author
Antonio Zea
Bernhard Mueller
Ingmar Baumgart

Definition at line 43 of file TCPExampleApp.h.

Constructor & Destructor Documentation

TCPExampleApp::TCPExampleApp ( )

Definition at line 39 of file TCPExampleApp.cc.

{
timerMsg = NULL;
}
TCPExampleApp::~TCPExampleApp ( )

Definition at line 44 of file TCPExampleApp.cc.

{
cancelAndDelete(timerMsg);
}

Member Function Documentation

void TCPExampleApp::finishApp ( )
private

Definition at line 83 of file TCPExampleApp.cc.

{
globalStatistics->addStdDev("TCPExampleApp: Sent packets", numSent);
globalStatistics->addStdDev("TCPExampleApp: Received packets", numReceived);
}
void TCPExampleApp::handleConnectionEvent ( EvCode  code,
TransportAddress  address 
)
private

Definition at line 167 of file TCPExampleApp.cc.

{
if (code == PEER_CLOSED) {
scheduleAt(simTime() + sendPeriod, timerMsg);
} else {
}
}
void TCPExampleApp::handleDataReceived ( TransportAddress  address,
cPacket *  msg,
bool  urgent 
)
private

Definition at line 133 of file TCPExampleApp.cc.

{
// *redefine* to perform or schedule next sending
TCPExampleMessage *TCPMsg = dynamic_cast<TCPExampleMessage*>(msg);
if (TCPMsg && TCPMsg->getType() == TCPEXMSG_PING){
// create PONG message
respMsg->setType(TCPEXMSG_PONG); // set the message type to PONG
respMsg->setSenderAddress(thisNode); // set the sender address to our own
respMsg->setByteLength(100);
sendTcpData(respMsg, address);
// user output
EV << thisNode.getIp() << ": Got PING from "
<< TCPMsg->getSenderAddress().getIp() << ", sending PONG!"
<< std::endl;
} else if (TCPMsg && TCPMsg->getType() == TCPEXMSG_PONG){
// user output
EV << thisNode.getIp() << ": Got PONG reply! Closing connection." << std::endl;
// dialog successfully transmitted, close connection
}
delete msg;
}
void TCPExampleApp::handleTimerEvent ( cMessage *  msg)
private

Definition at line 90 of file TCPExampleApp.cc.

{
if (msg == timerMsg) {
// if the simulator is still busy creating the network,
// let's wait a bit longer
scheduleAt(simTime() + sendPeriod, timerMsg);
return;
}
// do the same, if the node is the only one alive
scheduleAt(simTime() + sendPeriod, timerMsg);
return;
}
// get the address of one of the other nodes
while ((addr != NULL) && (thisNode.getIp().equals(addr->getIp()))) {
}
assert(addr != NULL);
// create a PING message
TCPMsg->setType(TCPEXMSG_PING); // set the message type to PING
TCPMsg->setSenderAddress(thisNode); // set the sender address to our own
TCPMsg->setByteLength(100); // set the message length to 100 bytes
RECORD_STATS(numSent++); // update statistics
// connect and send message
TransportAddress remoteAddress = TransportAddress(addr->getIp(), 24000);
establishTcpConnection(remoteAddress);
sendTcpData(TCPMsg, remoteAddress);
// user output
EV << thisNode.getIp() << ": Connecting to "<< addr->getIp()
<< " and sending PING."<< std::endl;
}
}
void TCPExampleApp::initializeApp ( int  stage)
private

Definition at line 49 of file TCPExampleApp.cc.

{
if (stage != MIN_STAGE_APP) {
return;
}
// copy the module parameter values to our own variables
sendPeriod = par("sendPeriod");
// initialize our statistics variables
numSent = 0;
// tell the GUI to display our variables
WATCH(numSent);
WATCH(numReceived);
// start our timer
timerMsg = new cMessage("Periodic timer");
// set up and listen on tcp
BootstrapList* bootstrapList = check_and_cast<BootstrapList*>(
// first node which was created starts with PING-PONG messaging
if (globalNodeList->getNumNodes() == 1) {
scheduleAt(simTime() + SimTime::parse("20s"), timerMsg);
}
}

Member Data Documentation

int TCPExampleApp::numReceived
private

Definition at line 62 of file TCPExampleApp.h.

int TCPExampleApp::numSent
private

Definition at line 61 of file TCPExampleApp.h.

simtime_t TCPExampleApp::sendPeriod
private

Definition at line 58 of file TCPExampleApp.h.

cMessage* TCPExampleApp::timerMsg
private

Definition at line 65 of file TCPExampleApp.h.


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