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

Vast Class Reference

Voronoi class. More...

#include <Vast.h>

Inheritance diagram for Vast:
BaseOverlay BaseRpc BaseTcpSupport TopologyVis RpcListener

List of all members.

Public Member Functions

 ~Vast ()
void initializeOverlay (int stage)
 Initializes derived-class-attributes.
void finishOverlay ()
 collects statistical data in derived class
void handleUDPMessage (BaseOverlayMessage *msg)
 Processes messages from underlay.
void handleTimerEvent (cMessage *msg)
void handleAppMessage (cMessage *msg)
 Processes "timer" self-messages.
void handleNodeLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed.
void handleNodeGracefulLeaveNotification ()
 This method gets call **.gracefulLeaveDelay seconds before it is killed if this node is among the gracefulLeaveProbability nodes.
double getAOI ()
Vector2D getPosition ()
NodeHandle getHandle ()
double getAreaDimension ()

Public Attributes

SiteMap Sites
Site thisSite

Protected Member Functions

void addNode (Vector2D p, NodeHandle node, int NeighborCount=0)
void addNodeToStock (NodeHandle node)
void removeNode (NodeHandle node)
void buildVoronoi ()
void buildVoronoi (Vector2D old_pos, Vector2D new_pos, NodeHandle enclosingCheck=NodeHandle::UNSPECIFIED_NODE)
void removeNeighbors ()
void sendToApp (cMessage *msg)
void sendMessage (VastMessage *vastMsg, NodeHandle destAddr)
void setBootstrapedIcon ()
void changeState (int state)
void processJoinTimer ()
void processPingTimer ()
void processSecTimer ()
void processCheckCriticalTimer ()
void processDiscoveryTimer ()
void handleJoin (GameAPIPositionMessage *sgcMsg)
void handleMove (GameAPIPositionMessage *sgcMsg)
void handleEvent (GameAPIMessage *msg)
void handleJoinRequest (VastMessage *vastMsg)
void handleJoinAcknowledge (VastListMessage *vastListMsg)
void handleNodeMove (VastMoveMessage *vastMoveMsg)
void handleNewNeighbors (VastListMessage *vastListMsg)
void handleNodeLeave (VastListMessage *vastListMsg)
void handleEnclosingNeighborsRequest (VastMessage *vastMsg)
void handleBackupNeighbors (VastListMessage *vastListMsg)
void handlePing (VastMessage *vastMsg)
void handlePong (VastMessage *vastMsg)
void handleDiscardNode (VastDiscardMessage *vastMsg)
void sendDiscardNode (VastMessage *vastMsg)
void synchronizeApp (VastMoveMessage *vastMoveMsg=NULL)

Protected Attributes

double AOI_size
double areaDimension
PositionSet Positions
StockList Stock
long joinRequestBytesSent
long joinAcknowledgeBytesSent
long nodeMoveBytesSent
long newNeighborsBytesSent
long nodeLeaveBytesSent
long enclosingNeighborsRequestBytesSent
long pingBytesSent
long pongBytesSent
long discardNodeBytesSent
long maxBytesPerSecondSent
long averageBytesPerSecondSent
long bytesPerSecond
unsigned int secTimerCount
bool debugVoronoiOutput
simtime_t joinTimeout
simtime_t pingTimeout
simtime_t discoveryIntervall
simtime_t checkCriticalIntervall
double criticalThreshold
unsigned long stockListSize
Geometry geom
EdgeList edgelist
HeapPQ heap
cMessage * join_timer
cMessage * ping_timer
cMessage * discovery_timer
cMessage * checkcritical_timer
cMessage * sec_timer

Detailed Description

Voronoi class.

An overlay network based on voronoi diagrams.

Definition at line 41 of file Vast.h.


Constructor & Destructor Documentation

Vast::~Vast (  ) 

Definition at line 1195 of file Vast.cc.

{
    if(Sites.size()) {
        for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
            delete itSites->second;
        }
        Sites.clear();
        Positions.clear();
    }
    // destroy self timer messages
    cancelAndDelete(join_timer);
    cancelAndDelete(ping_timer);
    cancelAndDelete(sec_timer);
    cancelAndDelete(discovery_timer);
    cancelAndDelete(checkcritical_timer);
}


Member Function Documentation

void Vast::addNode ( Vector2D  p,
NodeHandle  node,
int  NeighborCount = 0 
) [protected]

Definition at line 313 of file Vast.cc.

Referenced by handleJoinAcknowledge(), handleJoinRequest(), handleNewNeighbors(), handleNodeLeave(), handleNodeMove(), and handlePong().

{
    if(node != thisSite.addr) {
        if(Sites.find(node) == Sites.end()) {
            Site* temp_site = new Site();
            temp_site->coord = p;
            temp_site->addr = node;
            temp_site->neighborCount = NeighborCount;

            Sites.insert(std::make_pair(temp_site->addr, temp_site));
            Positions.insert(temp_site->coord);
        }
        else {
            SiteMap::iterator itSites = Sites.find(node);
            Positions.erase(itSites->second->coord);
            itSites->second->coord = p;
            Positions.insert(itSites->second->coord);
            if(NeighborCount != 0) {
                itSites->second->neighborCount = NeighborCount;
            }
        }
    }
}

void Vast::addNodeToStock ( NodeHandle  node  )  [protected]

Definition at line 337 of file Vast.cc.

Referenced by handleBackupNeighbors().

{
    if(node != thisSite.addr) {
        for(StockList::iterator itTemp = Stock.begin(); itTemp != Stock.end(); ++itTemp) {
            if(*itTemp == node) {
                return;
            }
        }
        Stock.push_front(node);
        if(Stock.size() > stockListSize) {
            Stock.pop_back();
        }
    }
}

void Vast::buildVoronoi ( Vector2D  old_pos,
Vector2D  new_pos,
NodeHandle  enclosingCheck = NodeHandle::UNSPECIFIED_NODE 
) [protected]

Definition at line 362 of file Vast.cc.

