Public Member Functions | Protected Member Functions | Protected Attributes

Gia Class Reference

Gia overlay module. More...

#include <Gia.h>

Inheritance diagram for Gia:
BaseOverlay BaseRpc BaseTcpSupport TopologyVis RpcListener

List of all members.

Public Member Functions

void initializeOverlay (int stage)
 initializes base class-attributes
void finishOverlay ()
 Writes statistical data and removes node from bootstrap oracle.
virtual void changeState (int toStage)
 Set state to toStage.
void updateTooltip ()
 Marks nodes if they are ready.
 ~Gia ()
 Destructor.
void handleTimerEvent (cMessage *msg)
void handleUDPMessage (BaseOverlayMessage *msg)
 Processes messages from underlay.
virtual void getRoute (const OverlayKey &key, CompType destComp, CompType srcComp, cPacket *msg, const std::vector< TransportAddress > &sourceRoute=TransportAddress::UNSPECIFIED_NODES, RoutingType routingType=DEFAULT_ROUTING)
void handleAppMessage (cMessage *msg)
 Processes "timer" self-messages.
void sendToken (const GiaNode &dst)

Protected Member Functions

void joinOverlay ()
 Join the overlay with a given nodeID in thisNode.key.
bool acceptNode (const GiaNode &newNode, unsigned int degree)
 Decides if Node newNode will be accepted as new neighor.
void addNeighbor (GiaNode &newNode, unsigned int degree)
 Adds newNode as new neighbor.
void removeNeighbor (const GiaNode &newNode)
 Removes newNode from our NeighborList.
double calculateLevelOfSatisfaction ()
 Calculates level of satisfaction.
void sendMessage_JOIN_REQ (const NodeHandle &dst)
 Sends JOIN_REQ_Message from node src to node dst.
void sendMessage_JOIN_RSP (const NodeHandle &dst)
 Sends JOIN_RSP_Message from node src to node dst.
void sendMessage_JOIN_ACK (const NodeHandle &dst)
 Sends JOIN_ACK_Message from node src to node dst.
void sendMessage_JOIN_DNY (const NodeHandle &dst)
 Sends JOIN_DNY_Message from node src to node dst.
void sendMessage_DISCONNECT (const NodeHandle &dst)
 Sends DISCONNECT_Message from node src to node dst.
void sendMessage_UPDATE (const NodeHandle &dst)
 Sends UPDATE_Message from node src to node dst.
void sendKeyListToNeighbor (const NodeHandle &dst)
 Sends KeyList to node dst.
void updateNeighborList (GiaMessage *msg)
 Updates neighborlist with new capacity and connectiondegree informations from received message msg.
void forwardSearchResponseMessage (SearchResponseMessage *msg)
 Forwards a search response message to the next node in reverse-path.
void forwardMessage (GiaIDMessage *msg, bool fromApplication)
 Forwards a message to the next random selected node, biased random walk.
void processSearchMessage (SearchMessage *msg, bool fromApplication)
 Processes search message msg.
void sendSearchResponseMessage (const GiaNode &srcNode, SearchMessage *msg)
 Sends a response message to a received search query.
void deliverSearchResult (SearchResponseMessage *msg)
 Delivers search result to application layer.

Protected Attributes

uint32_t maxNeighbors
 maximum number of neighbors
uint32_t minNeighbors
 minimum number of neighbors
uint32_t maxTopAdaptionInterval
 maximum topology adaption interval
uint32_t topAdaptionAggressiveness
 the topology adaption aggressiveness
double maxLevelOfSatisfaction
 maximum level of satisfaction
double updateDelay
 time between to update messages (in ms)
uint32_t maxHopCount
 maximum time to live for sent messages
uint32_t messageTimeout
 timeout for messages
uint32_t neighborTimeout
 timeout for neighbors
uint32_t sendTokenTimeout
 timeout for tokens
uint32_t tokenWaitTime
 delay to send a new token
double keyListDelay
 delay to send the keylist to our neighbors
bool outputNodeDetails
 output of node details? (on std::cout)
bool optimizeReversePath
 use optimized reverse path?
double levelOfSatisfaction
 current level of statisfaction
unsigned int connectionDegree
unsigned int receivedTokens
unsigned int sentTokens
GiaNode thisGiaNode
 this node
NodeHandle bootstrapNode
 next possible neighbor candidate
GiaMessageBookkeepingmsgBookkeepingList
 pointer to a message bookkeeping list
uint32_t stat_joinCount
 number of sent join messages
uint32_t stat_joinBytesSent
 number of sent bytes of join messages
uint32_t stat_joinREQ
 number of sent join request messages
uint32_t stat_joinREQBytesSent
 number of sent bytes of join request messages
uint32_t stat_joinRSP
 number of sent join response messages
uint32_t stat_joinRSPBytesSent
 number of sent bytes of join response messages
uint32_t stat_joinACK
 number of sent join acknowledge messages
uint32_t stat_joinACKBytesSent
 number of sent bytes of join acknowledge messages
uint32_t stat_joinDNY
 number of sent join deny messages
uint32_t stat_joinDNYBytesSent
 number of sent bytes of join deny messages
uint32_t stat_disconnectMessages
 number of sent disconnect messages
uint32_t stat_disconnectMessagesBytesSent
 number of sent bytes of disconnect messages
uint32_t stat_updateMessages
 number of sent update messages
uint32_t stat_updateMessagesBytesSent
 number of sent bytes of update messages
uint32_t stat_tokenMessages
 number of sent token messages
uint32_t stat_tokenMessagesBytesSent
 number of sent bytes of token messages
uint32_t stat_keyListMessages
 number of sent keylist messages
uint32_t stat_keyListMessagesBytesSent
 number of sent bytes of keylist messages
uint32_t stat_routeMessages
 number of sent route messages
uint32_t stat_routeMessagesBytesSent
 number of sent bytes of route messages
uint32_t stat_maxNeighbors
 maximum number of neighbors
uint32_t stat_addedNeighbors
 number of added neighbors during life cycle of this node
uint32_t stat_removedNeighbors
 number of removed neighbors during life cycle of this node
uint32_t stat_numSatisfactionMessages
 number of satisfaction self-messages
double stat_sumLevelOfSatisfaction
 sum of level of satisfaction
double stat_maxLevelOfSatisfaction
 maximum level of satisfaction
cMessage * satisfaction_timer
 timer for satisfaction self-message
cMessage * update_timer
 timer for update self-message
cMessage * timedoutMessages_timer
 timer for message timeout
cMessage * timedoutNeighbors_timer
 timer for neighbors timeout
cMessage * sendKeyList_timer
 timer for send keylist
cMessage * sendToken_timer
 timer for send token
GiaKeyListModulekeyListModule
 pointer to KeyListModule
GiaNeighborsneighbors
 pointer to neighbor list
GiaTokenFactorytokenFactory
 pointer to TokenFactory
GiaNeighborCandidateList neighCand
 list of all neighbor candidates
GiaNeighborCandidateList knownNodes
 list of known nodes in the overlay
GiaKeyList keyList
 key list of this node

Detailed Description

Gia overlay module.

Implementation of the Gia overlay as described in "Making Gnutella-like P2P Systems Scalable" by Y. Chawathe et al. published at SIGCOMM'03

Author:
Robert Palmer

Definition at line 61 of file Gia.h.


Constructor & Destructor Documentation

Gia::~Gia (  ) 

Destructor.

Definition at line 1248 of file Gia.cc.

{
    cancelAndDelete(satisfaction_timer);
    cancelAndDelete(update_timer);
    cancelAndDelete(timedoutMessages_timer);
    cancelAndDelete(timedoutNeighbors_timer);
    cancelAndDelete(sendKeyList_timer);
    cancelAndDelete(sendToken_timer);
    delete msgBookkeepingList;
}


Member Function Documentation

bool Gia::acceptNode ( const GiaNode newNode,
unsigned int  degree 
) [protected]

Decides if Node newNode will be accepted as new neighor.

Parameters:
newNode Node to accept or deny
degree the node's connection degree
Returns:
boolean true or false

Definition at line 569 of file Gia.cc.

Referenced by handleUDPMessage().

{
    if (neighbors->contains(nNode))
        return false;

    if (neighbors->getSize() < maxNeighbors) {
        // we have room for new node: accept node
        return true;
    }
    // we need to drop a neighbor
    NodeHandle dropCandidate = neighbors->getDropCandidate(nNode.getCapacity(), degree);
    if(!dropCandidate.isUnspecified()) {
        if (debugOutput)
            EV << "(Gia) " << thisGiaNode << " drops "
               << dropCandidate <<  endl;
        neighbors->remove(dropCandidate);
        sendMessage_DISCONNECT(dropCandidate);
        return true;
    }
    return false;
}

void Gia::addNeighbor ( GiaNode newNode,
unsigned int  degree 
) [protected]

