Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions

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

List of all members.

Public Member Functions

 BaseApp ()
virtual ~BaseApp ()
 virtual destructor

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)
 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)
void internalHandleRpcResponse (BaseResponseMessage *msg, cPolymorphic *context, int rpcId, simtime_t rtt)
void internalSendRouteRpc (BaseRpcMessage *message, const OverlayKey &destKey, const std::vector< TransportAddress > &sourceRoute, RoutingType routingType)
virtual CompType getThisCompType ()
void sendReadyMessage (bool ready=true)

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

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)

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.

{
    notificationBoard = NULL;

    overlay = NULL;
}

BaseApp::~BaseApp (  )  [virtual]

virtual destructor

Definition at line 48 of file BaseApp.cc.

{
    finishRpcs();
}


Member Function Documentation

void BaseApp::bindToPort ( int  port  )  [protected, virtual]

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

Definition at line 498 of file BaseApp.cc.

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

{
    EV << "[BaseApp::bindToPort() @ " << thisNode.getIp()
       << ":  Binding to UDP port " << port << endl;

    thisNode.setPort(port);

    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 
) [inline, protected]

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

Parameters:
key the destination key
num maximal number of nodes in answer
safe fraction 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  )  [inline, protected]

Common API function: produces a list of neighbor nodes.

Parameters:
num maximal 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 
) [inline, protected]

Common API function: calls route-method in overlay.

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

Parameters:
key destination key
msg message to route
hint next hop (usually unused)
routingType specifies the routing mode (ITERATIVE_ROUTING, ...)

Definition at line 181 of file BaseApp.h.

Referenced by Scribe::checkGroupEmpty(), RealWorldTestApp::deliver(), Scribe::deliverALMDataToGroup(), Scribe::handleTimerEvent(), MyApplication::handleTimerEvent(), KBRTestApp::handleTimerEvent(), I3::handleUDPMessage(), RealWorldTestApp::handleUpperMessage(), internalSendRouteRpc(), I3::sendPacket(), and P2pns::sendTunnelMessage().

    {
        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->setSrcComp(thisCompType);
    routeMsg->setDestComp(thisCompType);
    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 
) [protected, virtual]

Common API function: handles delivered messages from overlay.

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

Parameters:
key destination key
msg delivered message

Reimplemented in I3, I3TRTServer, KBRTestApp, MyApplication, RealWorldTestApp, Scribe, and P2pns.

Definition at line 283 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

{
    // deliver...

    delete msg;
}

void BaseApp::finish (  )  [protected]

collects statistical data

Reimplemented in I3, and I3TRTServer.

Definition at line 455 of file BaseApp.cc.

{
    // record scalar data
    simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);

    string baseAppName = string("BaseApp (") += string(this->getName())
                         += string("): ");

    if (time >= GlobalStatistics::MIN_MEASURED) {
        globalStatistics->addStdDev(baseAppName + string("Sent Messages/s to "
                                                         "Overlay"),
                                    numOverlaySent / time);
        globalStatistics->addStdDev(baseAppName +
                                    string("Received Messages/s from Overlay"),
                                    numOverlayReceived / time);
        globalStatistics->addStdDev(baseAppName + string("Sent Bytes/s to "
                                                         "Overlay"),
                                    bytesOverlaySent / time);
        globalStatistics->addStdDev(baseAppName + string("Received Bytes/s "
                                                         "from Overlay"),
                                    bytesOverlayReceived / time);
        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"),
                                    bytesUdpReceived / time);

    }

    finishApp();
}

void BaseApp::finishApp (  )  [protected, virtual]

collects statistical data of derived app

Reimplemented in ALMTest, DHT, GIASearchApp, KBRTestApp, MyApplication, RealWorldTestApp, Scribe, SimpleGameClient, TCPExampleApp, BootstrapList, CBRDHT, Landmark, NeighborCache, DHTTestApp, P2pns, and SimMud.

Definition at line 493 of file BaseApp.cc.