{
    int sqrt_nsites = 1;
    double xmin, xmax, ymin, ymax;
    double deltax, deltay;

    // check wether there are any neighbors
    if(Sites.size() == 0) return;

    xmin = xmax = thisSite.coord.x;
    ymin = ymax = thisSite.coord.y;

    std::map<Vector2D, Site*> sortedSites;
    sortedSites.insert(std::make_pair(thisSite.coord, &thisSite));

    for(SiteMap::iterator itTemp = Sites.begin(); itTemp != Sites.end(); ++itTemp) {
        // determine min/max site coordinates
        if(itTemp->second->coord.x < xmin) xmin = itTemp->second->coord.x;
        if(itTemp->second->coord.x > xmax) xmax = itTemp->second->coord.x;
        if(itTemp->second->coord.y < ymin) ymin = itTemp->second->coord.y;
        if(itTemp->second->coord.y > ymax) ymax = itTemp->second->coord.y;
        // reset all sites to UNDEF
        itTemp->second->type = UNDEF;
        // reset enclosing neighbors set
        itTemp->second->enclosingSet.clear();
        // fill sorted List
        sortedSites.insert(std::make_pair(itTemp->second->coord, itTemp->second));
        sqrt_nsites++;
    }

    // needed to determine appropriate hashtable size
    deltax = xmax - xmin;
    deltay = ymax - ymin;
    sqrt_nsites = (int)sqrt((double)(sqrt_nsites+4));

    // start to calculate the voronoi
    Site *newsite, *bot, *top, *temp, *p, *v, *bottomsite;
    Vector2D newintstar;
    int pm;
    Halfedge *lbnd, *rbnd, *llbnd, *rrbnd, *bisector;
    Edge *e;

    newintstar.x = newintstar.y = 0.0;

    std::map<Vector2D, Site*>::iterator itSortedSites = sortedSites.begin();

    geom.initialize(deltax, deltay, thisSite.coord, old_pos, new_pos, AOI_size);
    heap.PQinitialize(sqrt_nsites, ymin, deltay);
    bottomsite = itSortedSites->second;
    ++itSortedSites;
    edgelist.initialize(sqrt_nsites, xmin, deltax, bottomsite);

    newsite = itSortedSites->second;
    ++itSortedSites;
    while(true) {
        if(!heap.PQempty()) newintstar = heap.PQ_min();

        if(newsite != NULL && (heap.PQempty() ||
           newsite->coord.y < newintstar.y ||
           (newsite->coord.y == newintstar.y && newsite->coord.x < newintstar.x))) {
            lbnd = edgelist.ELleftbnd(&(newsite->coord));
            rbnd = edgelist.ELright(lbnd);
            bot = edgelist.rightreg(lbnd);
            e = geom.bisect(bot, newsite);
            bisector = edgelist.HEcreate(e, le);
            edgelist.ELinsert(lbnd, bisector);
            if ((p = geom.intersect(lbnd, bisector)) != NULL) {
                heap.PQdelete(lbnd);
                heap.PQinsert(lbnd, p, geom.dist(p, newsite));
            }
            lbnd = bisector;
            bisector = edgelist.HEcreate(e, re);
            edgelist.ELinsert(lbnd, bisector);
            if ((p = geom.intersect(bisector, rbnd)) != NULL) heap.PQinsert(bisector, p, geom.dist(p, newsite));
            if(itSortedSites != sortedSites.end()) {
                newsite = itSortedSites->second;
                ++itSortedSites;
            }
            else newsite = NULL;
        }
        else if (!heap.PQempty()) {
            lbnd = heap.PQextractmin();
            llbnd = edgelist.ELleft(lbnd);
            rbnd = edgelist.ELright(lbnd);
            rrbnd = edgelist.ELright(rbnd);
            bot = edgelist.leftreg(lbnd);
            top = edgelist.rightreg(rbnd);
            v = lbnd->vertex;
            geom.endpoint(lbnd->ELedge, lbnd->ELpm, v);
            geom.endpoint(rbnd->ELedge, rbnd->ELpm, v);
            edgelist.ELdelete(lbnd);
            heap.PQdelete(rbnd);
            edgelist.ELdelete(rbnd);
            pm = le;
            if (bot->coord.y > top->coord.y) {
                temp = bot;
                bot = top;
                top = temp;
                pm = re;
            }
            e = geom.bisect(bot, top);
            bisector = edgelist.HEcreate(e, pm);
            edgelist.ELinsert(llbnd, bisector);
            geom.endpoint(e, re-pm, v);
            if((p = geom.intersect(llbnd, bisector)) != NULL) {
                heap.PQdelete(llbnd);
                heap.PQinsert(llbnd, p, geom.dist(p, bot));
            }
            if ((p = geom.intersect(bisector, rrbnd)) != NULL) heap.PQinsert(bisector, p, geom.dist(p, bot));
        }
        else break;
    }

    // process the generated edgelist
    for(lbnd = edgelist.ELright(edgelist.ELleftend); lbnd != edgelist.ELrightend; lbnd = edgelist.ELright(lbnd)) {
        e = lbnd -> ELedge;
        geom.processEdge(e);
    }
    // process sites in order to determine our neighbors
    for(SiteMap::iterator itTemp = Sites.begin(); itTemp != Sites.end(); ++itTemp) {
        if(itTemp->second->innerEdge[0]) {
            if(itTemp->second->outerEdge) {
                itTemp->second->type |= BOUNDARY;
                // Debug output
                if(debugOutput)
                    EV << "[NeighborsList::buildVoronoi()]\n"
                       << "    Site at [" << itTemp->second->coord.x << ", "
                       << itTemp->second->coord.y << "] is a boundary neighbor."
                       << endl;
            }
            else {
                itTemp->second->type |= NEIGHBOR;
                // Debug output
                if(debugOutput)
                    EV << "[NeighborsList::buildVoronoi()]\n"
                       << "    Site at [" << itTemp->second->coord.x << ", "
                       << itTemp->second->coord.y << "] is a neighbor."
                       << endl;
            }
        }
        // Treat enclosing neighbors whose voronoi region is outside our AOI as boundary neighbors
        if((!itTemp->second->type & NEIGHBOR) && (itTemp->second->type & ENCLOSING)) {
            itTemp->second->type |= BOUNDARY;
            // Debug output
            if(debugOutput)
                EV << "[NeighborsList::buildVoronoi()]\n"
                << "    Site at [" << itTemp->second->coord.x << ", "
                << itTemp->second->coord.y << "] is a boundary neighbor."
                << endl;
        }
        if(!itTemp->second->innerEdge[1] && itTemp->second->innerEdge[2]) {
            itTemp->second->type |= NEW;
            // Debug output
            if(debugOutput)
                EV << "[NeighborsList::buildVoronoi()]\n"
                   << "    Site at [" << itTemp->second->coord.x << ", "
                   << itTemp->second->coord.y << "] is a new neighbor for site at " << new_pos.x << ":" << new_pos.y << "."
                   << endl;
        }
        // enhanced enclosing check
        if(!enclosingCheck.isUnspecified() && (Sites.find(enclosingCheck) != Sites.end())) {
            Site* tempSite = Sites.find(enclosingCheck)->second;
            for(EnclosingSet::iterator itSet = tempSite->enclosingSet.begin(); itSet != tempSite->enclosingSet.end(); ++itSet) {
                if(tempSite->oldEnclosingSet.find(*itSet) == tempSite->oldEnclosingSet.end()
                    && Sites.find(*itSet) != Sites.end()) {
                    Sites.find(*itSet)->second->type |= NEW;
                }
            }
            tempSite->enclosingSet.swap(tempSite->oldEnclosingSet);
        }
        // reset inner- and outeredge indicator
        itTemp->second->innerEdge[0] = false;
        itTemp->second->innerEdge[1] = false;
        itTemp->second->innerEdge[2] = false;
        itTemp->second->outerEdge = false;
    }
    // clean up
    edgelist.reset();
    heap.PQreset();
    geom.reset();
}