Adds newNode as new neighbor.

Parameters:
newNode the node to add as a neighbor
degree the node's connection degree

Definition at line 592 of file Gia.cc.

Referenced by handleUDPMessage().

{
    assert(neighbors->getSize() < maxNeighbors);

    stat_addedNeighbors++;
    EV << "(Gia) " << thisGiaNode << " accepted new neighbor " << node << endl;
    getParentModule()->getParentModule()->bubble("New neighbor");
    connectionDegree = neighbors->getSize();
    changeState(READY);
    if (stat_maxNeighbors < neighbors->getSize()) {
        stat_maxNeighbors = neighbors->getSize();
    }

    cancelEvent(update_timer);
    scheduleAt(simTime() + updateDelay, update_timer);

    //node.setSentTokens(5);
    //node.setReceivedTokens(5);

    // send keyList to new Neighbor
    if (keyList.getSize() > 0)
        sendKeyListToNeighbor(node);
    neighbors->add(node, degree);

    showOverlayNeighborArrow(node, false,
                             "m=m,50,0,50,0;ls=red,1");
    updateTooltip();
}

double Gia::calculateLevelOfSatisfaction (  )  [protected]

Calculates level of satisfaction.

Returns:
levelOfSatisfaction value

Definition at line 643 of file Gia.cc.

Referenced by handleTimerEvent().

{
    uint32_t neighborsCount = neighbors->getSize();
    if(neighborsCount < minNeighbors)
        return 0.0;

    double total = 0.0;
    double levelOfSatisfaction = 0.0;

    for (uint32_t i=0; i < neighborsCount; i++)
        total += neighbors->get(i).getCapacity() / neighborsCount;

    assert(thisGiaNode.getCapacity() != 0);
    levelOfSatisfaction = total / thisGiaNode.getCapacity();

    if ((levelOfSatisfaction > 1.0) || (neighborsCount >= maxNeighbors))
        return 1.0;
    return levelOfSatisfaction;
}

void Gia::changeState ( int  toStage  )  [virtual]

Set state to toStage.

Parameters:
toStage the stage to change to

Definition at line 124 of file Gia.cc.

Referenced by addNeighbor(), handleTimerEvent(), joinOverlay(), and removeNeighbor().

{
    switch (toState) {
    case INIT: {
        state = INIT;

        setOverlayReady(false);
        showOverlayNeighborArrow(thisGiaNode);

        // set up local nodehandle
        //thisGiaNode.setNodeHandle(thisNode);
        thisGiaNode = thisNode;

        callUpdate(thisNode, true);

        // get possible bandwidth from ppp-Module
        double capacity = 0;

        cModule* nodeModule = getParentModule()->getParentModule();

        if(!nodeModule->hasGate("pppg$i"))
            capacity += uniform(1,800000);
        else {
            // this relies on IPv4Underlay
                int gateSize = nodeModule->gateSize("pppg$i");
            for (int i=0; i<gateSize; i++) {
                cGate* currentGate = nodeModule->gate("pppg$i",i);
                if (currentGate->isConnected())
                    capacity += check_and_cast<cDatarateChannel *>
                        (currentGate->getPreviousGate()->getChannel())->getDatarate()
                        - uniform(0,800000);
            }
        }

        thisGiaNode.setCapacity(capacity);
        //thisGiaNode.setConnectionDegree(0);
        //thisGiaNode.setReceivedTokens(0);
        //thisGiaNode.setSentTokens(0);

        connectionDegree = 0;
        receivedTokens = 0;
        sentTokens = 0;

        if (outputNodeDetails)
            EV << "(Gia) Node details: " << thisGiaNode << endl;

        // get our entry point to GIA-Overlay
        bootstrapNode = bootstrapList->getBootstrapNode();
        if(!(bootstrapNode.isUnspecified()))
            knownNodes.add(bootstrapNode);
        //else {
        //assert(!(thisGiaNode.getNodeHandle().isUnspecified()));
        //globalNodeList->registerPeer(thisGiaNode.getNodeHandle());
        //}

        // register node at TokenFactory
        //tokenFactory->setNode(&thisGiaNode);
        tokenFactory->setNeighbors(neighbors);
        tokenFactory->setMaxHopCount(maxHopCount);

        if (debugOutput)
            EV << "(Gia) Node " << thisGiaNode.getKey()
               << " (" << thisGiaNode.getIp() << ":"
               << thisGiaNode.getPort() << ") with capacity: "
               << thisGiaNode.getCapacity()  << " entered INIT state." << endl;

        getParentModule()->getParentModule()->bubble("Enter INIT state.");

        // schedule satisfaction_timer
        cancelEvent(satisfaction_timer);
        scheduleAt(simTime(), satisfaction_timer);

        // schedule timedoutMessages_timer
        cancelEvent(timedoutMessages_timer);
        scheduleAt(simTime() + messageTimeout,
                   timedoutMessages_timer);

        cancelEvent(timedoutNeighbors_timer);
        scheduleAt(simTime() + neighborTimeout,
                   timedoutNeighbors_timer);

        cancelEvent(sendToken_timer);
        scheduleAt(simTime() + sendTokenTimeout,
                   sendToken_timer);

        break;
    }
    case READY:
        state = READY;
        setOverlayReady(true);
        break;
    }
    updateTooltip();
}

void Gia::deliverSearchResult ( SearchResponseMessage msg  )  [protected]

Delivers search result to application layer.

Parameters:
msg Search response message

Definition at line 1190 of file Gia.cc.

Referenced by forwardSearchResponseMessage(), and sendSearchResponseMessage().

{
    OverlayCtrlInfo* overlayCtrlInfo = new OverlayCtrlInfo();
    overlayCtrlInfo->setHopCount(msg->getSearchHopCount());
    overlayCtrlInfo->setSrcNode(msg->getSrcNode());
    overlayCtrlInfo->setTransportType(ROUTE_TRANSPORT);

    GIAanswer* deliverMsg = new GIAanswer("GIA-Answer");
    deliverMsg->setCommand(GIA_ANSWER);
    deliverMsg->setControlInfo(overlayCtrlInfo);
    deliverMsg->setSearchKey(msg->getSearchKey());
    deliverMsg->setNode(msg->getFoundNode());
    deliverMsg->setBitLength(GIAGETRSP_L(msg));

    send(deliverMsg, "appOut");
    if (debugOutput)
        EV << "(Gia) Deliver search response " << msg
           << " to application at " << thisGiaNode << endl;

    delete msg;
}

void Gia::finishOverlay (  )  [virtual]

Writes statistical data and removes node from bootstrap oracle.

Reimplemented from BaseOverlay.

Definition at line 1212 of file Gia.cc.

{
    // statistics

    globalStatistics->addStdDev("GIA: JOIN-Messages Count", stat_joinCount);
    globalStatistics->addStdDev("GIA: JOIN Bytes sent", stat_joinBytesSent);
    globalStatistics->addStdDev("GIA: JOIN::REQ Messages", stat_joinREQ);
    globalStatistics->addStdDev("GIA: JOIN::REQ Bytes sent", stat_joinREQBytesSent);
    globalStatistics->addStdDev("GIA: JOIN::RSP Messages", stat_joinRSP);
    globalStatistics->addStdDev("GIA: JOIN::RSP Bytes sent", stat_joinRSPBytesSent);
    globalStatistics->addStdDev("GIA: JOIN::ACK Messages", stat_joinACK);
    globalStatistics->addStdDev("GIA: JOIN::ACK Bytes sent", stat_joinACKBytesSent);
    globalStatistics->addStdDev("GIA: JOIN::DNY Messages", stat_joinDNY);
    globalStatistics->addStdDev("GIA: JOIN::DNY Bytes sent", stat_joinDNYBytesSent);
    globalStatistics->addStdDev("GIA: DISCONNECT:IND Messages", stat_disconnectMessages);
    globalStatistics->addStdDev("GIA: DISCONNECT:IND Bytes sent",
                                stat_disconnectMessagesBytesSent);
    globalStatistics->addStdDev("GIA: UPDATE:IND Messages", stat_updateMessages);
    globalStatistics->addStdDev("GIA: UPDATE:IND Bytes sent", stat_updateMessagesBytesSent);
    globalStatistics->addStdDev("GIA: TOKEN:IND Messages", stat_tokenMessages);
    globalStatistics->addStdDev("GIA: TOKEN:IND Bytes sent", stat_tokenMessagesBytesSent);
    globalStatistics->addStdDev("GIA: KEYLIST:IND Messages", stat_keyListMessages);
    globalStatistics->addStdDev("GIA: KEYLIST:IND Bytes sent", stat_keyListMessagesBytesSent);
    globalStatistics->addStdDev("GIA: ROUTE:IND Messages", stat_routeMessages);
    globalStatistics->addStdDev("GIA: ROUTE:IND Bytes sent", stat_routeMessagesBytesSent);
    globalStatistics->addStdDev("GIA: Neighbors max", stat_maxNeighbors);
    globalStatistics->addStdDev("GIA: Neighbors added", stat_addedNeighbors);
    globalStatistics->addStdDev("GIA: Neighbors removed", stat_removedNeighbors);
    globalStatistics->addStdDev("GIA: Level of satisfaction messages ",
                                stat_numSatisfactionMessages);
    globalStatistics->addStdDev("GIA: Level of satisfaction max ",stat_maxLevelOfSatisfaction);
    globalStatistics->addStdDev("GIA: Level of satisfaction avg ",
                                stat_sumLevelOfSatisfaction / stat_numSatisfactionMessages);
    bootstrapList->removeBootstrapNode(thisGiaNode);
}