Referenced by finish().

{
    // ...
}

void BaseApp::forward ( OverlayKey key,
cPacket **  msg,
NodeHandle nextHopNode 
) [protected, virtual]

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:
key destination key
msg message to forward
nextHopNode next hop

Reimplemented in I3, KBRTestApp, and Scribe.

Definition at line 290 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

{
    // 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:
key the destination OverlayKey
msg the message to forward
nextHopNode the considered next hop node on the route to the destination

Definition at line 295 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

{
    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);

    if (getThisCompType() == TIER1_COMP) {
        send(forwardMsg, "to_lowerTier");
    } else {
        sendDirect(forwardMsg, overlay->getCompRpcGate(OVERLAY_COMP));
    }
}

CompType BaseApp::getThisCompType (  )  [protected, virtual]

Reimplemented in BootstrapList, and NeighborCache.

Definition at line 186 of file BaseApp.cc.

Referenced by forwardResponse(), SimpleGameClient::handleReadyMessage(), SimMud::handleReadyMessage(), Scribe::handleReadyMessage(), ALMTest::handleReadyMessage(), initialize(), and sendReadyMessage().

{
    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:
commonAPIMsg CommonAPIMessage

Definition at line 321 of file BaseApp.cc.

Referenced by handleMessage().

{
    cPacket* tempMsg = commonAPIMsg->decapsulate();

    // process interface control information
    OverlayCtrlInfo* overlayCtrlInfo =
        dynamic_cast<OverlayCtrlInfo*>(commonAPIMsg->removeControlInfo());

    if (overlayCtrlInfo != NULL) {
        tempMsg->setControlInfo(overlayCtrlInfo);
    }

    switch (commonAPIMsg->getType()) {
        case KBR_DELIVER:
        {
            KBRdeliver* apiMsg = dynamic_cast<KBRdeliver*>(commonAPIMsg);
            OverlayKey key = apiMsg->getDestKey();
            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 {
                    RECORD_STATS(numOverlayReceived++;
                                 bytesOverlayReceived += tempMsg->getByteLength());

                    assert(overlayCtrlInfo->getTransportType()
                           == ROUTE_TRANSPORT);

                    // 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) {
                        internalHandleRpcMessage(rpcMessage);
                    } else {
                        deliver(apiMsg->getDestKey(), tempMsg);
                    }
                }
            }
            break;
        }

        case KBR_FORWARD:
        {
            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?
                    nextHopNode = NodeHandle::UNSPECIFIED_NODE;
                forwardResponse(key, tempMsg, nextHopNode);
            }
            break;
        }

        case KBR_UPDATE:
        {
            KBRupdate* apiMsg = dynamic_cast<KBRupdate*>(commonAPIMsg);
            update(apiMsg->getNode(), apiMsg->getJoined());

            break;
        }

        default:
        {
            delete tempMsg;
        }
    }
    delete commonAPIMsg;
}

void BaseApp::handleLowerMessage ( cMessage *  msg  )  [protected, virtual]

processes self-messages

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

Parameters:
msg self-message method to handle non-commonAPI messages from the overlay
msg message to handle

Reimplemented in ALMTest, GIASearchApp, SimpleGameClient, and SimMud.

Definition at line 418 of file BaseApp.cc.

Referenced by handleMessage().

{
    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:
msg the handled message

Definition at line 137 of file BaseApp.cc.

{
    if (internalHandleMessage(msg)) {
        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);
            RECORD_STATS(numOverlayReceived++;
                         bytesOverlayReceived += packet->getByteLength());
            handleLowerMessage(msg);
        }
        else delete msg;
    } else if (msg->arrivedOn("from_upperTier")) {
        handleUpperMessage(msg);
    } 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;
        }
        handleUDPMessage(msg);
    } else if(msg->arrivedOn("tcpIn")) {
        handleTCPMessage(msg);
    } else if (msg->arrivedOn("trace_in")) {
        handleTraceMessage(msg);
    }else {
        delete msg;
    }
}