void Vast::buildVoronoi (  )  [protected]
void Vast::changeState ( int  state  )  [protected]

Definition at line 105 of file Vast.cc.

Referenced by handleJoin(), handleJoinAcknowledge(), handleNodeGracefulLeaveNotification(), and initializeOverlay().

{
    switch(state) {
        case INIT: {
            this->state = INIT;
            globalNodeList->removePeer(thisSite.addr);
            cancelEvent(join_timer);
            cancelEvent(ping_timer);
            cancelEvent(sec_timer);
            cancelEvent(discovery_timer);
            cancelEvent(checkcritical_timer);
        } break;
        case JOINING: {
            this->state = JOINING;
            scheduleAt(simTime(), join_timer);
            scheduleAt(simTime() + 1.0, sec_timer);
        } break;
        case READY: {
            this->state = READY;
            cancelEvent(join_timer);
            globalNodeList->registerPeer(thisSite.addr);
            scheduleAt(simTime() + pingTimeout, ping_timer);
            if(checkCriticalIntervall > 0.0 && discoveryIntervall > 0.0) {
                scheduleAt(simTime() + checkCriticalIntervall, checkcritical_timer);
                scheduleAt(simTime() + discoveryIntervall, discovery_timer);
            }
            // tell the application we are ready
            CompReadyMessage* readyMsg = new CompReadyMessage("OVERLAY_READY");
            readyMsg->setReady(true);
            readyMsg->setComp(getThisCompType());
            sendToApp(readyMsg);
            GameAPIResizeAOIMessage* gameMsg = new GameAPIResizeAOIMessage("RESIZE_AOI");
            gameMsg->setCommand(RESIZE_AOI);
            gameMsg->setAOIsize(AOI_size);
            sendToApp(gameMsg);
        } break;
    }
    setBootstrapedIcon();
    // debug output
    if(debugOutput) {
        EV << "[Vast::changeState() @ " << thisSite.addr.getIp()
           << " (" << thisSite.addr.getKey().toString(16) << ")]\n"
           << "VAST: Node " << thisSite.addr.getIp() << " entered ";
        switch(state) {
            case INIT: ev << "INIT"; break;
            case JOINING: ev << "JOINING"; break;
            case READY: ev << "READY"; break;
        }
        ev << " state." << endl;
    }
}

void Vast::finishOverlay (  )  [virtual]

collects statistical data in derived class

Reimplemented from BaseOverlay.

Definition at line 1147 of file Vast.cc.

{
    globalNodeList->removePeer(thisSite.addr);

//    We use our own time count to avoid rounding errors
//    simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
//    if(time == 0) return;
    if(secTimerCount == 0) return;

    // collect statistics
    globalStatistics->addStdDev("Vast: JOIN_REQUEST bytes sent/s", joinRequestBytesSent/(double) secTimerCount);
    globalStatistics->addStdDev("Vast: JOIN_ACKNOWLEDGE bytes sent/s", joinAcknowledgeBytesSent/(double) secTimerCount);
    globalStatistics->addStdDev("Vast: NODE_MOVE bytes sent/s", nodeMoveBytesSent/(double) secTimerCount);
    globalStatistics->addStdDev("Vast: NEW_NEIGHBORS bytes sent/s", newNeighborsBytesSent/(double) secTimerCount);
    globalStatistics->addStdDev("Vast: NODE_LEAVE bytes sent/s", nodeLeaveBytesSent/(double) secTimerCount);
    globalStatistics->addStdDev("Vast: ENCLOSING_NEIGHBORS_REQUEST bytes sent/s", enclosingNeighborsRequestBytesSent/(double) secTimerCount);
    globalStatistics->addStdDev("Vast: PING bytes sent/s", pingBytesSent/(double) secTimerCount);
    globalStatistics->addStdDev("Vast: PONG bytes sent/s", pongBytesSent/(double) secTimerCount);
    globalStatistics->addStdDev("Vast: DISCARD_NODE bytes sent/s", discardNodeBytesSent/(double) secTimerCount);

    globalStatistics->addStdDev("Vast: max bytes/second sent", maxBytesPerSecondSent);
    globalStatistics->addStdDev("Vast: average bytes/second sent", averageBytesPerSecondSent / (double) secTimerCount);
}

double Vast::getAOI (  ) 

Definition at line 1171 of file Vast.cc.

{
    Enter_Method_Silent();
    return AOI_size;
}

double Vast::getAreaDimension (  ) 

Definition at line 1189 of file Vast.cc.

{
    Enter_Method_Silent();
    return areaDimension;
}

NodeHandle Vast::getHandle (  ) 

Definition at line 1183 of file Vast.cc.

Referenced by ConnectivityProbe::extractTopology().

{
    Enter_Method_Silent();
    return thisSite.addr;
}

Vector2D Vast::getPosition (  ) 

Definition at line 1177 of file Vast.cc.

{
    Enter_Method_Silent();
    return thisSite.coord;
}

void Vast::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 196 of file Vast.cc.

{
    if(dynamic_cast<GameAPIMessage*>(msg)) {
        GameAPIMessage* gameAPIMsg = check_and_cast<GameAPIMessage*>(msg);
        // debug output
        if(debugOutput) EV << "[Vast::handleAppMessage() @ " << thisSite.addr.getIp()
                           << " (" << thisSite.addr.getKey().toString(16) << ")]\n"
                           << "    Node " << thisSite.addr.getIp() << " received " << gameAPIMsg->getName() << " from application."
                           << endl;
        switch(gameAPIMsg->getCommand()) {
            case MOVEMENT_INDICATION: {
                GameAPIPositionMessage* gameAPIPosMsg = check_and_cast<GameAPIPositionMessage*>(msg);
                if(state == JOINING) {
                    handleJoin(gameAPIPosMsg);
                    delete msg;
                }
                else if(state == READY) {
                    handleMove(gameAPIPosMsg);
                    delete msg;
                }
            } break;
            case GAMEEVENT_CHAT:
            case GAMEEVENT_SNOW:
            case GAMEEVENT_FROZEN:
                handleEvent( gameAPIMsg );
                delete msg;
                break;
            default: {
                delete msg;
            }
        }
    }
    else delete msg;
}

void Vast::handleBackupNeighbors ( VastListMessage vastListMsg  )  [protected]

Definition at line 965 of file Vast.cc.

Referenced by handleUDPMessage().

{
    // add new neighbors to stock list
    for(unsigned int i=0; i<vastListMsg->getNeighborNodeArraySize(); i++) {
        if(Sites.find(vastListMsg->getNeighborNode(i)) == Sites.end()) {
            addNodeToStock(vastListMsg->getNeighborNode(i));
        }
    }
}

void Vast::handleDiscardNode ( VastDiscardMessage vastMsg  )  [protected]

Definition at line 993 of file Vast.cc.

Referenced by handleUDPMessage().

{
    // discard outdated entry
    removeNode(vastMsg->getDiscardNode());
    // update voronoi
    //buildVoronoi();
    //synchronizeApp();
    // removeNeighbors();
}