void Gia::forwardMessage ( GiaIDMessage msg,
bool  fromApplication 
) [protected]

Forwards a message to the next random selected node, biased random walk.

Parameters:
msg Message to forward to next node
fromApplication Marks if message is from application layer

Definition at line 872 of file Gia.cc.

Referenced by getRoute(), handleTimerEvent(), handleUDPMessage(), and processSearchMessage().

{
    if (msg->getHopCount() == 0) {
        // Max-Hopcount reached. Discard message
        if (!fromApplication)
            tokenFactory->grantToken();
        RECORD_STATS(numDropped++; bytesDropped += msg->getByteLength());
        delete msg;
    } else {
        // local delivery?
        if (msg->getDestKey() == thisGiaNode.getKey()) {
            if(!fromApplication)
                tokenFactory->grantToken();

            if(debugOutput)
                EV << "(Gia) Deliver messsage " << msg
                   << " to application at " << thisGiaNode << endl;

            OverlayCtrlInfo* overlayCtrlInfo =
                new OverlayCtrlInfo();

            overlayCtrlInfo->setHopCount(msg->getHopCount());
            overlayCtrlInfo->setSrcNode(msg->getSrcNode());
            overlayCtrlInfo->setTransportType(ROUTE_TRANSPORT);
            overlayCtrlInfo->setDestComp(TIER1_COMP); // workaround
            overlayCtrlInfo->setSrcComp(TIER1_COMP);

            msg->setControlInfo(overlayCtrlInfo);
            callDeliver(msg, msg->getDestKey());
        } else {
            // forward message to next hop

            // do we know the destination-node?
            if (neighbors->contains(msg->getDestKey())) {
                // yes, destination-Node is our neighbor
                NodeHandle targetNode = neighbors->get(msg->getDestKey());
                GiaNeighborInfo* targetInfo= neighbors->get(targetNode);

                if (targetInfo->receivedTokens == 0) {
                    // wait for free token
                    if (debugOutput)
                        EV << "(Gia) No free Node, wait for free token" << endl;

                    //bad code
                    std::string id;
                    if (!fromApplication)
                        id = "wait-for-token: " + msg->getID().toString();
                    else
                        id = "wait-for-token-fromapp: " +
                            msg->getID().toString();
                    cPacket* wait_timer = new cPacket(id.c_str());
                    wait_timer->encapsulate(msg);
                    scheduleAt(simTime() + tokenWaitTime,wait_timer);
                    return;
                } else {
                    // decrease nextHop-tokencount
                    neighbors->decreaseReceivedTokens(targetNode);
                    //targetInfo->receivedTokens = targetInfo->receivedTokens - 1;

                    // forward msg to nextHop
                    msg->setHopCount(msg->getHopCount()-1);
                    msg->setSrcNode(thisGiaNode);
                    msg->setSrcCapacity(thisGiaNode.getCapacity());
                    msg->setSrcDegree(connectionDegree);
                    if (debugOutput)
                        EV << "(Gia) Forwarding message " << msg
                           << " to neighbor " << targetNode << endl;
                    if (!fromApplication)
                        tokenFactory->grantToken();

                    stat_routeMessagesBytesSent += msg->getByteLength();
                    stat_routeMessages += 1;

                    if(msg->getHopCount() > 0)
                        RECORD_STATS(numAppDataForwarded++; bytesAppDataForwarded +=
                                     msg->getByteLength());

                    sendMessageToUDP(targetNode, msg);
                }
            } else {
                // no => pick node with at least one token and highest capacity
                if (!msgBookkeepingList->contains(msg))
                    msgBookkeepingList->addMessage(msg);
                NodeHandle nextHop = msgBookkeepingList->getNextHop(msg);
                // do we have a neighbor who send us a token?
                if(nextHop.isUnspecified()) {
                    // wait for free token
                    if (debugOutput)
                        EV << "(Gia) No free Node, wait for free token" << endl;
                    std::string id;
                    if (!fromApplication)
                        id = "wait-for-token: " + msg->getID().toString();
                    else
                        id = "wait-for-token-fromapp: " +
                            msg->getID().toString();
                    cPacket* wait_timer = new cPacket(id.c_str());
                    wait_timer->encapsulate(msg);
                    scheduleAt(simTime() + tokenWaitTime,wait_timer);
                    return;
                } else {
                    GiaNeighborInfo* nextHopInfo = neighbors->get(nextHop);
                    if(nextHopInfo == NULL) {
                        delete msg;
                        return; //???
                    }
                    // decrease nextHop-tokencount
                    neighbors->decreaseReceivedTokens(nextHop);
                    //nextHopInfo->receivedTokens--;

                    // forward msg to nextHop
                    msg->setHopCount(msg->getHopCount()-1);
                    msg->setSrcNode(thisGiaNode);
                    msg->setSrcCapacity(thisGiaNode.getCapacity());
                    msg->setSrcDegree(connectionDegree);
                    if (debugOutput)
                        EV << "(Gia) Forwarding message " << msg
                           << " to " << nextHop << endl;
                    if (!fromApplication)
                        tokenFactory->grantToken();

                    stat_routeMessagesBytesSent += msg->getByteLength();
                    stat_routeMessages += 1;

                    if(msg->getHopCount() > 0)
                        RECORD_STATS(numAppDataForwarded++; bytesAppDataForwarded +=
                                     msg->getByteLength());

                    sendMessageToUDP(nextHop, msg);
                }
            }
        }
    }
}

void Gia::forwardSearchResponseMessage ( SearchResponseMessage msg  )  [protected]

Forwards a search response message to the next node in reverse-path.

Parameters:
msg Message to forward to next node

Definition at line 828 of file Gia.cc.

Referenced by handleUDPMessage(), and sendSearchResponseMessage().

{
    if (responseMsg->getHopCount() != 0) {
        uint32_t reversePathArraySize = responseMsg->getReversePathArraySize();

        // reached node which started search?
        if (reversePathArraySize == 0) {
            deliverSearchResult(responseMsg);
        }
        // forward message to next node in reverse path list
        else {
            NodeHandle targetNode = neighbors->get
                (responseMsg->getReversePath(
                                             reversePathArraySize-1));

            if(!(targetNode.isUnspecified())) {
                responseMsg->setDestKey(targetNode.getKey());
                responseMsg->setReversePathArraySize(reversePathArraySize-1);
                for (uint32_t i=0; i<reversePathArraySize-1; i++)
                    responseMsg->setReversePath(i, responseMsg->getReversePath(i));
                responseMsg->setBitLength(responseMsg->getBitLength() - KEY_L);

                stat_routeMessagesBytesSent += responseMsg->getByteLength();
                stat_routeMessages += 1;

                if(responseMsg->getHopCount() > 0)
                    RECORD_STATS(numAppDataForwarded++; bytesAppDataForwarded +=
                                 responseMsg->getByteLength());

                sendMessageToUDP(targetNode, responseMsg);
            } else {
                EV << "(Gia) wrong reverse path in " << *responseMsg
                   << " ... deleted!" << endl;
                RECORD_STATS(numDropped++;
                             bytesDropped += responseMsg->getByteLength());
                delete responseMsg;
            }
        }
    }
    // max hopcount reached. delete message
    else
        delete responseMsg;
}

void Gia::getRoute ( const OverlayKey key,
CompType  destComp,
CompType  srcComp,
cPacket *  msg,
const std::vector< TransportAddress > &  sourceRoute = TransportAddress::UNSPECIFIED_NODES,
RoutingType  routingType = DEFAULT_ROUTING 
) [virtual]

Definition at line 1006 of file Gia.cc.