void BaseApp::handleNodeGracefulLeaveNotification (  )  [protected, virtual]

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.

Referenced by receiveChangeNotification().

{
    // ...
}

void BaseApp::handleNodeLeaveNotification (  )  [protected, virtual]

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

Reimplemented in KBRTestApp, and DHTTestApp.

Definition at line 231 of file BaseApp.cc.

Referenced by receiveChangeNotification().

{
    // ...
}

void BaseApp::handleReadyMessage ( CompReadyMessage msg  )  [protected, virtual]

method to handle ready messages from the overlay

Parameters:
msg message to handle

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

Definition at line 428 of file BaseApp.cc.

Referenced by handleMessage().

{
    delete msg;
}

void BaseApp::handleTraceMessage ( cMessage *  msg  )  [protected, virtual]

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:
msg the command message to handle

Reimplemented in DHTTestApp.

Definition at line 433 of file BaseApp.cc.

Referenced by handleMessage().

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

void BaseApp::handleTransportAddressChangedNotification (  )  [protected, virtual]

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.

Referenced by receiveChangeNotification().

{
    // ...
}

void BaseApp::handleUDPMessage ( cMessage *  msg  )  [protected, virtual]

method to handle messages that come directly from the UDP gate

Parameters:
msg message to handle

Reimplemented in ALMTest, I3, and MyApplication.

Definition at line 423 of file BaseApp.cc.

Referenced by handleMessage().

{
    delete msg;
}

void BaseApp::handleUpperMessage ( cMessage *  msg  )  [protected, virtual]

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

Parameters:
msg the message to handle

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

Definition at line 413 of file BaseApp.cc.

Referenced by handleMessage().

{
    delete msg;
}

void BaseApp::initialize ( int  stage  )  [protected]

initializes base class-attributes

Parameters:
stage the 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) {
        OverlayAccess().get(this)->registerComp(getThisCompType(), this);
        return;
    }

    if ((tier && stage == MIN_STAGE_APP) ||
        (!tier && stage == MIN_STAGE_COMPONENTS)) {
        // fetch parameters
        debugOutput = par("debugOutput");

        globalNodeList = GlobalNodeListAccess().get();
        underlayConfigurator = UnderlayConfiguratorAccess().get();
        globalStatistics = GlobalStatisticsAccess().get();
        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()));
        }

        thisNode.setPort(-1);

        WATCH(thisNode);

        // statistics
        numOverlaySent = 0;
        numOverlayReceived = 0;
        bytesOverlaySent = 0;
        bytesOverlayReceived = 0;
        numUdpSent = 0;
        numUdpReceived = 0;
        bytesUdpSent = 0;
        bytesUdpReceived = 0;

        creationTime = simTime();

        WATCH(numOverlaySent);
        WATCH(numOverlayReceived);
        WATCH(bytesOverlaySent);
        WATCH(bytesOverlayReceived);
        WATCH(numUdpSent);
        WATCH(numUdpReceived);
        WATCH(bytesUdpSent);
        WATCH(bytesUdpReceived);

        // init rpcs
        initRpcs();

        // 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  )  [protected, virtual]

initializes derived class-attributes

Parameters:
stage the init stage

Reimplemented in ALMTest, DHT, GIASearchApp, I3, I3TRTServer, KBRTestApp, MyApplication, RealWorldTestApp, Scribe, SimpleGameClient, TCPExampleApp, BootstrapList, CBRDHT, Landmark, NeighborCache, DHTTestApp, P2pns, and SimMud.

Definition at line 131 of file BaseApp.cc.

Referenced by initialize().

{
    // ...
}

bool BaseApp::internalHandleRpcCall ( BaseCallMessage msg  )  [protected]

Definition at line 545 of file BaseApp.cc.

{
    // if RPC was handled return true, else tell the parent class to handle it
    return BaseRpc::internalHandleRpcCall(msg);
}