void Vast::handleEnclosingNeighborsRequest ( VastMessage vastMsg  )  [protected]

Definition at line 936 of file Vast.cc.

Referenced by handleUDPMessage().

{
    // send new neighbors
    VastListMessage *vastListMsg = new VastListMessage("NEW_NEIGHBORS");
    vastListMsg->setCommand(NEW_NEIGHBORS);

    vastListMsg->setNeighborNodeArraySize(Sites.size());
    vastListMsg->setNeighborPosArraySize(Sites.size());

    int i = 0;
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
        if((itSites->second->type & ENCLOSING) && itSites->second->addr != vastMsg->getSourceNode()) {
            vastListMsg->setNeighborNode(i, itSites->second->addr);
            vastListMsg->setNeighborPos(i, itSites->second->coord);
            ++i;
        }
    }
    vastListMsg->setNeighborNodeArraySize(i);
    vastListMsg->setNeighborPosArraySize(i);

    vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
    if(vastListMsg->getNeighborNodeArraySize() > 0) {
        sendMessage(vastListMsg, vastMsg->getSourceNode());
    }
    else {
        delete vastListMsg;
    }
}

void Vast::handleEvent ( GameAPIMessage msg  )  [protected]

Definition at line 764 of file Vast.cc.

Referenced by handleAppMessage().

{
    // send event to neighbors
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
        VastEventMessage *vastMsg = new VastEventMessage("EVENT");
        vastMsg->setCommand(VAST_EVENT);
        vastMsg->encapsulate((cPacket*)msg->dup());
        // FIXME: Message length!
        sendMessage(vastMsg, itSites->second->addr);
    }
}

void Vast::handleJoin ( GameAPIPositionMessage sgcMsg  )  [protected]

Definition at line 721 of file Vast.cc.

Referenced by handleAppMessage().

{
    TransportAddress joinNode = bootstrapList->getBootstrapNode();
    thisSite.coord = sgcMsg->getPosition();
    // check if this is the only node in the overlay
    if(joinNode.isUnspecified()) {
        changeState(READY);
    }
    else {
        VastMessage *vastMsg = new VastMessage("JOIN_REQUEST");
        vastMsg->setCommand(JOIN_REQUEST);
        vastMsg->setBitLength(VAST_L(vastMsg));
        sendMessage(vastMsg, joinNode);
    }
}

void Vast::handleJoinAcknowledge ( VastListMessage vastListMsg  )  [protected]

Definition at line 827 of file Vast.cc.

Referenced by handleUDPMessage().

{
    // add acceptor node
    changeState(READY);
    addNode(vastListMsg->getPos(), vastListMsg->getSourceNode(), vastListMsg->getNeighborCount());
    // add new neighbors
    for(unsigned int i=0; i<vastListMsg->getNeighborNodeArraySize(); i++) {
        addNode(vastListMsg->getNeighborPos(i), vastListMsg->getNeighborNode(i));
    }
    // update voronoi with new neighbors
    buildVoronoi();
    synchronizeApp();
    // removeNeighbors();
    // contact new neighbors
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
        VastMoveMessage *vastMoveMsg = new VastMoveMessage("NODE_MOVE");
        vastMoveMsg->setCommand(NODE_MOVE);
        vastMoveMsg->setNewPos(thisSite.coord);
        vastMoveMsg->setIs_boundary(itSites->second->type & BOUNDARY);
        vastMoveMsg->setRequest_list(true);
        vastMoveMsg->setBitLength(VASTMOVE_L(vastMoveMsg));
        sendMessage(vastMoveMsg, itSites->second->addr);
    }
}

void Vast::handleJoinRequest ( VastMessage vastMsg  )  [protected]

Definition at line 776 of file Vast.cc.

Referenced by handleUDPMessage().

{
    Site *forwardSite = NULL;
    // start with this node
    double min_dist = thisSite.coord.distanceSqr(vastMsg->getPos());
    forwardSite = &thisSite;
    // iterate through all neighbors
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
        // dont forward to nodes which are still joining
        if(itSites->second->coord.distanceSqr(vastMsg->getPos()) < min_dist && itSites->second->neighborCount >= 0) {
            min_dist = itSites->second->coord.distanceSqr(vastMsg->getPos());
            forwardSite = itSites->second;
        }
    }
    // do nothing and let node retry with new position if current position is illegal
    if(min_dist == 0.0) {
        delete vastMsg;
    }
    else {
        // send an acknowledge or forward request if any of our neighbors is closer to joining node
        if(forwardSite->type & THIS) {
            VastListMessage *vastListMsg = new VastListMessage("JOIN_ACKNOWLEDGE");
            vastListMsg->setCommand(JOIN_ACKNOWLEDGE);
            // fill neighbors list
            vastListMsg->setNeighborNodeArraySize(Sites.size());
            vastListMsg->setNeighborPosArraySize(Sites.size());
            int i = 0;
            for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
                vastListMsg->setNeighborNode(i, itSites->second->addr);
                vastListMsg->setNeighborPos(i, itSites->second->coord);
                ++i;
            }

            vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
            sendMessage(vastListMsg, vastMsg->getSourceNode());

            // add node to list to propagte its position early
            // nieghborCount is set to -1 to indicate node is still joining
            addNode(vastMsg->getPos(), vastMsg->getSourceNode(), -1);
            // update voronoi with new neighbors
            buildVoronoi();
            synchronizeApp();
            // removeNeighbors();
            delete vastMsg;
        }
        else {
            sendMessage(vastMsg, forwardSite->addr);
        }
    }
}

void Vast::handleMove ( GameAPIPositionMessage sgcMsg  )  [protected]

Definition at line 737 of file Vast.cc.

Referenced by handleAppMessage().

{
    Vector2D pos = sgcMsg->getPosition();
    // test if new position is legal
    if(Positions.find(pos) != Positions.end()) {
        GameAPIMessage *gameMsg = new GameAPIMessage("MOVEMENT_REQUEST");
        gameMsg->setCommand(MOVEMENT_REQUEST);
        sendToApp(gameMsg);
        return;
    }
    // set new position
    thisSite.coord = pos;
    // update voronoi
    buildVoronoi();
    synchronizeApp();
    removeNeighbors();
    // send position update to neighbors
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
        VastMoveMessage *vastMoveMsg = new VastMoveMessage("NODE_MOVE");
        vastMoveMsg->setCommand(NODE_MOVE);
        vastMoveMsg->setNewPos(pos);
        vastMoveMsg->setIs_boundary(itSites->second->type & BOUNDARY);
        vastMoveMsg->setBitLength(VASTMOVE_L(vastMoveMsg));
        sendMessage(vastMoveMsg, itSites->second->addr);
    }
}

void Vast::handleNewNeighbors ( VastListMessage vastListMsg  )  [protected]

Definition at line 904 of file Vast.cc.

Referenced by handleUDPMessage().