{
    if ((destComp != TIER1_COMP) || (srcComp != TIER1_COMP)) {
        throw cRuntimeError("Gia::getRoute(): Works currently "
                             "only with srcComp=destComp=TIER1_COMP!");
    }

    if (state == READY) {
        GiaRouteMessage* routeMsg = new GiaRouteMessage("ROUTE");
        routeMsg->setStatType(APP_DATA_STAT);
        routeMsg->setCommand(ROUTE);
        routeMsg->setHopCount(maxHopCount);
        routeMsg->setDestKey(key);
        routeMsg->setSrcNode(thisGiaNode);
        routeMsg->setSrcCapacity(thisGiaNode.getCapacity());
        routeMsg->setSrcDegree(connectionDegree);
        routeMsg->setOriginatorKey(thisGiaNode.getKey());
        routeMsg->setOriginatorIP(thisGiaNode.getIp());
        routeMsg->setOriginatorPort(thisGiaNode.getPort());
        routeMsg->setID(OverlayKey::random());
        routeMsg->setBitLength(GIAROUTE_L(routeMsg));
        routeMsg->encapsulate(msg);


        forwardMessage(routeMsg, true);
    } else {
        RECORD_STATS(numDropped++; bytesDropped += msg->getByteLength());
        delete msg;
    }
}

void Gia::handleAppMessage ( cMessage *  msg  )  [virtual]

Processes "timer" self-messages.

Parameters:
msg A self-message Processes non-commonAPI messages
msg non-commonAPIMessage

Reimplemented from BaseOverlay.

Definition at line 1040 of file Gia.cc.

{
    // do we receive a keylist?
    if (dynamic_cast<GIAput*>(msg) != NULL) {
        GIAput* putMsg = check_and_cast<GIAput*>(msg);
        uint32_t keyListSize = putMsg->getKeysArraySize();
        for (uint32_t k=0; k<keyListSize; k++)
            keyList.addKeyItem(putMsg->getKeys(k));

        // actualize vector in KeyListModule
        keyListModule->setKeyListVector(keyList.getVector());

        scheduleAt(simTime() + keyListDelay, sendKeyList_timer);

        delete putMsg;
    } else if (dynamic_cast<GIAsearch*>(msg) != NULL) {
        if (state == READY) {
            GIAsearch* getMsg = check_and_cast<GIAsearch*>(msg);
            SearchMessage* searchMsg = new SearchMessage("SEARCH");
            searchMsg->setCommand(SEARCH);
            searchMsg->setStatType(APP_DATA_STAT);
            searchMsg->setHopCount(maxHopCount);
            searchMsg->setDestKey(getMsg->getSearchKey());
            searchMsg->setSrcNode(thisGiaNode);
            searchMsg->setSrcCapacity(thisGiaNode.getCapacity());
            searchMsg->setSrcDegree(connectionDegree);
            searchMsg->setSearchKey(getMsg->getSearchKey());
            searchMsg->setMaxResponses(getMsg->getMaxResponses());
            searchMsg->setReversePathArraySize(0);
            searchMsg->setID(OverlayKey::random());
            searchMsg->setBitLength(SEARCH_L(searchMsg));

            processSearchMessage(searchMsg, true);

            delete getMsg;
        } else
            delete msg;
    } else {
        delete msg;
        EV << "(Gia) unkown message from app deleted!" << endl;
    }
}

void Gia::handleTimerEvent ( cMessage *  msg  ) 

Definition at line 261 of file Gia.cc.

{
    if (msg == sendToken_timer) {
        tokenFactory->grantToken();
    } else if (msg->isName("satisfaction_timer")) {
        // calculate level of satisfaction and select new neighbor candidate

        levelOfSatisfaction = calculateLevelOfSatisfaction();
        stat_numSatisfactionMessages++;
        stat_sumLevelOfSatisfaction += levelOfSatisfaction;
        if (levelOfSatisfaction > stat_maxLevelOfSatisfaction)
            stat_maxLevelOfSatisfaction = levelOfSatisfaction;

        // start again satisfaction_timer
        scheduleAt(simTime() + (maxTopAdaptionInterval *
                                           pow(topAdaptionAggressiveness,
                                               -(1 - levelOfSatisfaction))),
                   satisfaction_timer);

        // Only search a new neighbor if level of satisfaction is
        // under level of maxLevelOfSatisfaction
        if(levelOfSatisfaction < maxLevelOfSatisfaction) {
            if(knownNodes.getSize() == 0) {
                if(neighbors->getSize() == 0 && neighCand.getSize() == 0)
                    knownNodes.add(globalNodeList->getBootstrapNode()/*bootstrapList->getBootstrapNode()*/);
                else
                    return;
            }

            NodeHandle possibleNeighbor = knownNodes.getRandomCandidate();

            if(!(possibleNeighbor.isUnspecified()) &&
               thisGiaNode != possibleNeighbor &&
               !neighbors->contains(possibleNeighbor) &&
               !neighCand.contains(possibleNeighbor)) {
                // try to add new neighbor
                neighCand.add(possibleNeighbor);
                sendMessage_JOIN_REQ(possibleNeighbor);
            }
        }
    } else if (msg->isName("update_timer")) {
        // send current capacity and degree to all neighbors
        for (uint32_t i=0; i<neighbors->getSize(); i++) {
            sendMessage_UPDATE(neighbors->get(i));
        }
    } else if (msg->isName("timedoutMessages_timer")) {
        // remove timedout messages
        msgBookkeepingList->removeTimedoutMessages();
        scheduleAt(simTime() + messageTimeout,
                   timedoutMessages_timer);
    } else if (msg->isName("timedoutNeighbors_timer")) {
        // remove timedout neighbors
        neighbors->removeTimedoutNodes();
        if (neighbors->getSize() == 0) {
            changeState(INIT);
        }
        cancelEvent(timedoutNeighbors_timer);
        scheduleAt(simTime() + neighborTimeout,
                   timedoutNeighbors_timer);
    } else if (msg->isName("sendKeyList_timer")) {
        if (keyList.getSize() > 0) {
            // send keyList to all of our neighbors
            for (uint32_t i=0; i<neighbors->getSize(); i++)
                sendKeyListToNeighbor(neighbors->get(i));
        }
    } else {
        // other self-messages are notoken-self-messages
        // with an encapsulated message
        const std::string id = msg->getName();
        if (id.substr(0, 16) == std::string("wait-for-token: ")) {
                cPacket* packet = check_and_cast<cPacket*>(msg);
            cMessage* decapsulatedMessage = packet->decapsulate();
            if (dynamic_cast<GiaIDMessage*>(decapsulatedMessage) != NULL) {
                GiaIDMessage* message = check_and_cast<GiaIDMessage*>
                    (decapsulatedMessage);
                forwardMessage(message, false);
            }
        } else if (id.substr(0, 24) == std::string("wait-for-token-fromapp: ")) {
            cPacket* packet = check_and_cast<cPacket*>(msg);
            cMessage* decapsulatedMessage = packet->decapsulate();
            if (dynamic_cast<GiaIDMessage*>(decapsulatedMessage) != NULL) {
                GiaIDMessage* message = check_and_cast<GiaIDMessage*>
                    (decapsulatedMessage);
                forwardMessage(message, true);
            }
        }
        delete msg;
    }
}

void Gia::handleUDPMessage ( BaseOverlayMessage msg  )  [virtual]

Processes messages from underlay.

Parameters:
msg Message from UDP

Reimplemented from BaseOverlay.

Definition at line 351 of file Gia.cc.