void BaseApp::internalHandleRpcResponse ( BaseResponseMessage msg,
cPolymorphic *  context,
int  rpcId,
simtime_t  rtt 
) [protected]

Definition at line 551 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 
) [protected]

Definition at line 559 of file BaseApp.cc.

                                                            {
    callRoute(destKey, message, sourceRoute, routingType);
}

void BaseApp::internalSendRpcResponse ( BaseCallMessage call,
BaseResponseMessage response 
) [private]

Definition at line 567 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());
    const OverlayKey* destKey = &OverlayKey::UNSPECIFIED_KEY;

    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())
                == FULL_RECURSIVE_ROUTING) {
            destKey = &(overlayCtrlInfo->getSrcNode().getKey());//&(call->getSrcNode().getKey());
            destNode = &NodeHandle::UNSPECIFIED_NODE;
        }
    } 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 
) [inline, protected]

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:
node the NodeHandle
key destination key
numSiblings The nodes knows all numSiblings nodes close to this key
err return 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 SimMud::initializeApp(), Scribe::initializeApp(), and ALMTest::initializeApp().

{
    return MAX_STAGE_APP + 1;
}

void BaseApp::receiveChangeNotification ( int  category,
const cPolymorphic *  details 
) [protected, virtual]

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) {
        handleTransportAddressChangedNotification();
    } else if (category == NF_OVERLAY_NODE_LEAVE) {
        handleNodeLeaveNotification();
    } else if (category == NF_OVERLAY_NODE_GRACEFUL_LEAVE) {
        handleNodeGracefulLeaveNotification();
    }
}

void BaseApp::sendMessageToLowerTier ( cPacket *  msg  )  [protected]

sends non-commonAPI message to the lower tier

Parameters:
msg message to send

Definition at line 440 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 
) [protected, virtual]

Sends a packet over UDP.

Definition at line 513 of file BaseApp.cc.

Referenced by MyApplication::deliver(), I3::sendQueryReply(), and I3::sendToNode().

{
    // 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());
    send(msg, "udpOut");
}

void BaseApp::sendReadyMessage ( bool  ready = true  )  [protected]
void BaseApp::update ( const NodeHandle node,
bool  joined 
) [protected, virtual]

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

Parameters:
node new or lost neighbor
joined new or lost?

Reimplemented in DHT, Scribe, and CBRDHT.

Definition at line 317 of file BaseApp.cc.

Referenced by handleCommonAPIMessage().

{
}


Member Data Documentation

number of received bytes from overlay

Definition at line 354 of file BaseApp.h.

Referenced by finish(), handleCommonAPIMessage(), handleMessage(), and initialize().

int BaseApp::bytesOverlaySent [protected]

number of sent bytes to overlay

Definition at line 352 of file BaseApp.h.

Referenced by callRoute(), finish(), initialize(), and sendMessageToLowerTier().

int BaseApp::bytesUdpReceived [protected]

number of received bytes from UDP

Definition at line 358 of file BaseApp.h.

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

int BaseApp::bytesUdpSent [protected]

number of sent bytes to UDP

Definition at line 356 of file BaseApp.h.

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

NotificationBoard* BaseApp::notificationBoard [protected]

pointer to NotificationBoard in this node

Definition at line 344 of file BaseApp.h.

Referenced by BaseApp(), and initialize().

int BaseApp::numOverlayReceived [protected]

number of received packets from overlay

Definition at line 353 of file BaseApp.h.

Referenced by finish(), handleCommonAPIMessage(), handleMessage(), and initialize().

int BaseApp::numOverlaySent [protected]

number of sent packets to overlay

Definition at line 351 of file BaseApp.h.

Referenced by callRoute(), finish(), initialize(), and sendMessageToLowerTier().

int BaseApp::numUdpReceived [protected]

number of received packets from UDP

Definition at line 357 of file BaseApp.h.

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

int BaseApp::numUdpSent [protected]

number of sent packets to UDP

Definition at line 355 of file BaseApp.h.

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


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