{
    // add new neighbors
    for(unsigned int i=0; i<vastListMsg->getNeighborNodeArraySize(); i++) {
        addNode(vastListMsg->getNeighborPos(i), vastListMsg->getNeighborNode(i));

        if(vastListMsg->getRequestEnclosingNeighbors()) {
            VastMessage *vastMsg = new VastMessage("ENCLOSING_NEIGHBORS_REQUEST");
            vastMsg->setCommand(ENCLOSING_NEIGHBORS_REQUEST);
            vastMsg->setBitLength(VAST_L(vastMsg));
            sendMessage(vastMsg, vastListMsg->getNeighborNode(i));
        }
    }
    // update voronoi with new neighbors
//    buildVoronoi();
//    synchronizeApp();
    // removeNeighbors();
}

void Vast::handleNodeGracefulLeaveNotification (  )  [virtual]

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

Reimplemented from BaseOverlay.

Definition at line 585 of file Vast.cc.

{
     if(state == READY) {
        // generate node leave messages
        VastListMessage *vastListMsg = new VastListMessage("NODE_LEAVE");
        vastListMsg->setCommand(NODE_LEAVE);
        // fill neighbors list
        vastListMsg->setNeighborNodeArraySize(Sites.size());
        vastListMsg->setNeighborPosArraySize(Sites.size());
        int i = 0;
        for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
            if(itSites->second->type & ENCLOSING) {
                vastListMsg->setNeighborNode(i, itSites->second->addr);
                vastListMsg->setNeighborPos(i, itSites->second->coord);
                ++i;
            }
        }
        vastListMsg->setNeighborNodeArraySize(i);
        vastListMsg->setNeighborPosArraySize(i);

        vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
        if(vastListMsg->getNeighborNodeArraySize() > 0) {
            for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
                VastListMessage *vastCopyMsg = new VastListMessage(*vastListMsg);
               sendMessage(vastCopyMsg, itSites->second->addr);
            }
        }
        delete vastListMsg;
        changeState(INIT);
    }
}

void Vast::handleNodeLeave ( VastListMessage vastListMsg  )  [protected]

Definition at line 923 of file Vast.cc.

Referenced by handleUDPMessage().

{
    removeNode(vastListMsg->getSourceNode());
    // add possible new neighbors
    for(unsigned int i=0; i<vastListMsg->getNeighborNodeArraySize(); i++) {
        addNode(vastListMsg->getNeighborPos(i), vastListMsg->getNeighborNode(i));
    }
    // update voronoi with new neighbors
    // buildVoronoi();
    // synchronizeApp();
    // removeNeighbors();
}

void Vast::handleNodeLeaveNotification (  )  [virtual]

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

Reimplemented from BaseOverlay.

Definition at line 567 of file Vast.cc.

{
    if(state == READY) {
        // debug output
        if(debugOutput) {
            EV << "[Vast::receiveChangeNotification() @ " << thisSite.addr.getIp()
               << " (" << thisSite.addr.getKey().toString(16) << ")]\n"
               << "    Node " << thisSite.addr.getIp() << " is leaving the overlay."
               << endl;
        }

        CompReadyMessage* readyMsg = new CompReadyMessage("OVERLAY_FINISHED");
        readyMsg->setReady(false);
        readyMsg->setComp(getThisCompType());
        sendToApp(readyMsg);
    }
}

void Vast::handleNodeMove ( VastMoveMessage vastMoveMsg  )  [protected]

Definition at line 852 of file Vast.cc.

Referenced by handleUDPMessage().

{
    RECORD_STATS(
            globalStatistics->addStdDev(
                "Vast: MoveDelay",
                SIMTIME_DBL(simTime()) - SIMTIME_DBL(vastMoveMsg->getCreationTime())
                );
            );

    Vector2D old_p, new_p;
    old_p = vastMoveMsg->getPos();
    new_p = vastMoveMsg->getNewPos();
    addNode(new_p, vastMoveMsg->getSourceNode(), vastMoveMsg->getNeighborCount());
    // update voronoi with new neighbor detection or without
    if(vastMoveMsg->getIs_boundary() || vastMoveMsg->getRequest_list()) {
        buildVoronoi(old_p, new_p, vastMoveMsg->getSourceNode()); // enhanced enclosing check
        synchronizeApp(vastMoveMsg);
        // removeNeighbors();
        // send new neighbors
        VastListMessage *vastListMsg = new VastListMessage("NEW_NEIGHBORS");
        vastListMsg->setCommand(NEW_NEIGHBORS);

        vastListMsg->setNeighborNodeArraySize(Sites.size());
        vastListMsg->setNeighborPosArraySize(Sites.size());

        int i = 0;
        for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
            if(itSites->second->type & NEW || vastMoveMsg->getRequest_list()) {
                vastListMsg->setNeighborNode(i, itSites->second->addr);
                vastListMsg->setNeighborPos(i, itSites->second->coord);
                ++i;
            }
        }
        vastListMsg->setNeighborNodeArraySize(i);
        vastListMsg->setNeighborPosArraySize(i);
        vastListMsg->setRequestEnclosingNeighbors(true);

        vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
        if(vastListMsg->getNeighborNodeArraySize() > 0) {
            sendMessage(vastListMsg, vastMoveMsg->getSourceNode());
        }
        else {
            delete vastListMsg;
        }
    }
    else {
        // buildVoronoi();
        synchronizeApp(vastMoveMsg);
        // removeNeighbors();
    }
}

void Vast::handlePing ( VastMessage vastMsg  )  [protected]

Definition at line 975 of file Vast.cc.

Referenced by handleUDPMessage().

{
    VastMessage *vastPongMsg = new VastMessage("PONG");
    vastPongMsg->setCommand(PONG);
    vastPongMsg->setBitLength(VAST_L(vastPongMsg));
    sendMessage(vastPongMsg, vastMsg->getSourceNode());
}

void Vast::handlePong ( VastMessage vastMsg  )  [protected]

Definition at line 983 of file Vast.cc.

Referenced by handleUDPMessage().

{
    // replace entry cause it was probably outdated
    addNode(vastMsg->getPos(), vastMsg->getSourceNode(), vastMsg->getNeighborCount());
    // update voronoi
    //buildVoronoi();
    //synchronizeApp();
    // removeNeighbors();
}

void Vast::handleTimerEvent ( cMessage *  msg  ) 

Definition at line 157 of file Vast.cc.

{
    if(msg->isName("join_timer")) {
        //reset timer
        cancelEvent(join_timer);
        scheduleAt(simTime() + joinTimeout, msg);
        // handle event
        processJoinTimer();
    }
    else if(msg->isName("ping_timer")) {
        //reset timer
        cancelEvent(ping_timer);
        scheduleAt(simTime() + pingTimeout, msg);
        // handle event
        processPingTimer();
    }
    else if(msg->isName("sec_timer")) {
        //reset timer
        cancelEvent(sec_timer);
        scheduleAt(simTime() + 1, msg);
        // handle event
        processSecTimer();
    }
    else if(msg->isName("checkcritical_timer")) {
        //reset timer
        cancelEvent(checkcritical_timer);
        scheduleAt(simTime() + checkCriticalIntervall, msg);
        // handle event
        processCheckCriticalTimer();
    }
    else if(msg->isName("discovery_timer")) {
        //reset timer
        cancelEvent(discovery_timer);
        scheduleAt(simTime() + discoveryIntervall, msg);
        // handle event
        processDiscoveryTimer();
    }
}

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