{
    if(debugOutput)
        EV << "(Gia) " << thisGiaNode << " received udp message" << endl;

    cPolymorphic* ctrlInfo = msg->removeControlInfo();
    if(ctrlInfo != NULL)
        delete ctrlInfo;

    // Parse TokenMessages
    if (dynamic_cast<TokenMessage*>(msg) != NULL) {
        TokenMessage* giaMsg = check_and_cast<TokenMessage*>(msg);

        // Process TOKEN-Message
        if ((giaMsg->getCommand() == TOKEN)) {
            if(debugOutput)
                EV << "(Gia) Received Tokenmessage from "
                           << giaMsg->getSrcNode() << endl;

            //neighbors->setReceivedTokens(giaMsg->getSrcNode(), giaMsg->getDstTokenNr());
            neighbors->increaseReceivedTokens(giaMsg->getSrcNode());
            updateNeighborList(giaMsg);
        }
        delete msg;
    }

    // Process Route messages
    else if (dynamic_cast<GiaRouteMessage*>(msg) != NULL) {
        GiaRouteMessage* giaMsg = check_and_cast<GiaRouteMessage*>(msg);
        GiaNode oppositeNode(giaMsg->getSrcNode(), giaMsg->getSrcCapacity(),
                             giaMsg->getSrcDegree());

        if((giaMsg->getCommand() == ROUTE)) {
            if(debugOutput)
                EV << "(Gia) Received ROUTE::IND from " << oppositeNode << endl;

            if(state == READY) {
                //neighbors->decreaseReceivedTokens(giaMsg->getSrcNode());
                updateNeighborList(giaMsg);
                forwardMessage(giaMsg, false);
            }
        }
    }

    // Process KeyList-Messages
    else if (dynamic_cast<KeyListMessage*>(msg) != NULL) {
        KeyListMessage* giaMsg = check_and_cast<KeyListMessage*>(msg);
        GiaNode oppositeNode(giaMsg->getSrcNode(), giaMsg->getSrcCapacity(),
                             giaMsg->getSrcDegree());

        if (giaMsg->getCommand() == KEYLIST) {
            if (debugOutput)
                EV << "(Gia) " << thisGiaNode
                   << " received KEYLIST:IND message" << endl;
            // update KeyList in neighborList
            uint32_t keyListSize = giaMsg->getKeysArraySize();
            GiaKeyList neighborKeyList;
            for (uint32_t k = 0; k < keyListSize; k++)
                neighborKeyList.addKeyItem(giaMsg->getKeys(k));
            neighbors->setNeighborKeyList(giaMsg->getSrcNode(), neighborKeyList);
        }
        delete giaMsg;
    }

    // Process Search-Messages
    else if (dynamic_cast<SearchMessage*>(msg) != NULL) {
        SearchMessage* giaMsg = check_and_cast<SearchMessage*>(msg);
        GiaNode oppositeNode(giaMsg->getSrcNode(), giaMsg->getSrcCapacity(),
                             giaMsg->getSrcDegree());

        //neighbors->decreaseSentTokens(giaMsg->getSrcNode());
        updateNeighborList(giaMsg);
        processSearchMessage(giaMsg, false);
        // } else {
        //             EV << "(Gia) Message " << msg << " dropped!" << endl;
        //             RECORD_STATS(numDropped++; bytesDropped += msg->getByteLength());
        //             delete msg;
        //         }
    }

    // Process Search-Response-Messages
    else if (dynamic_cast<SearchResponseMessage*>(msg) != NULL) {
        SearchResponseMessage* responseMsg =
            check_and_cast<SearchResponseMessage*>(msg);
        forwardSearchResponseMessage(responseMsg);
    }

    // Process Gia messages
    else if (dynamic_cast<GiaMessage*>(msg) != NULL) {
        GiaMessage* giaMsg = check_and_cast<GiaMessage*>(msg);

        //assert(giaMsg->getSrcNode().moduleId != -1);
        GiaNode oppositeNode(giaMsg->getSrcNode(), giaMsg->getSrcCapacity(),
                             giaMsg->getSrcDegree());

        if (debugOutput)
            EV << "(Gia) " << thisGiaNode << " received GIA- message from "
               << oppositeNode << endl;
        updateNeighborList(giaMsg);

        // Process JOIN:REQ messages
        if (giaMsg->getCommand() == JOIN_REQUEST) {
            if (debugOutput)
                EV << "(Gia) " << thisGiaNode
                   << " received JOIN:REQ message" << endl;
            if (acceptNode(oppositeNode, giaMsg->getSrcDegree())) {
                neighCand.add(oppositeNode);
                sendMessage_JOIN_RSP(oppositeNode);
            } else {
                if (debugOutput)
                    EV << "(Gia) " << thisGiaNode << " denies node "
                       << oppositeNode << endl;
                sendMessage_JOIN_DNY(oppositeNode);
            }
        }

        // Process JOIN:RSP messages
        else if (giaMsg->getCommand() == JOIN_RESPONSE) {
            if(debugOutput)
                EV << "(Gia) " << thisGiaNode << " received JOIN:RSP message"
                   << endl;
            if(neighCand.contains(oppositeNode)) {
                neighCand.remove(oppositeNode);
                if(acceptNode(oppositeNode, giaMsg->getSrcDegree())) {
                    addNeighbor(oppositeNode, giaMsg->getSrcDegree());

                    GiaNeighborMessage* msg =
                        check_and_cast<GiaNeighborMessage*>(giaMsg);
                    for(uint32_t i = 0; i < msg->getNeighborsArraySize(); i++) {
                        GiaNode temp = msg->getNeighbors(i);
                        if(temp != thisGiaNode && temp != oppositeNode)
                            knownNodes.add(temp);
                    }

                    sendMessage_JOIN_ACK(oppositeNode);
                } else {
                    if (debugOutput)
                        EV << "(Gia) " << thisGiaNode << " denies node "
                           << oppositeNode << endl;
                    sendMessage_JOIN_DNY(oppositeNode);
                }
            }
        }

        // Process JOIN:ACK messages
        else if (giaMsg->getCommand() == JOIN_ACK) {
            if (debugOutput)
                EV << "(Gia) " << thisGiaNode << " received JOIN:ACK message"
                   << endl;
            if (neighCand.contains(oppositeNode) &&
                neighbors->getSize() < maxNeighbors) {
                neighCand.remove(oppositeNode);
                addNeighbor(oppositeNode, giaMsg->getSrcDegree());

                GiaNeighborMessage* msg =
                    check_and_cast<GiaNeighborMessage*>(giaMsg);

                for(uint32_t i = 0; i < msg->getNeighborsArraySize(); i++) {
                    GiaNode temp = msg->getNeighbors(i);
                    if(temp != thisGiaNode && temp != oppositeNode)
                        knownNodes.add(msg->getNeighbors(i));
                }
            } else {
                sendMessage_DISCONNECT(oppositeNode);
            }

        }

        // Process JOIN:DNY messages
        else if (giaMsg->getCommand() == JOIN_DENY) {
            if (debugOutput)
                EV << "(Gia) " << thisGiaNode << " received JOIN:DNY message"
                   << endl;

            if (neighCand.contains(oppositeNode))
                neighCand.remove(oppositeNode);
            knownNodes.remove(oppositeNode);

        }


        // Process DISCONNECT-Message
        else if (giaMsg->getCommand() == DISCONNECT) {
            if (debugOutput)
                EV << "(Gia) " << thisGiaNode << " received DISCONNECT:IND message" << endl;
            removeNeighbor(giaMsg->getSrcNode());
        }

        // Process UPDATE-Message
        else if (giaMsg->getCommand() == UPDATE) {
            if (debugOutput)
                EV << "(Gia) " << thisGiaNode << " received UPDATE:IND message"
                   << endl;

            neighbors->setConnectionDegree(giaMsg->getSrcNode(),
                                           giaMsg->getSrcDegree());
            //neighbors->setCapacity(giaMsg->getSrcNode(),
            //giaMsg->getSrcCapacity());
        } else {
            // Show unknown gia-messages
            if (debugOutput) {
                EV << "(Gia) NODE: "<< thisGiaNode << endl
                   << "       Command: " << giaMsg->getCommand() << endl
                   << "       HopCount: " << giaMsg->getHopCount() << endl
                   << "       SrcKey: " << giaMsg->getSrcNode().getKey() << endl
                   << "       SrcIP: " << giaMsg->getSrcNode().getKey() << endl
                   << "       SrcPort: " << giaMsg->getSrcNode().getPort() << endl
                   << "       SrcCapacity: " << giaMsg->getSrcCapacity() << endl
                   << "       SrcDegree: " << giaMsg->getSrcDegree() << endl;

                RECORD_STATS(numDropped++;bytesDropped += giaMsg->getByteLength());
            }
        }
        delete giaMsg;
    } else // PROCESS other messages than GiaMessages
        delete msg; // delete them all
}

void Gia::initializeOverlay ( int  stage  )  [virtual]

initializes base class-attributes

Parameters:
stage the init stage

Reimplemented from BaseOverlay.

Definition at line 39 of file Gia.cc.

