OverSim
BaseApp Class Reference

Base class for applications. More...

#include <BaseApp.h>

Inheritance diagram for BaseApp:
BaseRpc BaseTcpSupport RpcListener ALMTest BootstrapList CBRDHT DHT DHTTestApp GIASearchApp I3 KBRTestApp Landmark MyApplication NeighborCache P2pns RealWorldTestApp Scribe SimMud SimpleGameClient TCPExampleApp TierDummy XmlRpcInterface

Public Member Functions

 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)

Protected Member Functions

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 Member Functions inherited from BaseRpc
virtual void internalHandleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 Handles rpc timeouts internal in base classes

void initRpcs ()
 Initializes Remote-Procedure state.
void finishRpcs ()
 Deinitializes Remote-Procedure state.
virtual void internalHandleRpcMessage (BaseRpcMessage *msg)
 Handles incoming rpc messages and delegates them to the corresponding listeners or handlers.
uint32_t sendRouteRpcCall (CompType destComp, const TransportAddress &dest, const OverlayKey &destKey, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Routes a Remote-Procedure-Call message to an OverlayKey.
uint32_t sendRouteRpcCall (CompType destComp, const OverlayKey &destKey, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Routes a Remote-Procedure-Call message to an OverlayKey.
uint32_t sendRouteRpcCall (CompType destComp, const TransportAddress &dest, BaseCallMessage *msg, cPolymorphic *context=NULL, RoutingType routingType=DEFAULT_ROUTING, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends a Remote-Procedure-Call message using the overlay's UDP port
This replaces ROUTE_DIRECT calls!
uint32_t sendUdpRpcCall (const TransportAddress &dest, BaseCallMessage *msg, cPolymorphic *context=NULL, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends a Remote-Procedure-Call message to the underlay

uint32_t sendInternalRpcCall (CompType destComp, BaseCallMessage *msg, cPolymorphic *context=NULL, simtime_t timeout=-1, int retries=0, int rpcId=-1, RpcListener *rpcListener=NULL)
 Sends an internal Remote-Procedure-Call between two tiers

void cancelRpcMessage (uint32_t nonce)
 Cancels a Remote-Procedure-Call.
void cancelAllRpcs ()
 Cancels all RPCs.
void sendRpcResponse (TransportType transportType, CompType destComp, const TransportAddress &dest, const OverlayKey &destKey, BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message and deletes call message.
void sendRpcResponse (BaseCallMessage *call, BaseResponseMessage *response)
 Send Remote-Procedure response message to UDP and deletes call message.
int pingNode (const TransportAddress &dest, simtime_t timeout=-1, int retries=0, cPolymorphic *context=NULL, const char *caption="PING", RpcListener *rpcListener=NULL, int rpcId=-1, TransportType transportType=INVALID_TRANSPORT)
 ping a node by its TransportAddress
virtual bool handleRpcCall (BaseCallMessage *msg)
 Processes Remote-Procedure-Call invocation messages.
virtual void pingResponse (PingResponse *pingResponse, cPolymorphic *context, int rpcId, simtime_t rtt)
virtual void pingTimeout (PingCall *pingCall, const TransportAddress &dest, cPolymorphic *context, int rpcId)
bool internalHandleMessage (cMessage *msg)
- Protected Member Functions inherited from RpcListener
virtual void handleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcResponse (BaseResponseMessage *msg, const RpcState &rpcState, simtime_t rtt)
 This method is called if an RPC response has been received.
virtual void handleRpcTimeout (BaseCallMessage *msg, const TransportAddress &dest, cPolymorphic *context, int rpcId, const OverlayKey &destKey)
 This method is called if an RPC timeout has been reached.
virtual void handleRpcTimeout (const RpcState &rpcState)
 This method is called if an RPC timeout has been reached.
- Protected Member Functions inherited from BaseTcpSupport
void handleTCPMessage (cMessage *msg)
 Member function to handle incoming TCP messages.
void bindAndListenTcp (int port)
 Member function to bind service to the specified port and listen afterwards.
bool isAlreadyConnected (TransportAddress address)
 Member function to check if the service is already connected.
void establishTcpConnection (TransportAddress address)
 Member function to establish a connection to the specified node.
void sendTcpData (cPacket *msg, TransportAddress address)
 Member function to send TCP data to the specified node.
virtual void handleConnectionEvent (EvCode code, TransportAddress address)
 Member function to handle passive connection events.
virtual void handleDataReceived (TransportAddress address, cPacket *msg, bool urgent)
 Member function to handle incoming data.
virtual void handleIncomingConnection (TransportAddress address)
 Member function to handle newly opened connections.
void closeTcpConnection (TransportAddress address)
 Member function to close an established connection.
void setTcpOut (cGate *gate)
 Member function to set local gate towards the TCP module during init phase.
cGate * getTcpOut ()
 Member function to get local gate towards the TCP module.

Protected Attributes

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
- Protected Attributes inherited from BaseRpc
NodeHandle thisNode
 NodeHandle to this node.
BaseOverlayoverlay
bool debugOutput
 debug output ?
GlobalStatisticsglobalStatistics
 pointer to GlobalStatistics module in this node
CompType thisCompType
NeighborCacheneighborCache
 pointer to the neighbor cache
CryptoModulecryptoModule
 pointer to CryptoModule
int numPingSent
int bytesPingSent
int numPingResponseSent
int bytesPingResponseSent

Private Member Functions

void forwardResponse (const OverlayKey &key, cPacket *msg, const NodeHandle &nextHopNode)
 sends msg encapsulated in a KBRforward message to the overlay with destination key
void handleCommonAPIMessage (CommonAPIMessage *commonAPIMsg)
 handles CommonAPIMessages
void internalSendRpcResponse (BaseCallMessage *call, BaseResponseMessage *response)

Additional Inherited Members

- Public Types inherited from BaseTcpSupport
enum  EvCode {
  NO_EST_CONNECTION, PEER_CLOSED, PEER_TIMEDOUT, PEER_REFUSED,
  CONNECTION_RESET, CONNECTION_SUCC_ClOSED
}

Detailed Description

Base class for applications.

Base class for applications (Tier 1-3) that use overlay functionality. provides common API for structured overlays (KBR), RPC and UDP

BaseApp provides the following API calls for derived classes:

Method nameCall directionavailable on Tierimplemented as
Modified CommonAPI for structured P2P overlays:
callRoute()CALL1OMNeT++ messages
deliver()CALLBACK1OMNeT++ messages
forward()CALLBACK1OMNeT++ messages
update()CALLBACK1OMNeT++ messages
callLocalLookup()CALL1-3direct C++-method calls
callNeighborSet()CALL1-3direct C++-method calls
isSiblingFor()CALL1-3direct C++-method calls
Remote Procedure Call API (RPC):
sendUdpRpcCall()CALL1-3*OMNeT++ messages
sendRouteRpcCall()CALL1-3*OMNeT++ messages
sendInternalRpcCall()CALL1-3*OMNeT++ messages
UDP API:
handleUDPMessage()CALLBACK1-3OMNeT++ messages
sendMessageToUDP()CALL1-3OMNeT++ messages
bindToPort()CALL1-3OMNeT++ messages

Callback functions have to be implemented in derived classes!

See Also
KBRTestApp
Author
Bernhard Heep

Definition at line 76 of file BaseApp.h.

Constructor & Destructor Documentation

BaseApp::BaseApp ( )

Definition at line 41 of file BaseApp.cc.

{
overlay = NULL;
}
BaseApp::~BaseApp ( )
virtual

virtual destructor

Definition at line 48 of file BaseApp.cc.

{
}

Member Function Documentation

void BaseApp::bindToPort ( int  port)
protectedvirtual

Tells UDP we want to get all packets arriving on the given port.

Definition at line 511 of file BaseApp.cc.

Referenced by MyApplication::initializeApp(), and KBRTestApp::initializeApp().

{
EV << "[BaseApp::bindToPort() @ " << thisNode.getIp()
<< ": Binding to UDP port " << port << endl;
cMessage *msg = new cMessage("UDP_C_BIND", UDP_C_BIND);
UDPControlInfo *ctrl = new UDPControlInfo();
ctrl->setSrcPort(port);
ctrl->setSockId(UDPSocket::generateSocketId());
msg->setControlInfo(ctrl);
send(msg, "udpOut");
}
NodeVector* BaseApp::callLocalLookup ( const OverlayKey key,
int  num,
bool  safe 
)
inlineprotected

Common API function: produces a list of nodes that can be used as next hops towards key.

Parameters
keythe destination key
nummaximal number of nodes in answer
safefraction of faulty nodes is not higher than in the overlay?

Definition at line 233 of file BaseApp.h.

{
return overlay->local_lookup(key, num, safe);
};
NodeVector* BaseApp::callNeighborSet ( int  num)
inlineprotected

Common API function: produces a list of neighbor nodes.

Parameters
nummaximal number of nodes in answer

Definition at line 244 of file BaseApp.h.

{
return overlay->neighborSet(num);
};
void BaseApp::callRoute ( const OverlayKey key,
cPacket *  msg,
const TransportAddress hint = TransportAddress::UNSPECIFIED_NODE,
RoutingType  routingType = DEFAULT_ROUTING 
)
inlineprotected

Common API function: calls route-method in overlay.

encapsulates msg into KBRroute message and sends it to the overlay module

Parameters
keydestination key
msgmessage to route
hintnext hop (usually unused)
routingTypespecifies the routing mode (ITERATIVE_ROUTING, ...)

Definition at line 181 of file BaseApp.h.

Referenced by RealWorldTestApp::deliver(), MyApplication::handleTimerEvent(), KBRTestApp::handleTimerEvent(), and RealWorldTestApp::handleUpperMessage().

{
std::vector<TransportAddress> sourceRoute;
sourceRoute.push_back(hint);
callRoute(key, msg, sourceRoute, routingType);
}
void BaseApp::callRoute ( const OverlayKey key,
cPacket *  msg,
const std::vector< TransportAddress > &  sourceRoute,
RoutingType  routingType = DEFAULT_ROUTING 
)
protected

Definition at line 241 of file BaseApp.cc.

{
// create route-message (common API)
KBRroute* routeMsg = new KBRroute();
routeMsg->setDestKey(key);
if (!(sourceRoute.size() == 1 && sourceRoute[0].isUnspecified())) {
routeMsg->setSourceRouteArraySize(sourceRoute.size());
for (uint32_t i = 0; i < sourceRoute.size(); ++i) {
routeMsg->setSourceRoute(i, sourceRoute[i]);
}
}
routeMsg->encapsulate(msg);
routeMsg->setRoutingType(routingType);
routeMsg->setType(KBR_ROUTE);
sendDirect(routeMsg, overlay->getCompRpcGate(OVERLAY_COMP));
// debug message
if (debugOutput && !ev.isDisabled()) {
EV << "[BaseApp::callRoute() @ " << thisNode.getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " Sending " << *msg
<< " to destination key " << key
<< " with source route ";
for (uint32_t i = 0; i < sourceRoute.size(); ++i) {
EV << sourceRoute[i] << " ";
}
EV << endl;
}
// count
RECORD_STATS(numOverlaySent++; bytesOverlaySent += msg->getByteLength());
}
void BaseApp::deliver ( OverlayKey key,
cMessage *  msg 
)
protectedvirtual

Common API function: handles delivered messages from overlay.

method to handle decapsulated KBRdeliver messages from overlay module, should be overwritten in derived application

Parameters
keydestination key
msgdelivered message

Reimplemented in Scribe, I3, and RealWorldTestApp.

Definition at line 283 of file BaseApp.cc.

{
// deliver...
delete msg;
}
void BaseApp::finish ( )
protected

collects statistical data

Reimplemented in I3.

Definition at line 468 of file BaseApp.cc.

{
// record scalar data
string baseAppName = string("BaseApp (") += string(this->getName())
+= string("): ");
globalStatistics->addStdDev(baseAppName + string("Sent Messages/s to "
"Overlay"),
numOverlaySent / time);
globalStatistics->addStdDev(baseAppName +
string("Received Messages/s from Overlay"),
globalStatistics->addStdDev(baseAppName + string("Sent Bytes/s to "
"Overlay"),
globalStatistics->addStdDev(baseAppName + string("Received Bytes/s "
"from Overlay"),
globalStatistics->addStdDev(baseAppName + string("Sent Messages/s to "
"UDP"),
numUdpSent / time);
globalStatistics->addStdDev(baseAppName +
string("Received Messages/s from UDP"),
numUdpReceived / time);
globalStatistics->addStdDev(baseAppName + string("Sent Bytes/s to UDP"),
bytesUdpSent / time);
globalStatistics->addStdDev(baseAppName + string("Received Bytes/s "
"from UDP"),
}
}
void BaseApp::finishApp ( )
protectedvirtual

collects statistical data of derived app

Reimplemented in NeighborCache, Scribe, SimMud, CBRDHT, GIASearchApp, SimpleGameClient, RealWorldTestApp, and ALMTest.

Definition at line 506 of file BaseApp.cc.

{
// ...
}
void BaseApp::forward ( OverlayKey key,
cPacket **  msg,
NodeHandle nextHopNode 
)
protectedvirtual

Common API function: handles messages from overlay to be forwarded.

method to handle decapsulated KBRdeliver messages from overlay module, should be overwritten in derived application if needed

Parameters
keydestination key
msgmessage to forward
nextHopNodenext hop

Reimplemented in Scribe, and I3.

Definition at line 290 of file BaseApp.cc.

Referenced by I3::forward().

{
// usually do nothing
}
void BaseApp::forwardResponse ( const OverlayKey key,
cPacket *  msg,
const NodeHandle nextHopNode 
)
private

sends msg encapsulated in a KBRforward message to the overlay with destination key

Parameters
keythe destination OverlayKey
msgthe message to forward
nextHopNodethe considered next hop node on the route to the destination

Definition at line 295 of file BaseApp.cc.

{
OverlayCtrlInfo* ctrlInfo =
check_and_cast<OverlayCtrlInfo*>(msg->removeControlInfo());
//create forwardResponse message (common API)
KBRforward* forwardMsg = new KBRforward();
forwardMsg->setDestKey(key);
forwardMsg->setNextHopNode(nextHopNode);
forwardMsg->setControlInfo(ctrlInfo);
forwardMsg->encapsulate(msg);
forwardMsg->setType(KBR_FORWARD_RESPONSE);
send(forwardMsg, "to_lowerTier");
} else {
sendDirect(forwardMsg, overlay->getCompRpcGate(OVERLAY_COMP));
}
}
CompType BaseApp::getThisCompType ( )
protectedvirtual

Return the component type of this module.

This method is overloaded by BaseOverlay/BaseApp and returns the appropriate component type of this module.

Returns
the component type of this module

Implements BaseRpc.

Reimplemented in NeighborCache, and BootstrapList.

Definition at line 186 of file BaseApp.cc.

Referenced by ALMTest::handleReadyMessage(), and SimpleGameClient::handleReadyMessage().

{
std::string name(this->getName());
if (name == std::string("tier1")) {
return TIER1_COMP;
} else if (name == std::string("tier2")) {
return TIER2_COMP;
} else if (name == std::string("tier3")) {
return TIER3_COMP;
}
std::string parentName(this->getParentModule()->getName());
if (parentName == std::string("tier1")) {
return TIER1_COMP;
} else if (parentName == std::string("tier2")) {
return TIER2_COMP;
} else if (parentName == std::string("tier3")) {
return TIER3_COMP;
} else {
throw cRuntimeError("BaseApp::getThisCompType(): "
"Unknown module type!");
}
return INVALID_COMP;
}
void BaseApp::handleCommonAPIMessage ( CommonAPIMessage commonAPIMsg)
private

handles CommonAPIMessages

This method gets called from BaseApp::handleMessage if message arrived from_lowerTier. It determines type of msg (KBR_DELIVER, KBR_FORWARD, KBR_UPDATE) and calls corresponding methods. All other messages are deleted.

Parameters
commonAPIMsgCommonAPIMessage

Definition at line 332 of file BaseApp.cc.

{
cPacket* tempMsg = commonAPIMsg->decapsulate();
// process interface control information
OverlayCtrlInfo* overlayCtrlInfo =
dynamic_cast<OverlayCtrlInfo*>(commonAPIMsg->removeControlInfo());
if (overlayCtrlInfo != NULL) {
tempMsg->setControlInfo(overlayCtrlInfo);
}
switch (commonAPIMsg->getType()) {
{
KBRdeliver* apiMsg = dynamic_cast<KBRdeliver*>(commonAPIMsg);
OverlayKey key = apiMsg->getDestKey(); // TODO key in overlayCtrlInfo
NodeHandle nextHopNode = overlay->getThisNode();
//first call forward, then deliver
forward(&key, &tempMsg, &nextHopNode);
if(tempMsg != NULL) {
//if key or nextHopNode is changed send msg back to overlay
if ((!key.isUnspecified() && key != apiMsg->getDestKey()) ||
(!nextHopNode.isUnspecified()
&& nextHopNode != overlay->getThisNode())) {
forwardResponse(key, tempMsg, nextHopNode);
}
else {
bytesOverlayReceived += tempMsg->getByteLength());
assert(overlayCtrlInfo->getTransportType()
// debug message
if (debugOutput) {
EV << "[BaseApp:handleCommonAPIMessage() @ "
<< thisNode.getIp() << " ("
<< overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " Received " << *tempMsg << " from "
<< overlayCtrlInfo->getSrcRoute() << endl;
}
//handle RPC first
BaseRpcMessage* rpcMessage
= dynamic_cast<BaseRpcMessage*>(tempMsg);
if (rpcMessage!=NULL) {
} else {
deliver(apiMsg->getDestKey(), tempMsg);
}
}
}
break;
}
{
KBRforward* apiMsg = dynamic_cast<KBRforward*>(commonAPIMsg);
OverlayKey key = apiMsg->getDestKey();
NodeHandle nextHopNode = apiMsg->getNextHopNode();
forward(&key, &tempMsg, &nextHopNode);
//if message ist not deleted send it back
if(tempMsg != NULL) {
if(nextHopNode == apiMsg->getNextHopNode())
//do we need this?
forwardResponse(key, tempMsg, nextHopNode);
}
break;
}
case KBR_UPDATE:
{
KBRupdate* apiMsg = dynamic_cast<KBRupdate*>(commonAPIMsg);
update(apiMsg->getNode(), apiMsg->getJoined());
break;
}
default:
{
delete tempMsg;
break;
}
}
delete commonAPIMsg;
}
void BaseApp::handleLowerMessage ( cMessage *  msg)
protectedvirtual

processes self-messages

method to handle self-messages should be overwritten in derived application if needed

Parameters
msgself-message method to handle non-commonAPI messages from the overlay
msgmessage to handle

Reimplemented in SimMud, GIASearchApp, SimpleGameClient, and ALMTest.

Definition at line 430 of file BaseApp.cc.

{
delete msg;
}
void BaseApp::handleMessage ( cMessage *  msg)
protected

checks for message type and calls corresponding method

checks for message type (from overlay or selfmessage) and calls corresponding method like deliver(), forward(), and timer()

Parameters
msgthe handled message

Reimplemented in XmlRpcInterface.

Definition at line 137 of file BaseApp.cc.

{
return;
}
if (msg->arrivedOn("from_lowerTier") ||
msg->arrivedOn("direct_in")) {
CompReadyMessage* readyMsg = dynamic_cast<CompReadyMessage*>(msg);
if (readyMsg != NULL) {
handleReadyMessage(readyMsg);
return;
}
// common API
CommonAPIMessage* commonAPIMsg = dynamic_cast<CommonAPIMessage*>(msg);
if (commonAPIMsg != NULL) {
handleCommonAPIMessage(commonAPIMsg);
} else if (msg->arrivedOn("from_lowerTier")) {
// TODO: What kind of messages to we want to measure here?
cPacket* packet = check_and_cast<cPacket*>(msg);
bytesOverlayReceived += packet->getByteLength());
}
else delete msg;
} else if (msg->arrivedOn("from_upperTier")) {
} else if (msg->arrivedOn("udpIn")) {
cPacket* packet = check_and_cast<cPacket*>(msg);
RECORD_STATS(numUdpReceived++; bytesUdpReceived += packet->getByteLength());
// debug message
if (debugOutput && !ev.isDisabled()) {
UDPControlInfo* udpControlInfo =
check_and_cast<UDPControlInfo*>(msg->getControlInfo());
EV << "[BaseApp:handleMessage() @ " << thisNode.getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " Received " << *msg << " from "
<< udpControlInfo->getSrcAddr() << endl;
}
} else if(msg->arrivedOn("tcpIn")) {
} else if (msg->arrivedOn("trace_in")) {
}else {
delete msg;
}
}
void BaseApp::handleNodeGracefulLeaveNotification ( )
protectedvirtual

This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.

Definition at line 236 of file BaseApp.cc.

{
// ...
}
void BaseApp::handleNodeLeaveNotification ( )
protectedvirtual

This method gets call **.gracefulLeaveDelay seconds before it is killed.

Definition at line 231 of file BaseApp.cc.

{
// ...
}
void BaseApp::handleReadyMessage ( CompReadyMessage msg)
protectedvirtual

method to handle ready messages from the overlay

Parameters
msgmessage to handle

Reimplemented in NeighborCache, XmlRpcInterface, Scribe, SimMud, SimpleGameClient, P2pns, and ALMTest.

Definition at line 440 of file BaseApp.cc.

{
delete msg;
}
void BaseApp::handleTraceMessage ( cMessage *  msg)
protectedvirtual

handleTraceMessage gets called of handleMessage(cMessage* msg) if a message arrives at trace_in.

The command included in this message should be parsed and handled.

Parameters
msgthe command message to handle

Definition at line 445 of file BaseApp.cc.

{
throw cRuntimeError("This application cannot handle trace data. "
"You have to overwrite handleTraceMessage() in your "
"application to make trace files work");
}
void BaseApp::handleTransportAddressChangedNotification ( )
protectedvirtual

This method gets call if the node has a new TransportAddress (IP address) because he changed his access network.

Reimplemented in ALMTest.

Definition at line 226 of file BaseApp.cc.

{
// ...
}
void BaseApp::handleUDPMessage ( cMessage *  msg)
protectedvirtual

method to handle messages that come directly from the UDP gate

Parameters
msgmessage to handle

Reimplemented in I3, and ALMTest.

Definition at line 435 of file BaseApp.cc.

{
delete msg;
}
void BaseApp::handleUpperMessage ( cMessage *  msg)
protectedvirtual

handleUpperMessage gets called of handleMessage(cMessage* msg) if msg arrivedOn from_upperTier (currently msg gets deleted in this function)

Parameters
msgthe message to handle

Reimplemented in Scribe, CBRDHT, SimMud, ALMTest, and RealWorldTestApp.

Definition at line 425 of file BaseApp.cc.

{
delete msg;
}
void BaseApp::initialize ( int  stage)
protected

initializes base class-attributes

Parameters
stagethe init stage

Definition at line 58 of file BaseApp.cc.

{
CompType compType = getThisCompType();
bool tier = (compType == TIER1_COMP ||
compType == TIER2_COMP ||
compType == TIER3_COMP);
if (stage == REGISTER_STAGE) {
return;
}
if ((tier && stage == MIN_STAGE_APP) ||
(!tier && stage == MIN_STAGE_COMPONENTS)) {
// fetch parameters
debugOutput = par("debugOutput");
notificationBoard = NotificationBoardAccess().get();
// subscribe to the notification board
notificationBoard->subscribe(this, NF_OVERLAY_TRANSPORTADDRESS_CHANGED);
notificationBoard->subscribe(this, NF_OVERLAY_NODE_LEAVE);
notificationBoard->subscribe(this, NF_OVERLAY_NODE_GRACEFUL_LEAVE);
// determine the terminal's transport address
if (getParentModule()->getSubmodule("interfaceTable", 0) != NULL) {
thisNode.setIp(IPAddressResolver()
.addressOf(getParentModule()));
} else {
thisNode.setIp(IPAddressResolver()
.addressOf(getParentModule()->getParentModule()));
}
WATCH(thisNode);
// statistics
creationTime = simTime();
WATCH(numUdpSent);
WATCH(bytesUdpSent);
// init rpcs
// set TCP output gate
setTcpOut(gate("tcpOut"));
}
if ((stage >= MIN_STAGE_APP && stage <= MAX_STAGE_APP) ||
(stage >= MIN_STAGE_COMPONENTS && stage <= MAX_STAGE_COMPONENTS)) //TODO
initializeApp(stage);
}
void BaseApp::initializeApp ( int  stage)
protectedvirtual

initializes derived class-attributes

Parameters
stagethe init stage

Reimplemented in NeighborCache, XmlRpcInterface, Scribe, CBRDHT, I3, SimMud, GIASearchApp, SimpleGameClient, RealWorldTestApp, and ALMTest.

Definition at line 131 of file BaseApp.cc.

{
// ...
}
bool BaseApp::internalHandleRpcCall ( BaseCallMessage msg)
protectedvirtual

Handles internal rpc requests.


This method is used to implement basic functionality in the BaseRpc.

Parameters
msgThe call message
Returns
bool true, if call has been handled.

Reimplemented from BaseRpc.

Definition at line 559 of file BaseApp.cc.

{
// if RPC was handled return true, else tell the parent class to handle it
}
void BaseApp::internalHandleRpcResponse ( BaseResponseMessage msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
)
protectedvirtual

Handles rpc responses internal in base classes

This method is used to implement basic functionality in the BaseRpc.

Parameters
msgThe call message
contextPointer to an optional state object. The object has to be handled/deleted by the internalHandleRpcResponse() code
rpcIdThe ID of the call
rttthe time between sending the call and receiving the response

Reimplemented from BaseRpc.

Definition at line 565 of file BaseApp.cc.

{
// if RPC was handled return true, else tell the parent class to handle it
BaseRpc::internalHandleRpcResponse(msg, context, rpcId, rtt);
}
void BaseApp::internalSendRouteRpc ( BaseRpcMessage message,
const OverlayKey destKey,
const std::vector< TransportAddress > &  sourceRoute,
RoutingType  routingType 
)
protectedvirtual

Implements BaseRpc.

Definition at line 573 of file BaseApp.cc.

{
callRoute(destKey, message, sourceRoute, routingType);
}
void BaseApp::internalSendRpcResponse ( BaseCallMessage call,
BaseResponseMessage response 
)
private

Definition at line 581 of file BaseApp.cc.

{
// default values for UDP transport
TransportType transportType = UDP_TRANSPORT;
CompType compType = INVALID_COMP;
const TransportAddress* destNode = &TransportAddress::UNSPECIFIED_NODE;//&(call->getSrcNode());
TransportAddress tempNode;
OverlayCtrlInfo* overlayCtrlInfo =
dynamic_cast<OverlayCtrlInfo*>(call->getControlInfo());
if (overlayCtrlInfo &&
overlayCtrlInfo->getTransportType() == ROUTE_TRANSPORT) {
//destNode = &(overlayCtrlInfo->getSrcNode());
if (overlayCtrlInfo->getSrcNode().isUnspecified())
destNode = &(overlayCtrlInfo->getLastHop());
else
destNode = &(overlayCtrlInfo->getSrcNode());
transportType = ROUTE_TRANSPORT;
compType = static_cast<CompType>(overlayCtrlInfo->getSrcComp());
if (static_cast<RoutingType>(overlayCtrlInfo->getRoutingType())
destKey = &(overlayCtrlInfo->getSrcNode().getKey());//&(call->getSrcNode().getKey());
}
} else {
UDPControlInfo* udpCtrlInfo =
check_and_cast<UDPControlInfo*>(call->getControlInfo());
tempNode = TransportAddress(udpCtrlInfo->getSrcAddr(), udpCtrlInfo->getSrcPort());
destNode = &tempNode;
}
sendRpcResponse(transportType, compType,
*destNode, *destKey, call, response);
}
bool BaseApp::isSiblingFor ( const NodeHandle node,
const OverlayKey key,
int  numSiblings,
bool *  err 
)
inlineprotected

Query if a node is among the siblings for a given key.

Query if a node is among the siblings for a given key. This means, that the nodeId of this node among the close numSiblings nodes to the key and that by a local findNode() call all other siblings to this key can be retrieved.

Parameters
nodethe NodeHandle
keydestination key
numSiblingsThe nodes knows all numSiblings nodes close to this key
errreturn false if the range could not be determined
Returns
bool true, if the node is responsible for the key.

Definition at line 264 of file BaseApp.h.

{
return overlay->isSiblingFor(node, key, numSiblings, err);
};
int BaseApp::numInitStages ( ) const
protected

method to set InitStage

Reimplemented in I3.

Definition at line 53 of file BaseApp.cc.

Referenced by ALMTest::initializeApp().

{
return MAX_STAGE_APP + 1;
}
void BaseApp::receiveChangeNotification ( int  category,
const cPolymorphic *  details 
)
protectedvirtual

callback-method for events at the NotificationBoard

Parameters
category...
details...

Definition at line 214 of file BaseApp.cc.

{
Enter_Method_Silent();
if (category == NF_OVERLAY_TRANSPORTADDRESS_CHANGED) {
} else if (category == NF_OVERLAY_NODE_LEAVE) {
} else if (category == NF_OVERLAY_NODE_GRACEFUL_LEAVE) {
}
}
void BaseApp::sendMessageToLowerTier ( cPacket *  msg)
protected

sends non-commonAPI message to the lower tier

Parameters
msgmessage to send

Definition at line 452 of file BaseApp.cc.

Referenced by SimpleGameClient::handleRealworldPacket(), SimpleGameClient::handleTimerEvent(), GIASearchApp::handleTimerEvent(), and SimpleGameClient::updatePosition().

{
RECORD_STATS(numOverlaySent++; bytesOverlaySent += msg->getByteLength());
send(msg, "to_lowerTier");
}
void BaseApp::sendMessageToUDP ( const TransportAddress destAddr,
cPacket *  msg,
simtime_t  delay = SIMTIME_ZERO 
)
protectedvirtual

Sends a packet over UDP.

Reimplemented from BaseRpc.

Definition at line 526 of file BaseApp.cc.

Referenced by MyApplication::deliver().

{
// send message to UDP, with the appropriate control info attached
msg->removeControlInfo();
msg->setKind(UDP_C_DATA);
UDPControlInfo *ctrl = new UDPControlInfo();
ctrl->setSrcPort(thisNode.getPort());
ctrl->setSrcAddr(thisNode.getIp());
ctrl->setDestAddr(destAddr.getIp());
ctrl->setDestPort(destAddr.getPort());
msg->setControlInfo(ctrl);
if (ev.isGUI()) {
BaseRpcMessage* rpc = dynamic_cast<BaseRpcMessage*>(msg);
if (rpc) rpc->setStatType(APP_DATA_STAT);
}
// debug message
if (debugOutput) {
EV << "[BaseApp::sendMessageToUDP() @ " << thisNode.getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " Sending " << *msg << " to " << destAddr.getIp()
<< endl;
}
RECORD_STATS(numUdpSent++; bytesUdpSent += msg->getByteLength());
sendDelayed(msg, delay, "udpOut");
}
void BaseApp::sendReadyMessage ( bool  ready = true,
const OverlayKey nodeId = OverlayKey::UNSPECIFIED_KEY 
)
protected

Definition at line 458 of file BaseApp.cc.

Referenced by NeighborCache::prepareOverlay().

void BaseApp::update ( const NodeHandle node,
bool  joined 
)
protectedvirtual

Common API function: informs application about neighbors and own nodeID.

Parameters
nodenew or lost neighbor
joinednew or lost?

Reimplemented in Scribe, and CBRDHT.

Definition at line 317 of file BaseApp.cc.

{
EV << "[BaseApp::update() @ " << thisNode.getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " " << node << (joined ? " joined " : " left ") << "siblings"
<< endl;
/*
std::cout << simTime() << " [BaseApp::update() @ " << thisNode.getIp()
<< " (" << overlay->getThisNode().getKey().toString(16) << ")]\n"
<< " " << node << (joined ? " joined " : " left ") << "siblings"
<< std::endl;
*/
}

Member Data Documentation

int BaseApp::bytesOverlayReceived
protected

number of received bytes from overlay

Definition at line 356 of file BaseApp.h.

int BaseApp::bytesOverlaySent
protected

number of sent bytes to overlay

Definition at line 354 of file BaseApp.h.

int BaseApp::bytesUdpReceived
protected

number of received bytes from UDP

Definition at line 360 of file BaseApp.h.

int BaseApp::bytesUdpSent
protected

number of sent bytes to UDP

Definition at line 358 of file BaseApp.h.

simtime_t BaseApp::creationTime
protected

simTime when the App has been created

Definition at line 362 of file BaseApp.h.

Referenced by KBRTestApp::finishApp(), and NeighborCache::finishApp().

bool BaseApp::debugOutput
protected

debug output yes/no?

Definition at line 350 of file BaseApp.h.

Referenced by GIASearchApp::handleLowerMessage(), GIASearchApp::handleTimerEvent(), and SimpleGameClient::initializeApp().

GlobalNodeList* BaseApp::globalNodeList
protected
NotificationBoard* BaseApp::notificationBoard
protected

pointer to NotificationBoard in this node

Definition at line 346 of file BaseApp.h.

int BaseApp::numOverlayReceived
protected

number of received packets from overlay

Definition at line 355 of file BaseApp.h.

int BaseApp::numOverlaySent
protected

number of sent packets to overlay

Definition at line 353 of file BaseApp.h.

int BaseApp::numUdpReceived
protected

number of received packets from UDP

Definition at line 359 of file BaseApp.h.

int BaseApp::numUdpSent
protected

number of sent packets to UDP

Definition at line 357 of file BaseApp.h.


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