Processes messages from underlay.

Parameters:
msg Message from UDP

Reimplemented from BaseOverlay.

Definition at line 231 of file Vast.cc.

{
    if(state == INIT) {
        delete msg;
        return;
    }
    if(dynamic_cast<VastMessage*>(msg)) {
        VastMessage* vastMsg = check_and_cast<VastMessage*>(msg);
        if(vastMsg->getDestKey().isUnspecified() || 
           thisSite.addr.getKey().isUnspecified() ||
           vastMsg->getDestKey() == thisSite.addr.getKey()) {
            // debug output
            if(debugOutput) EV << "[Vast::handleUDPMessage() @ " << thisSite.addr.getIp()
                               << " (" << thisSite.addr.getKey().toString(16) << ")]\n"
                               << "    Node " << thisSite.addr.getIp() << " received " << vastMsg->getName() << " from " << vastMsg->getSourceNode().getIp()
                               << endl;
            bool doUpdate = true;
            if(state == READY) {
                switch(vastMsg->getCommand()) {
                    case JOIN_REQUEST: {
                        handleJoinRequest(vastMsg);
                        doUpdate = false;
                    } break;
                    case NODE_MOVE: {
                        VastMoveMessage* vastMoveMsg = check_and_cast<VastMoveMessage*>(msg);
                        handleNodeMove(vastMoveMsg);
                    } break;
                    case NEW_NEIGHBORS: {
                        VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
                        handleNewNeighbors(vastListMsg);
                    } break;
                    case NODE_LEAVE: {
                        VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
                        handleNodeLeave(vastListMsg);
                    } break;
                    case ENCLOSING_NEIGHBORS_REQUEST: {
                        handleEnclosingNeighborsRequest(vastMsg);
                    } break;
                    case BACKUP_NEIGHBORS: {
                        VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
                        handleBackupNeighbors(vastListMsg);
                    } break;
                    case PING: {
                        handlePing(vastMsg);
                    } break;
                    case PONG: {
                        handlePong(vastMsg);
                    } break;
                    case DISCARD_NODE: {
                        VastDiscardMessage* vastDiscardMsg = check_and_cast<VastDiscardMessage*>(msg);
                        handleDiscardNode(vastDiscardMsg);
                    } break;
                    case VAST_EVENT: {
                        sendToApp(vastMsg->decapsulate());
                        doUpdate = false;
                        delete vastMsg;
                    } break;
                }
                // update timestamp
                if(doUpdate) {
                    SiteMap::iterator itSites = Sites.find(vastMsg->getSourceNode());
                    if(itSites != Sites.end()) {
                        itSites->second->tstamp = simTime();
                    }
                    delete msg;
                }
            }
            else if(state == JOINING && vastMsg->getCommand() == JOIN_ACKNOWLEDGE) {
                VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
                handleJoinAcknowledge(vastListMsg);
                delete msg;
            }
            else delete msg;
        }
        else {
            sendDiscardNode(vastMsg);
            delete msg;
        }
    }
    else delete msg;
}

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

Initializes derived-class-attributes.


Initializes derived-class-attributes, called by BaseOverlay::initialize(). By default this method is called once. If more stages are needed one can overload numInitStages() and add more stages.

Parameters:
stage the init stage

Reimplemented from BaseOverlay.

Definition at line 34 of file Vast.cc.

{
    // because of IPAddressResolver, we need to wait until interfaces are registered,
    // address auto-assignment takes place etc.
    if(stage != MIN_STAGE_OVERLAY) return;

    // fetch parameters
    debugVoronoiOutput = par("debugVastOutput");
    areaDimension = par("areaDimension");
    AOI_size = par("AOIWidth");
    joinTimeout = par("joinTimeout");
    pingTimeout = par("pingTimeout");
    discoveryIntervall = par("discoveryIntervall");
    checkCriticalIntervall = par("criticalCheckIntervall");
    criticalThreshold = par("criticalThreshold");
    stockListSize = par("stockListSize");

    // set node key
    thisNode.setKey(OverlayKey::random());
    thisSite.type = THIS;
    thisSite.addr = thisNode;

    geom.setDebug(debugOutput);

    // self-messages
    join_timer = new cMessage("join_timer");
    ping_timer = new cMessage("ping_timer");
    sec_timer = new cMessage("sec_timer");
    discovery_timer = new cMessage("discovery_timer");
    checkcritical_timer = new cMessage("checkcritical_timer");

    // statistics
    joinRequestBytesSent = 0;
    joinAcknowledgeBytesSent = 0;
    nodeMoveBytesSent = 0;
    newNeighborsBytesSent = 0;
    nodeLeaveBytesSent = 0;
    enclosingNeighborsRequestBytesSent = 0;
    pingBytesSent = 0;
    pongBytesSent = 0;
    discardNodeBytesSent = 0;

    maxBytesPerSecondSent = 0;
    averageBytesPerSecondSent = 0;
    bytesPerSecond = 0;
    secTimerCount = 0;

    // watch some variables
    WATCH(AOI_size);
    WATCH(thisSite);
    WATCH_MAP(Sites);
    WATCH_SET(Positions);

    WATCH(joinRequestBytesSent);
    WATCH(joinAcknowledgeBytesSent);
    WATCH(nodeMoveBytesSent);
    WATCH(newNeighborsBytesSent);
    WATCH(nodeLeaveBytesSent);
    WATCH(enclosingNeighborsRequestBytesSent);
    WATCH(pingBytesSent);
    WATCH(pongBytesSent);
    WATCH(discardNodeBytesSent);

    WATCH(maxBytesPerSecondSent);
    WATCH(bytesPerSecond);

    // set initial state
    changeState(INIT);
    changeState(JOINING);
}

void Vast::processCheckCriticalTimer (  )  [protected]

Definition at line 677 of file Vast.cc.

Referenced by handleTimerEvent().

{
    double NeighborLevel;
    int NeighborSum = 0;
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
        if(itSites->second->neighborCount > 0) {
            NeighborSum += itSites->second->neighborCount;
        }
    }
    NeighborLevel = (double)(Sites.size() * Sites.size()) / (double)NeighborSum;

    if(NeighborLevel < criticalThreshold) {
        VastListMessage *vastListMsg = new VastListMessage("BACKUP_NEIGHBORS");
        vastListMsg->setCommand(BACKUP_NEIGHBORS);
        // fill neighbors list
        vastListMsg->setNeighborNodeArraySize(Sites.size());
        vastListMsg->setNeighborPosArraySize(Sites.size());
        int i = 0;
        for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
            vastListMsg->setNeighborNode(i, itSites->second->addr);
            vastListMsg->setNeighborPos(i, itSites->second->coord);
            ++i;
        }
        vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
        for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
            VastListMessage *vastCopyMsg = new VastListMessage(*vastListMsg);
            sendMessage(vastCopyMsg, itSites->second->addr);
        }
        delete vastListMsg;
    }
}