{
    // wait until IPAddressResolver initialized all interfaces and assigns addresses
    if(stage != MIN_STAGE_OVERLAY)
        return;

    // Get parameters from omnetpp.ini
    maxNeighbors = par("maxNeighbors");
    minNeighbors = par("minNeighbors");
    maxTopAdaptionInterval = par("maxTopAdaptionInterval");
    topAdaptionAggressiveness = par("topAdaptionAggressiveness");
    maxLevelOfSatisfaction = par("maxLevelOfSatisfaction");
    updateDelay = par("updateDelay");
    maxHopCount = par("maxHopCount"); //obsolete
    messageTimeout = par("messageTimeout");
    neighborTimeout = par("neighborTimeout");
    sendTokenTimeout = par("sendTokenTimeout");
    tokenWaitTime = par("tokenWaitTime");
    keyListDelay = par("keyListDelay");
    outputNodeDetails = par("outputNodeDetails");
    optimizeReversePath = par("optimizeReversePath");

    // get references on necessary modules
    keyListModule = check_and_cast<GiaKeyListModule*>
        (getParentModule()->getSubmodule("keyListModule"));
    neighbors = check_and_cast<GiaNeighbors*>
        (getParentModule()->getSubmodule("neighbors"));
    tokenFactory = check_and_cast<GiaTokenFactory*>
        (getParentModule()->getSubmodule("tokenFactory"));

    msgBookkeepingList = new GiaMessageBookkeeping(neighbors, messageTimeout);

    // clear neighbor candidate list
    neighCand.clear();
    knownNodes.clear();

    WATCH(thisGiaNode);
    WATCH(bootstrapNode);
    WATCH(levelOfSatisfaction);

    // self-messages
    satisfaction_timer = new cMessage("satisfaction_timer");
    update_timer = new cMessage("update_timer");
    timedoutMessages_timer = new cMessage("timedoutMessages_timer");
    timedoutNeighbors_timer = new cMessage("timedoutNeighbors_timer");
    sendKeyList_timer = new cMessage("sendKeyList_timer");
    sendToken_timer = new cMessage("sendToken_timer");

    // statistics
    stat_joinCount = 0;
    stat_joinBytesSent = 0;
    stat_joinREQ = 0;
    stat_joinREQBytesSent = 0;
    stat_joinRSP = 0;
    stat_joinRSPBytesSent = 0;
    stat_joinACK = 0;
    stat_joinACKBytesSent = 0;
    stat_joinDNY = 0;
    stat_joinDNYBytesSent = 0;
    stat_disconnectMessages = 0;
    stat_disconnectMessagesBytesSent = 0;
    stat_updateMessages = 0;
    stat_updateMessagesBytesSent = 0;
    stat_tokenMessages = 0;
    stat_tokenMessagesBytesSent = 0;
    stat_keyListMessages = 0;
    stat_keyListMessagesBytesSent = 0;
    stat_routeMessages = 0;
    stat_routeMessagesBytesSent = 0;
    stat_maxNeighbors = 0;
    stat_addedNeighbors = 0;
    stat_removedNeighbors = 0;
    stat_numSatisfactionMessages = 0;
    stat_sumLevelOfSatisfaction = 0.0;
    stat_maxLevelOfSatisfaction = 0.0;
}

void Gia::joinOverlay (  )  [protected, virtual]

Join the overlay with a given nodeID in thisNode.key.

Join the overlay with a given nodeID in thisNode.key. This method may be called by an application to join the overlay with a specific nodeID. It is also called if the node's IP address changes.

Reimplemented from BaseOverlay.

Definition at line 116 of file Gia.cc.

void Gia::processSearchMessage ( SearchMessage msg,
bool  fromApplication 
) [protected]

Processes search message msg.

Generates Search_Response_Messages

Parameters:
msg Search message
fromApplication Marks if message is from application layer

Definition at line 1147 of file Gia.cc.

Referenced by handleAppMessage(), and handleUDPMessage().

{
    OverlayKey searchKey = msg->getSearchKey();

    if (keyList.contains(searchKey)) {
        // this node contains search key
        sendSearchResponseMessage(thisGiaNode, msg);
    }

    // check if neighbors contain search key
    for (uint32_t i = 0; i < neighbors->getSize(); i++) {
        GiaKeyList* keyList = neighbors->getNeighborKeyList(neighbors->get(i));
        if (keyList->contains(searchKey))
            sendSearchResponseMessage(neighbors->get(i), msg);
    }

    // forward search-message to next hop
    if (msg->getMaxResponses() > 0) {
        // actualize reverse path
        uint32_t reversePathSize = msg->getReversePathArraySize();

        if (optimizeReversePath)
            for (uint32_t i=0; i<reversePathSize; i++) {
                if (msg->getReversePath(i) == thisGiaNode.getKey()) {
                    // Our node already in ReversePath.
                    // Delete successor nodes from ReversePath
                    msg->setBitLength(msg->getBitLength() - (reversePathSize - i)*KEY_L);
                    reversePathSize = i; // set new array size
                    break;
                }
            }

        msg->setReversePathArraySize(reversePathSize+1);
        msg->setReversePath(reversePathSize, thisGiaNode.getKey());
        msg->setBitLength(msg->getBitLength() + KEY_L);

        forwardMessage(msg, fromApplication);
    } else {
        tokenFactory->grantToken();
        delete msg;
    }
}

void Gia::removeNeighbor ( const GiaNode newNode  )  [protected]

Removes newNode from our NeighborList.

Parameters:
newNode NodeHandle of the node to remove from neighbors

Definition at line 621 of file Gia.cc.

Referenced by handleUDPMessage().

{
    stat_removedNeighbors++;

    if (debugOutput)
        EV << "(Gia) " << thisGiaNode << " removes " << node
           << " from neighborlist." << endl;
    neighbors->remove(node);

    connectionDegree = neighbors->getSize();

    if (neighbors->getSize() == 0) {
        changeState(INIT);
    }

    deleteOverlayNeighborArrow(node);
    updateTooltip();

    cancelEvent(update_timer);
    scheduleAt(simTime() + updateDelay, update_timer);
}

void Gia::sendKeyListToNeighbor ( const NodeHandle dst  )  [protected]

Sends KeyList to node dst.

Parameters:
dst,: Destination

Definition at line 780 of file Gia.cc.

Referenced by addNeighbor(), and handleTimerEvent().

{
    // send KEYLIST:IND message
    KeyListMessage* msg = new KeyListMessage("KEYLIST");
    msg->setCommand(KEYLIST);
    msg->setSrcNode(thisGiaNode);
    msg->setSrcCapacity(thisGiaNode.getCapacity());
    msg->setSrcDegree(connectionDegree);

    msg->setKeysArraySize(keyList.getSize());
    for (uint32_t i=0; i<keyList.getSize(); i++)
        msg->setKeys(i, keyList.get(i));

    msg->setBitLength(KEYLIST_L(msg));

    stat_keyListMessagesBytesSent += msg->getByteLength();
    stat_keyListMessages += 1;

    sendMessageToUDP(dst, msg);
}

void Gia::sendMessage_DISCONNECT ( const NodeHandle dst  )  [protected]

Sends DISCONNECT_Message from node src to node dst.

Parameters:
dst,: Destination

Definition at line 748 of file Gia.cc.

Referenced by acceptNode(), and handleUDPMessage().

{
    // send DISCONNECT:IND message
    GiaMessage* msg = new GiaMessage("DISCONNECT");
    msg->setCommand(DISCONNECT);
    msg->setSrcNode(thisGiaNode);
    msg->setSrcCapacity(thisGiaNode.getCapacity());
    msg->setSrcDegree(connectionDegree);
    msg->setBitLength(GIA_L(msg));

    stat_disconnectMessagesBytesSent += msg->getByteLength();
    stat_disconnectMessages += 1;

    sendMessageToUDP(dst, msg);
}

void Gia::sendMessage_JOIN_ACK ( const NodeHandle dst  )  [protected]

Sends JOIN_ACK_Message from node src to node dst.

Parameters:
dst,: Destination

Definition at line 706 of file Gia.cc.

Referenced by handleUDPMessage().

{
    // send JOIN:ACK message
    GiaNeighborMessage* msg = new GiaNeighborMessage("JOIN_ACK");
    msg->setCommand(JOIN_ACK);
    msg->setSrcNode(thisGiaNode);
    msg->setSrcCapacity(thisGiaNode.getCapacity());
    msg->setSrcDegree(connectionDegree);

    msg->setNeighborsArraySize(neighbors->getSize());
    //TODO: add parameter maxSendNeighbors
    for(uint32_t i = 0; i < neighbors->getSize(); i++)
        msg->setNeighbors(i, neighbors->get(i));

    msg->setBitLength(GIANEIGHBOR_L(msg));

    stat_joinCount += 1;
    stat_joinBytesSent += msg->getByteLength();
    stat_joinACK += 1;
    stat_joinACKBytesSent += msg->getByteLength();

    sendMessageToUDP(dst, msg);
}

void Gia::sendMessage_JOIN_DNY ( const NodeHandle dst  )  [protected]

Sends JOIN_DNY_Message from node src to node dst.

Parameters:
dst,: Destination

Definition at line 730 of file Gia.cc.

Referenced by handleUDPMessage().

{
    // send JOIN:DNY message
    GiaMessage* msg = new GiaMessage("JOIN_DENY");
    msg->setCommand(JOIN_DENY);
    msg->setSrcNode(thisGiaNode);
    msg->setSrcCapacity(thisGiaNode.getCapacity());
    msg->setSrcDegree(connectionDegree);
    msg->setBitLength(GIA_L(msg));

    stat_joinCount += 1;
    stat_joinBytesSent += msg->getByteLength();
    stat_joinDNY += 1;
    stat_joinDNYBytesSent += msg->getByteLength();

    sendMessageToUDP(dst, msg);
}

void Gia::sendMessage_JOIN_REQ ( const NodeHandle dst  )  [protected]

Sends JOIN_REQ_Message from node src to node dst.

Parameters:
dst,: Destination

Definition at line 664 of file Gia.cc.

Referenced by handleTimerEvent().