void Vast::processDiscoveryTimer (  )  [protected]

Definition at line 709 of file Vast.cc.

Referenced by handleTimerEvent().

{
    for(StockList::iterator itStock = Stock.begin(); itStock != Stock.end(); ++itStock) {
        VastMoveMessage *vastMoveMsg = new VastMoveMessage("NODE_MOVE");
        vastMoveMsg->setCommand(NODE_MOVE);
        vastMoveMsg->setNewPos(thisSite.coord);
        vastMoveMsg->setRequest_list(true);
        vastMoveMsg->setBitLength(VASTMOVE_L(vastMoveMsg));
        sendMessage(vastMoveMsg, *itStock);
    }
}

void Vast::processJoinTimer (  )  [protected]

Definition at line 617 of file Vast.cc.

Referenced by handleTimerEvent().

{
    GameAPIMessage *sgcMsg = new GameAPIMessage("MOVEMENT_REQUEST");
    sgcMsg->setCommand(MOVEMENT_REQUEST);
    sendToApp(sgcMsg);
}

void Vast::processPingTimer (  )  [protected]

Definition at line 624 of file Vast.cc.

Referenced by handleTimerEvent().

{
    bool abnormalLeave = false;
    bool boundaryLeave = false;
    std::set<NodeHandle> removeSet;
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
        if(itSites->second->tstamp < 0.0) { // node is dropped cause no pong has been received see below
            abnormalLeave = true;
            if(!(itSites->second->type & NEIGHBOR)) boundaryLeave = true;
            itSites->second->type = UNDEF;
            removeSet.insert( itSites->first );
        }
        else if(itSites->second->tstamp < simTime() - pingTimeout) { // node showed no activity for some time request pong and mark it to be dropped next time
            VastMessage *vastMsg = new VastMessage("PING");
            vastMsg->setCommand(PING);
            vastMsg->setBitLength(VAST_L(vastMsg));
            sendMessage(vastMsg, itSites->second->addr);
            itSites->second->tstamp = -1.0;
        }
    }
    if(abnormalLeave) {
        synchronizeApp();
        for( std::set<NodeHandle>::iterator it = removeSet.begin(); it != removeSet.end(); ++it) {
            removeNode( *it );
        }
        // removeNeighbors();
        if(boundaryLeave) {
            for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
                if(itSites->second->type & BOUNDARY) {
                    VastMessage *vastMsg = new VastMessage("ENCLOSING_NEIGHBORS_REQUEST");
                    vastMsg->setCommand(ENCLOSING_NEIGHBORS_REQUEST);
                    vastMsg->setBitLength(VAST_L(vastMsg));
                    sendMessage(vastMsg, itSites->second->addr);
                }
            }
        }
        //buildVoronoi();
        //removeNeighbors(); should be superfluous
    }
}

void Vast::processSecTimer (  )  [protected]
void Vast::removeNeighbors (  )  [protected]

Definition at line 549 of file Vast.cc.

Referenced by handleMove().

{
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end();) {
        // if current site is no neighbor remove it else go on to next site
        if(itSites->second->type == UNDEF) {
            // Debug output
            if(debugOutput)  EV << "[NeighborsList::removeNeighbors()]\n"
                                << "    Site at [" << itSites->second->coord.x << ", " << itSites->second->coord.y
                                << "] has been removed from list."
                                << endl;
            Positions.erase(itSites->second->coord);
            delete itSites->second;
            Sites.erase(itSites++);
        }
        else ++itSites;
    }
}

void Vast::removeNode ( NodeHandle  node  )  [protected]

Definition at line 352 of file Vast.cc.

Referenced by handleDiscardNode(), handleNodeLeave(), and processPingTimer().

{
    SiteMap::iterator itSites = Sites.find(node);
    if(itSites != Sites.end()) {
        Positions.erase(itSites->second->coord);
        delete itSites->second;
        Sites.erase(itSites);
    }
}

void Vast::sendDiscardNode ( VastMessage vastMsg  )  [protected]

Definition at line 1003 of file Vast.cc.

Referenced by handleUDPMessage().

{
    NodeHandle discardNode;
    discardNode.setIp(thisSite.addr.getIp());
    discardNode.setKey(vastMsg->getDestKey());
    // send message
    VastDiscardMessage *vastDiscardMsg = new VastDiscardMessage("DISCARD_NODE");
    vastDiscardMsg->setCommand(DISCARD_NODE);
    vastDiscardMsg->setDiscardNode(discardNode);
    // debug output
    if(debugOutput) EV << "[Vast::sendDiscardNode() @ " << thisSite.addr.getIp()
                       << " (" << thisSite.addr.getKey().toString(16) << ")]\n"
                       << "    Node " << thisSite.addr.getIp() << " is leaving the overlay."
                       << endl;
    vastDiscardMsg->setBitLength(VASTDISCARD_L(vastDiscardMsg));
    sendMessage(vastDiscardMsg, vastMsg->getSourceNode());
}

void Vast::sendMessage ( VastMessage vastMsg,
NodeHandle  destAddr 
) [protected]

Definition at line 1075 of file Vast.cc.

Referenced by handleEnclosingNeighborsRequest(), handleEvent(), handleJoin(), handleJoinAcknowledge(), handleJoinRequest(), handleMove(), handleNewNeighbors(), handleNodeGracefulLeaveNotification(), handleNodeMove(), handlePing(), processCheckCriticalTimer(), processDiscoveryTimer(), processPingTimer(), and sendDiscardNode().

{
    // collect statistics
    RECORD_STATS(
        switch(vastMsg->getCommand()) {
            case JOIN_REQUEST: {
                joinRequestBytesSent += vastMsg->getByteLength();
            } break;
            case JOIN_ACKNOWLEDGE: {
                joinAcknowledgeBytesSent += vastMsg->getByteLength();
            } break;
            case NODE_MOVE: {
                nodeMoveBytesSent += vastMsg->getByteLength();
            } break;
            case NEW_NEIGHBORS: {
                newNeighborsBytesSent += vastMsg->getByteLength();
            } break;
            case NODE_LEAVE: {
                nodeLeaveBytesSent += vastMsg->getByteLength();
            } break;
            case ENCLOSING_NEIGHBORS_REQUEST: {
                enclosingNeighborsRequestBytesSent += vastMsg->getByteLength();
            } break;
            case PING: {
                pingBytesSent += vastMsg->getByteLength();
            } break;
            case PONG: {
                pongBytesSent += vastMsg->getByteLength();
            } break;
            case DISCARD_NODE: {
                discardNodeBytesSent += vastMsg->getByteLength();
            } break;
        }
        bytesPerSecond += vastMsg->getByteLength();
    );

    // debug output
    if(debugOutput) EV << "[Vast::sendMessage() @ " << thisSite.addr.getIp()
                       << " (" << thisSite.addr.getKey().toString(16) << ")]\n"
                       << "    Node " << thisSite.addr.getIp() << " sending " << vastMsg->getName() << " to " << destAddr.getIp() << "."
                       << endl;
    // set vastbase message stuff
    vastMsg->setDestKey(destAddr.getKey());
    // fill in sender information only if we are not forwarding a message from another node
    // e.g. a joining node
    if(vastMsg->getSourceNode().isUnspecified()) {
        vastMsg->setSourceNode(thisSite.addr);
        vastMsg->setPos(thisSite.coord);
        vastMsg->setNeighborCount(Sites.size());
    }

    sendMessageToUDP(destAddr, vastMsg);
}