{
    // send JOIN:REQ message
    GiaMessage* msg = new GiaMessage("JOIN_REQ");
    msg->setCommand(JOIN_REQUEST);
    msg->setSrcNode(thisGiaNode);
    msg->setSrcCapacity(thisGiaNode.getCapacity());
    msg->setSrcDegree(connectionDegree);
    msg->setBitLength(GIA_L(msg));

    stat_joinCount += 1;
    stat_joinBytesSent += msg->getByteLength();
    stat_joinREQ += 1;
    stat_joinREQBytesSent += msg->getByteLength();

    sendMessageToUDP(dst, msg);
}

void Gia::sendMessage_JOIN_RSP ( const NodeHandle dst  )  [protected]

Sends JOIN_RSP_Message from node src to node dst.

Parameters:
dst,: Destination

Definition at line 682 of file Gia.cc.

Referenced by handleUDPMessage().

{
    // send JOIN:RSP message
    GiaNeighborMessage* msg = new GiaNeighborMessage("JOIN_RSP");
    msg->setCommand(JOIN_RESPONSE);
    msg->setSrcNode(thisGiaNode);
    msg->setSrcCapacity(thisGiaNode.getCapacity());
    msg->setSrcDegree(connectionDegree);

    msg->setNeighborsArraySize(neighbors->getSize());
    //TODO: add parameter maxSendNeighbors
    for(uint32_t i = 0; i < neighbors->getSize(); i++)
        msg->setNeighbors(i, neighbors->get(i));

    msg->setBitLength(GIANEIGHBOR_L(msg));

    stat_joinCount += 1;
    stat_joinBytesSent += msg->getByteLength();
    stat_joinRSP += 1;
    stat_joinRSPBytesSent += msg->getByteLength();

    sendMessageToUDP(dst, msg);
}

void Gia::sendMessage_UPDATE ( const NodeHandle dst  )  [protected]

Sends UPDATE_Message from node src to node dst.

Parameters:
dst,: Destination

Definition at line 764 of file Gia.cc.

Referenced by handleTimerEvent().

{
    // send UPDATE:IND message
    GiaMessage* msg = new GiaMessage("UPDATE");
    msg->setCommand(UPDATE);
    msg->setSrcNode(thisGiaNode);
    msg->setSrcCapacity(thisGiaNode.getCapacity());
    msg->setSrcDegree(connectionDegree);
    msg->setBitLength(GIA_L(msg));

    stat_updateMessagesBytesSent += msg->getByteLength();
    stat_updateMessages += 1;

    sendMessageToUDP(dst, msg);
}

void Gia::sendSearchResponseMessage ( const GiaNode srcNode,
SearchMessage msg 
) [protected]

Sends a response message to a received search query.

Parameters:
srcNode Node which contains the searched key
msg SearchMessage

Definition at line 1084 of file Gia.cc.

Referenced by processSearchMessage().

{
    // does SearchMessage->foundNode[] already contain this node
    uint32_t foundNodeArraySize = msg->getFoundNodeArraySize();
    bool containsNode = false;
    for (uint32_t i=0; i<foundNodeArraySize; i++)
        if (srcNode.getKey() == msg->getFoundNode(i))
            containsNode = true;

    if (!containsNode && msg->getMaxResponses() > 0) {
        // add this node to SearchMessage->foundNode[]
        msg->setFoundNodeArraySize(foundNodeArraySize+1);
        msg->setFoundNode(foundNodeArraySize, srcNode.getKey());

        // decrease SearchMessage->maxResponses
        msg->setMaxResponses(msg->getMaxResponses()-1);

        // get first node in reverse-path
        uint32_t reversePathArraySize = msg->getReversePathArraySize();

        if (reversePathArraySize == 0) {
            // we have the key
            // deliver response to application
            SearchResponseMessage* responseMsg =
                new SearchResponseMessage("ANSWER");
            responseMsg->setCommand(ANSWER);
            responseMsg->setStatType(APP_DATA_STAT);
            responseMsg->setHopCount(maxHopCount);
            responseMsg->setSrcNode(thisGiaNode);
            responseMsg->setSrcCapacity(thisGiaNode.getCapacity());
            responseMsg->setSrcDegree(connectionDegree);
            responseMsg->setSearchKey(msg->getSearchKey());
            responseMsg->setFoundNode(srcNode);
            responseMsg->setID(OverlayKey::random());
            responseMsg->setSearchHopCount(0);

            responseMsg->setBitLength(SEARCHRESPONSE_L(responseMsg));

            deliverSearchResult(responseMsg);
        } else {
            uint32_t reversePathArraySize(msg->getReversePathArraySize());
            SearchResponseMessage* responseMsg =
                new SearchResponseMessage("ANSWER");
            responseMsg->setCommand(ANSWER);
            responseMsg->setHopCount(maxHopCount);
            responseMsg->setSrcNode(srcNode);
            responseMsg->setSrcCapacity(srcNode.getCapacity());
            responseMsg->setSrcDegree(connectionDegree);
            responseMsg->setSearchKey(msg->getSearchKey());
            responseMsg->setFoundNode(srcNode);
            responseMsg->setReversePathArraySize(reversePathArraySize);
            for (uint32_t i=0; i<reversePathArraySize; i++)
                responseMsg->setReversePath(i, msg->getReversePath(i));
            responseMsg->setID(OverlayKey::random());
            responseMsg->setSearchHopCount(reversePathArraySize);
            responseMsg->setBitLength(SEARCHRESPONSE_L(responseMsg));

            forwardSearchResponseMessage(responseMsg);
        }
    }
}

void Gia::sendToken ( const GiaNode dst  ) 

Definition at line 801 of file Gia.cc.

Referenced by GiaTokenFactory::grantToken().

{
    TokenMessage* tokenMsg = new TokenMessage("TOKEN");
    tokenMsg->setCommand(TOKEN);
    tokenMsg->setHopCount(maxHopCount);
    tokenMsg->setSrcNode(thisGiaNode);
    tokenMsg->setSrcCapacity(thisGiaNode.getCapacity());
    tokenMsg->setSrcDegree(connectionDegree);
    tokenMsg->setSrcTokenNr(0/*dst.getReceivedTokens()*/);//???
    tokenMsg->setDstTokenNr(/*dst.getSentTokens()+*/1);
    tokenMsg->setBitLength(TOKEN_L(tokenMsg));

    stat_tokenMessagesBytesSent += tokenMsg->getByteLength();
    stat_tokenMessages += 1;

    sendMessageToUDP(dst, tokenMsg);
}

void Gia::updateNeighborList ( GiaMessage msg  )  [protected]

Updates neighborlist with new capacity and connectiondegree informations from received message msg.

Parameters:
msg Received message

Definition at line 819 of file Gia.cc.

Referenced by handleUDPMessage().

{
    if(neighbors->contains(msg->getSrcNode().getKey())) {
        neighbors->setConnectionDegree(msg->getSrcNode(),msg->getSrcDegree());
        //neighbors->setCapacity(msg->getSrcNode(), msg->getSrcCapacity());
        neighbors->updateTimestamp(msg->getSrcNode());
    }
}

void Gia::updateTooltip (  ) 

Marks nodes if they are ready.

Definition at line 234 of file Gia.cc.

Referenced by addNeighbor(), changeState(), and removeNeighbor().

{
    if (ev.isGUI()) {
//        if (state == READY) {
//            getParentModule()->getParentModule()->getDisplayString().
//                setTagArg("i2", 1, "");
//            getDisplayString().setTagArg("i", 1, "");
//        } else {
//            getParentModule()->getParentModule()->getDisplayString().
//                setTagArg("i2", 1, "red");
//            getDisplayString().setTagArg("i", 1, "red");
//        }

        std::stringstream ttString;

        // show our predecessor and successor in tooltip
        ttString << thisNode << "\n# Neighbors: "
                 << neighbors->getSize();

        getParentModule()->getParentModule()->getDisplayString().
            setTagArg("tt", 0, ttString.str().c_str());
        getParentModule()->getDisplayString().
            setTagArg("tt", 0, ttString.str().c_str());
        getDisplayString().setTagArg("tt", 0, ttString.str().c_str());
    }
}


Member Data Documentation

next possible neighbor candidate

Definition at line 134 of file Gia.h.

Referenced by changeState(), initializeOverlay(), and joinOverlay().

GiaKeyList Gia::keyList [protected]

key list of this node

Definition at line 181 of file Gia.h.

Referenced by addNeighbor(), handleAppMessage(), handleTimerEvent(), processSearchMessage(), and sendKeyListToNeighbor().

double Gia::keyListDelay [protected]

delay to send the keylist to our neighbors

Definition at line 123 of file Gia.h.

Referenced by handleAppMessage(), and initializeOverlay().

pointer to KeyListModule

Definition at line 174 of file Gia.h.

Referenced by handleAppMessage(), and initializeOverlay().

list of known nodes in the overlay

Definition at line 180 of file Gia.h.

Referenced by changeState(), handleTimerEvent(), handleUDPMessage(), and initializeOverlay().

double Gia::levelOfSatisfaction [protected]

current level of statisfaction

Definition at line 127 of file Gia.h.

Referenced by calculateLevelOfSatisfaction(), handleTimerEvent(), and initializeOverlay().

uint32_t Gia::maxHopCount [protected]

maximum time to live for sent messages

Definition at line 118 of file Gia.h.

Referenced by changeState(), getRoute(), handleAppMessage(), initializeOverlay(), sendSearchResponseMessage(), and sendToken().

double Gia::maxLevelOfSatisfaction [protected]

maximum level of satisfaction

Definition at line 116 of file Gia.h.

Referenced by handleTimerEvent(), and initializeOverlay().

uint32_t Gia::maxNeighbors [protected]

maximum number of neighbors

Definition at line 112 of file Gia.h.

Referenced by acceptNode(), addNeighbor(), calculateLevelOfSatisfaction(), handleUDPMessage(), and initializeOverlay().

uint32_t Gia::maxTopAdaptionInterval [protected]

maximum topology adaption interval

Definition at line 114 of file Gia.h.

Referenced by handleTimerEvent(), and initializeOverlay().

uint32_t Gia::messageTimeout [protected]

timeout for messages

Definition at line 119 of file Gia.h.

Referenced by changeState(), handleTimerEvent(), and initializeOverlay().

uint32_t Gia::minNeighbors [protected]

minimum number of neighbors

Definition at line 113 of file Gia.h.

Referenced by calculateLevelOfSatisfaction(), and initializeOverlay().

pointer to a message bookkeeping list

Definition at line 135 of file Gia.h.

Referenced by forwardMessage(), handleTimerEvent(), initializeOverlay(), and ~Gia().

uint32_t Gia::neighborTimeout [protected]

timeout for neighbors

Definition at line 120 of file Gia.h.

Referenced by changeState(), handleTimerEvent(), and initializeOverlay().

list of all neighbor candidates

Definition at line 179 of file Gia.h.

Referenced by handleTimerEvent(), handleUDPMessage(), and initializeOverlay().

bool Gia::optimizeReversePath [protected]

use optimized reverse path?

Definition at line 125 of file Gia.h.

Referenced by initializeOverlay(), and processSearchMessage().

bool Gia::outputNodeDetails [protected]

output of node details? (on std::cout)

Definition at line 124 of file Gia.h.

Referenced by changeState(), and initializeOverlay().

unsigned int Gia::receivedTokens [protected]

Definition at line 129 of file Gia.h.

Referenced by changeState().

cMessage* Gia::satisfaction_timer [protected]

timer for satisfaction self-message

Definition at line 166 of file Gia.h.

Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Gia().

cMessage* Gia::sendKeyList_timer [protected]

timer for send keylist

Definition at line 170 of file Gia.h.

Referenced by handleAppMessage(), initializeOverlay(), and ~Gia().

cMessage* Gia::sendToken_timer [protected]

timer for send token

Definition at line 171 of file Gia.h.

Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Gia().

uint32_t Gia::sendTokenTimeout [protected]

timeout for tokens

Definition at line 121 of file Gia.h.

Referenced by changeState(), and initializeOverlay().

unsigned int Gia::sentTokens [protected]

Definition at line 130 of file Gia.h.

Referenced by changeState().

uint32_t Gia::stat_addedNeighbors [protected]

number of added neighbors during life cycle of this node

Definition at line 159 of file Gia.h.

Referenced by addNeighbor(), finishOverlay(), and initializeOverlay().

uint32_t Gia::stat_disconnectMessages [protected]

number of sent disconnect messages

Definition at line 148 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_DISCONNECT().

number of sent bytes of disconnect messages

Definition at line 149 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_DISCONNECT().

uint32_t Gia::stat_joinACK [protected]

number of sent join acknowledge messages

Definition at line 144 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_ACK().

uint32_t Gia::stat_joinACKBytesSent [protected]

number of sent bytes of join acknowledge messages

Definition at line 145 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_ACK().

uint32_t Gia::stat_joinBytesSent [protected]

number of sent bytes of join messages

Definition at line 139 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), sendMessage_JOIN_ACK(), sendMessage_JOIN_DNY(), sendMessage_JOIN_REQ(), and sendMessage_JOIN_RSP().

uint32_t Gia::stat_joinCount [protected]

number of sent join messages

Definition at line 138 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), sendMessage_JOIN_ACK(), sendMessage_JOIN_DNY(), sendMessage_JOIN_REQ(), and sendMessage_JOIN_RSP().

uint32_t Gia::stat_joinDNY [protected]

number of sent join deny messages

Definition at line 146 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_DNY().

uint32_t Gia::stat_joinDNYBytesSent [protected]

number of sent bytes of join deny messages

Definition at line 147 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_DNY().

uint32_t Gia::stat_joinREQ [protected]

number of sent join request messages

Definition at line 140 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_REQ().

uint32_t Gia::stat_joinREQBytesSent [protected]

number of sent bytes of join request messages

Definition at line 141 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_REQ().

uint32_t Gia::stat_joinRSP [protected]

number of sent join response messages

Definition at line 142 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_RSP().

uint32_t Gia::stat_joinRSPBytesSent [protected]

number of sent bytes of join response messages

Definition at line 143 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_JOIN_RSP().

uint32_t Gia::stat_keyListMessages [protected]

number of sent keylist messages

Definition at line 154 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendKeyListToNeighbor().

uint32_t Gia::stat_keyListMessagesBytesSent [protected]

number of sent bytes of keylist messages

Definition at line 155 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendKeyListToNeighbor().

maximum level of satisfaction

Definition at line 163 of file Gia.h.

Referenced by finishOverlay(), handleTimerEvent(), and initializeOverlay().

uint32_t Gia::stat_maxNeighbors [protected]

maximum number of neighbors

Definition at line 158 of file Gia.h.

Referenced by addNeighbor(), finishOverlay(), and initializeOverlay().

uint32_t Gia::stat_numSatisfactionMessages [protected]

number of satisfaction self-messages

Definition at line 161 of file Gia.h.

Referenced by finishOverlay(), handleTimerEvent(), and initializeOverlay().

uint32_t Gia::stat_removedNeighbors [protected]

number of removed neighbors during life cycle of this node

Definition at line 160 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and removeNeighbor().

uint32_t Gia::stat_routeMessages [protected]

number of sent route messages

Definition at line 156 of file Gia.h.

Referenced by finishOverlay(), forwardMessage(), forwardSearchResponseMessage(), and initializeOverlay().

uint32_t Gia::stat_routeMessagesBytesSent [protected]

number of sent bytes of route messages

Definition at line 157 of file Gia.h.

Referenced by finishOverlay(), forwardMessage(), forwardSearchResponseMessage(), and initializeOverlay().

sum of level of satisfaction

Definition at line 162 of file Gia.h.

Referenced by finishOverlay(), handleTimerEvent(), and initializeOverlay().

uint32_t Gia::stat_tokenMessages [protected]

number of sent token messages

Definition at line 152 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendToken().

uint32_t Gia::stat_tokenMessagesBytesSent [protected]

number of sent bytes of token messages

Definition at line 153 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendToken().

uint32_t Gia::stat_updateMessages [protected]

number of sent update messages

Definition at line 150 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_UPDATE().

uint32_t Gia::stat_updateMessagesBytesSent [protected]

number of sent bytes of update messages

Definition at line 151 of file Gia.h.

Referenced by finishOverlay(), initializeOverlay(), and sendMessage_UPDATE().

cMessage* Gia::timedoutMessages_timer [protected]

timer for message timeout

Definition at line 168 of file Gia.h.

Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Gia().

cMessage* Gia::timedoutNeighbors_timer [protected]

timer for neighbors timeout

Definition at line 169 of file Gia.h.

Referenced by changeState(), handleTimerEvent(), initializeOverlay(), and ~Gia().

pointer to TokenFactory

Definition at line 176 of file Gia.h.

Referenced by changeState(), forwardMessage(), handleTimerEvent(), initializeOverlay(), and processSearchMessage().

uint32_t Gia::tokenWaitTime [protected]

delay to send a new token

Definition at line 122 of file Gia.h.

Referenced by forwardMessage(), and initializeOverlay().

uint32_t Gia::topAdaptionAggressiveness [protected]

the topology adaption aggressiveness

Definition at line 115 of file Gia.h.

Referenced by handleTimerEvent(), and initializeOverlay().

cMessage* Gia::update_timer [protected]

timer for update self-message

Definition at line 167 of file Gia.h.

Referenced by addNeighbor(), initializeOverlay(), removeNeighbor(), and ~Gia().

double Gia::updateDelay [protected]

time between to update messages (in ms)

Definition at line 117 of file Gia.h.

Referenced by addNeighbor(), initializeOverlay(), and removeNeighbor().


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