void Vast::sendToApp ( cMessage *  msg  )  [protected]

Definition at line 1065 of file Vast.cc.

Referenced by changeState(), handleMove(), handleNodeLeaveNotification(), handleUDPMessage(), processJoinTimer(), and synchronizeApp().

{
    // debug output
    if(debugOutput) EV << "[Vast::sendToApp() @ " << thisSite.addr.getIp()
                       << " (" << thisSite.addr.getKey().toString(16) << ")]\n"
                       << "    Node " << thisSite.addr.getIp() << " sending " << msg->getName() << " to application."
                       << endl;
    send(msg, "appOut");
}

void Vast::setBootstrapedIcon (  )  [protected]

Definition at line 1129 of file Vast.cc.

Referenced by changeState().

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

void Vast::synchronizeApp ( VastMoveMessage vastMoveMsg = NULL  )  [protected]

Definition at line 1021 of file Vast.cc.

Referenced by handleJoinAcknowledge(), handleJoinRequest(), handleMove(), handleNodeMove(), and processPingTimer().

{
    GameAPIListMessage *sgcMsg = new GameAPIListMessage("NEIGHBOR_UPDATE");
    sgcMsg->setCommand(NEIGHBOR_UPDATE);

    sgcMsg->setRemoveNeighborArraySize(Sites.size());
    sgcMsg->setAddNeighborArraySize(Sites.size() + 1);
    sgcMsg->setNeighborPositionArraySize(Sites.size() + 1);

    int remSize, addSize;
    remSize = addSize = 0;
    for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
        if(itSites->second->type == UNDEF) {
            sgcMsg->setRemoveNeighbor(remSize, itSites->second->addr);
            ++remSize;
        }
        else if(!itSites->second->isAdded) {
            sgcMsg->setAddNeighbor(addSize, itSites->second->addr);
            sgcMsg->setNeighborPosition(addSize, itSites->second->coord);
            itSites->second->isAdded = true;
            ++addSize;
        }
    }

    if(vastMoveMsg &&
       Sites.find(vastMoveMsg->getSourceNode()) != Sites.end() &&
       Sites.find(vastMoveMsg->getSourceNode())->second->isAdded) {
        sgcMsg->setAddNeighbor(addSize, vastMoveMsg->getSourceNode());
        sgcMsg->setNeighborPosition(addSize, vastMoveMsg->getNewPos());
        ++addSize;
    }

    sgcMsg->setRemoveNeighborArraySize(remSize);
    sgcMsg->setAddNeighborArraySize(addSize);
    sgcMsg->setNeighborPositionArraySize(addSize);

    if(sgcMsg->getAddNeighborArraySize() || sgcMsg->getRemoveNeighborArraySize()) {
        sendToApp(sgcMsg);
    }
    else {
        delete sgcMsg;
    }
}


Member Data Documentation

double Vast::AOI_size [protected]

Definition at line 64 of file Vast.h.

Referenced by buildVoronoi(), changeState(), getAOI(), and initializeOverlay().

double Vast::areaDimension [protected]

Definition at line 65 of file Vast.h.

Referenced by getAreaDimension(), and initializeOverlay().

Definition at line 80 of file Vast.h.

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

long Vast::bytesPerSecond [protected]

Definition at line 80 of file Vast.h.

Referenced by initializeOverlay(), processSecTimer(), and sendMessage().

cMessage* Vast::checkcritical_timer [protected]

Definition at line 105 of file Vast.h.

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

simtime_t Vast::checkCriticalIntervall [protected]

Definition at line 85 of file Vast.h.

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

double Vast::criticalThreshold [protected]

Definition at line 86 of file Vast.h.

Referenced by initializeOverlay(), and processCheckCriticalTimer().

bool Vast::debugVoronoiOutput [protected]

Definition at line 84 of file Vast.h.

Referenced by initializeOverlay().

long Vast::discardNodeBytesSent [protected]

Definition at line 78 of file Vast.h.

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

cMessage* Vast::discovery_timer [protected]

Definition at line 104 of file Vast.h.

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

simtime_t Vast::discoveryIntervall [protected]

Definition at line 85 of file Vast.h.

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

EdgeList Vast::edgelist [protected]

Definition at line 91 of file Vast.h.

Referenced by buildVoronoi().

Definition at line 75 of file Vast.h.

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

Geometry Vast::geom [protected]

Definition at line 90 of file Vast.h.

Referenced by buildVoronoi(), and initializeOverlay().

HeapPQ Vast::heap [protected]

Definition at line 92 of file Vast.h.

Referenced by buildVoronoi().

cMessage* Vast::join_timer [protected]

Definition at line 102 of file Vast.h.

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

Definition at line 71 of file Vast.h.

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

long Vast::joinRequestBytesSent [protected]

Definition at line 70 of file Vast.h.

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

simtime_t Vast::joinTimeout [protected]

Definition at line 85 of file Vast.h.

Referenced by handleTimerEvent(), and initializeOverlay().

long Vast::maxBytesPerSecondSent [protected]

Definition at line 80 of file Vast.h.

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

long Vast::newNeighborsBytesSent [protected]

Definition at line 73 of file Vast.h.

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

long Vast::nodeLeaveBytesSent [protected]

Definition at line 74 of file Vast.h.

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

long Vast::nodeMoveBytesSent [protected]

Definition at line 72 of file Vast.h.

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

cMessage* Vast::ping_timer [protected]

Definition at line 103 of file Vast.h.

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

long Vast::pingBytesSent [protected]

Definition at line 76 of file Vast.h.

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

simtime_t Vast::pingTimeout [protected]

Definition at line 85 of file Vast.h.

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

long Vast::pongBytesSent [protected]

Definition at line 77 of file Vast.h.

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

Definition at line 66 of file Vast.h.

Referenced by addNode(), handleMove(), initializeOverlay(), removeNeighbors(), removeNode(), and ~Vast().

cMessage* Vast::sec_timer [protected]

Definition at line 106 of file Vast.h.

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

unsigned int Vast::secTimerCount [protected]

Definition at line 81 of file Vast.h.

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

StockList Vast::Stock [protected]

Definition at line 67 of file Vast.h.

Referenced by addNodeToStock(), and processDiscoveryTimer().

unsigned long Vast::stockListSize [protected]

Definition at line 87 of file Vast.h.

Referenced by addNodeToStock(), and initializeOverlay().


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