Vast.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #include "Vast.h"
00025 
00026 Define_Module(Vast);
00027 
00028 #include <NotifierConsts.h>
00029 
00030 #include <GlobalNodeList.h>
00031 #include <GlobalStatistics.h>
00032 #include <BootstrapList.h>
00033 
00034 void Vast::initializeOverlay(int stage)
00035 {
00036     // because of IPAddressResolver, we need to wait until interfaces are registered,
00037     // address auto-assignment takes place etc.
00038     if(stage != MIN_STAGE_OVERLAY) return;
00039 
00040     // fetch parameters
00041     debugVoronoiOutput = par("debugVastOutput");
00042     areaDimension = par("areaDimension");
00043     AOI_size = par("AOIWidth");
00044     joinTimeout = par("joinTimeout");
00045     pingTimeout = par("pingTimeout");
00046     discoveryIntervall = par("discoveryIntervall");
00047     checkCriticalIntervall = par("criticalCheckIntervall");
00048     criticalThreshold = par("criticalThreshold");
00049     stockListSize = par("stockListSize");
00050 
00051     // set node key
00052     thisNode.key = OverlayKey::random();
00053     thisSite.type = THIS;
00054     thisSite.addr = thisNode;
00055 
00056     geom.setDebug(debugOutput);
00057 
00058     // self-messages
00059     join_timer = new cMessage("join_timer");
00060     ping_timer = new cMessage("ping_timer");
00061     sec_timer = new cMessage("sec_timer");
00062     discovery_timer = new cMessage("discovery_timer");
00063     checkcritical_timer = new cMessage("checkcritical_timer");
00064 
00065     // statistics
00066     joinRequestBytesSent = 0;
00067     joinAcknowledgeBytesSent = 0;
00068     nodeMoveBytesSent = 0;
00069     newNeighborsBytesSent = 0;
00070     nodeLeaveBytesSent = 0;
00071     enclosingNeighborsRequestBytesSent = 0;
00072     pingBytesSent = 0;
00073     pongBytesSent = 0;
00074     discardNodeBytesSent = 0;
00075 
00076     maxBytesPerSecondSent = 0;
00077     averageBytesPerSecondSent = 0;
00078     bytesPerSecond = 0;
00079 
00080     // watch some variables
00081     WATCH(AOI_size);
00082     WATCH(thisSite);
00083     WATCH_MAP(Sites);
00084     WATCH_SET(Positions);
00085 
00086     WATCH(joinRequestBytesSent);
00087     WATCH(joinAcknowledgeBytesSent);
00088     WATCH(nodeMoveBytesSent);
00089     WATCH(newNeighborsBytesSent);
00090     WATCH(nodeLeaveBytesSent);
00091     WATCH(enclosingNeighborsRequestBytesSent);
00092     WATCH(pingBytesSent);
00093     WATCH(pongBytesSent);
00094     WATCH(discardNodeBytesSent);
00095 
00096     WATCH(maxBytesPerSecondSent);
00097     WATCH(bytesPerSecond);
00098 
00099     // set initial state
00100     changeState(INIT);
00101     changeState(JOINING);
00102 }
00103 
00104 void Vast::changeState(int state)
00105 {
00106     switch(state) {
00107         case INIT: {
00108             this->state = INIT;
00109             globalNodeList->removePeer(thisSite.addr);
00110             cancelEvent(join_timer);
00111             cancelEvent(ping_timer);
00112             cancelEvent(sec_timer);
00113             cancelEvent(discovery_timer);
00114             cancelEvent(checkcritical_timer);
00115         } break;
00116         case JOINING: {
00117             this->state = JOINING;
00118             scheduleAt(simTime(), join_timer);
00119             scheduleAt(simTime() + 1.0, sec_timer);
00120         } break;
00121         case READY: {
00122             this->state = READY;
00123             cancelEvent(join_timer);
00124             globalNodeList->registerPeer(thisSite.addr);
00125             scheduleAt(simTime() + pingTimeout, ping_timer);
00126             if(checkCriticalIntervall > 0.0 && discoveryIntervall > 0.0) {
00127                 scheduleAt(simTime() + checkCriticalIntervall, checkcritical_timer);
00128                 scheduleAt(simTime() + discoveryIntervall, discovery_timer);
00129             }
00130             // tell the application we are ready
00131             CompReadyMessage* readyMsg = new CompReadyMessage("OVERLAY_READY");
00132             readyMsg->setReady(true);
00133             readyMsg->setComp(getThisCompType());
00134             sendToApp(readyMsg);
00135             GameAPIResizeAOIMessage* gameMsg = new GameAPIResizeAOIMessage("RESIZE_AOI");
00136             gameMsg->setCommand(RESIZE_AOI);
00137             gameMsg->setAOIsize(AOI_size);
00138             sendToApp(gameMsg);
00139         } break;
00140     }
00141     setBootstrapedIcon();
00142     // debug output
00143     if(debugOutput) {
00144         EV << "[Vast::changeState() @ " << thisSite.addr.ip
00145            << " (" << thisSite.addr.key.toString(16) << ")]\n"
00146            << "VAST: Node " << thisSite.addr.ip << " entered ";
00147         switch(state) {
00148             case INIT: ev << "INIT"; break;
00149             case JOINING: ev << "JOINING"; break;
00150             case READY: ev << "READY"; break;
00151         }
00152         ev << " state." << endl;
00153     }
00154 }
00155 
00156 void Vast::handleTimerEvent(cMessage* msg)
00157 {
00158     if(msg->isName("join_timer")) {
00159         //reset timer
00160         cancelEvent(join_timer);
00161         scheduleAt(simTime() + joinTimeout, msg);
00162         // handle event
00163         processJoinTimer();
00164     }
00165     else if(msg->isName("ping_timer")) {
00166         //reset timer
00167         cancelEvent(ping_timer);
00168         scheduleAt(simTime() + pingTimeout, msg);
00169         // handle event
00170         processPingTimer();
00171     }
00172     else if(msg->isName("sec_timer")) {
00173         //reset timer
00174         cancelEvent(sec_timer);
00175         scheduleAt(simTime() + 1, msg);
00176         // handle event
00177         processSecTimer();
00178     }
00179     else if(msg->isName("checkcritical_timer")) {
00180         //reset timer
00181         cancelEvent(checkcritical_timer);
00182         scheduleAt(simTime() + checkCriticalIntervall, msg);
00183         // handle event
00184         processCheckCriticalTimer();
00185     }
00186     else if(msg->isName("discovery_timer")) {
00187         //reset timer
00188         cancelEvent(discovery_timer);
00189         scheduleAt(simTime() + discoveryIntervall, msg);
00190         // handle event
00191         processDiscoveryTimer();
00192     }
00193 }
00194 
00195 void Vast::handleAppMessage(cMessage* msg)
00196 {
00197     if(dynamic_cast<GameAPIMessage*>(msg)) {
00198         GameAPIMessage* gameAPIMsg = check_and_cast<GameAPIMessage*>(msg);
00199         // debug output
00200         if(debugOutput) EV << "[Vast::handleAppMessage() @ " << thisSite.addr.ip
00201                            << " (" << thisSite.addr.key.toString(16) << ")]\n"
00202                            << "    Node " << thisSite.addr.ip << " received " << gameAPIMsg->getName() << " from application."
00203                            << endl;
00204         switch(gameAPIMsg->getCommand()) {
00205             case MOVEMENT_INDICATION: {
00206                 GameAPIPositionMessage* gameAPIPosMsg = check_and_cast<GameAPIPositionMessage*>(msg);
00207                 if(state == JOINING) {
00208                     handleJoin(gameAPIPosMsg);
00209                     delete msg;
00210                 }
00211                 else if(state == READY) {
00212                     handleMove(gameAPIPosMsg);
00213                     delete msg;
00214                 }
00215             } break;
00216             case GAMEEVENT_CHAT:
00217             case GAMEEVENT_SNOW:
00218             case GAMEEVENT_FROZEN:
00219                 handleEvent( gameAPIMsg );
00220                 delete msg;
00221                 break;
00222             default: {
00223                 delete msg;
00224             }
00225         }
00226     }
00227     else delete msg;
00228 }
00229 
00230 void Vast::handleUDPMessage(BaseOverlayMessage* msg)
00231 {
00232     if(state == INIT) {
00233         delete msg;
00234         return;
00235     }
00236     if(dynamic_cast<VastMessage*>(msg)) {
00237         VastMessage* vastMsg = check_and_cast<VastMessage*>(msg);
00238         if(vastMsg->getDestKey().isUnspecified() || 
00239            thisSite.addr.key.isUnspecified() ||
00240            vastMsg->getDestKey() == thisSite.addr.key) {
00241             // debug output
00242             if(debugOutput) EV << "[Vast::handleUDPMessage() @ " << thisSite.addr.ip
00243                                << " (" << thisSite.addr.key.toString(16) << ")]\n"
00244                                << "    Node " << thisSite.addr.ip << " received " << vastMsg->getName() << " from " << vastMsg->getSourceNode().ip
00245                                << endl;
00246             bool doUpdate = true;
00247             if(state == READY) {
00248                 switch(vastMsg->getCommand()) {
00249                     case JOIN_REQUEST: {
00250                         handleJoinRequest(vastMsg);
00251                         doUpdate = false;
00252                     } break;
00253                     case NODE_MOVE: {
00254                         VastMoveMessage* vastMoveMsg = check_and_cast<VastMoveMessage*>(msg);
00255                         handleNodeMove(vastMoveMsg);
00256                     } break;
00257                     case NEW_NEIGHBORS: {
00258                         VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
00259                         handleNewNeighbors(vastListMsg);
00260                     } break;
00261                     case NODE_LEAVE: {
00262                         VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
00263                         handleNodeLeave(vastListMsg);
00264                     } break;
00265                     case ENCLOSING_NEIGHBORS_REQUEST: {
00266                         handleEnclosingNeighborsRequest(vastMsg);
00267                     } break;
00268                     case BACKUP_NEIGHBORS: {
00269                         VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
00270                         handleBackupNeighbors(vastListMsg);
00271                     } break;
00272                     case PING: {
00273                         handlePing(vastMsg);
00274                     } break;
00275                     case PONG: {
00276                         handlePong(vastMsg);
00277                     } break;
00278                     case DISCARD_NODE: {
00279                         VastDiscardMessage* vastDiscardMsg = check_and_cast<VastDiscardMessage*>(msg);
00280                         handleDiscardNode(vastDiscardMsg);
00281                     } break;
00282                     case VAST_EVENT: {
00283                         sendToApp(vastMsg->decapsulate());
00284                         doUpdate = false;
00285                         delete vastMsg;
00286                     } break;
00287                 }
00288                 // update timestamp
00289                 if(doUpdate) {
00290                     SiteMap::iterator itSites = Sites.find(vastMsg->getSourceNode());
00291                     if(itSites != Sites.end()) {
00292                         itSites->second->tstamp = simTime();
00293                     }
00294                     delete msg;
00295                 }
00296             }
00297             else if(state == JOINING && vastMsg->getCommand() == JOIN_ACKNOWLEDGE) {
00298                 VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
00299                 handleJoinAcknowledge(vastListMsg);
00300                 delete msg;
00301             }
00302             else delete msg;
00303         }
00304         else {
00305             sendDiscardNode(vastMsg);
00306             delete msg;
00307         }
00308     }
00309     else delete msg;
00310 }
00311 
00312 void Vast::addNode(Vector2D p, NodeHandle node, int NeighborCount)
00313 {
00314     if(node != thisSite.addr) {
00315         if(Sites.find(node) == Sites.end()) {
00316             Site* temp_site = new Site();
00317             temp_site->coord = p;
00318             temp_site->addr = node;
00319             temp_site->neighborCount = NeighborCount;
00320 
00321             Sites.insert(std::make_pair(temp_site->addr, temp_site));
00322             Positions.insert(temp_site->coord);
00323         }
00324         else {
00325             SiteMap::iterator itSites = Sites.find(node);
00326             Positions.erase(itSites->second->coord);
00327             itSites->second->coord = p;
00328             Positions.insert(itSites->second->coord);
00329             if(NeighborCount != 0) {
00330                 itSites->second->neighborCount = NeighborCount;
00331             }
00332         }
00333     }
00334 }
00335 
00336 void Vast::addNodeToStock(NodeHandle node)
00337 {
00338     if(node != thisSite.addr) {
00339         for(StockList::iterator itTemp = Stock.begin(); itTemp != Stock.end(); ++itTemp) {
00340             if(*itTemp == node) {
00341                 return;
00342             }
00343         }
00344         Stock.push_front(node);
00345         if(Stock.size() > stockListSize) {
00346             Stock.pop_back();
00347         }
00348     }
00349 }
00350 
00351 void Vast::removeNode(NodeHandle node)
00352 {
00353     SiteMap::iterator itSites = Sites.find(node);
00354     if(itSites != Sites.end()) {
00355         Positions.erase(itSites->second->coord);
00356         delete itSites->second;
00357         Sites.erase(itSites);
00358     }
00359 }
00360 
00361 void Vast::buildVoronoi(Vector2D old_pos, Vector2D new_pos)
00362 {
00363     int sqrt_nsites = 1;
00364     double xmin, xmax, ymin, ymax;
00365     double deltax, deltay;
00366 
00367     // check wether there are any neighbors
00368     if(Sites.size() == 0) return;
00369 
00370     xmin = xmax = thisSite.coord.x;
00371     ymin = ymax = thisSite.coord.y;
00372 
00373     std::map<Vector2D, Site*> sortedSites;
00374     sortedSites.insert(std::make_pair(thisSite.coord, &thisSite));
00375 
00376     for(SiteMap::iterator itTemp = Sites.begin(); itTemp != Sites.end(); ++itTemp) {
00377         // determine min/max site coordinates
00378         if(itTemp->second->coord.x < xmin) xmin = itTemp->second->coord.x;
00379         if(itTemp->second->coord.x > xmax) xmax = itTemp->second->coord.x;
00380         if(itTemp->second->coord.y < ymin) ymin = itTemp->second->coord.y;
00381         if(itTemp->second->coord.y > ymax) ymax = itTemp->second->coord.y;
00382         // reset all sites to UNDEF
00383         itTemp->second->type = UNDEF;
00384         // fill sorted List
00385         sortedSites.insert(std::make_pair(itTemp->second->coord, itTemp->second));
00386         sqrt_nsites++;
00387     }
00388 
00389     // needed to determine appropriate hashtable size
00390     deltax = xmax - xmin;
00391     deltay = ymax - ymin;
00392     sqrt_nsites = (int)sqrt((double)(sqrt_nsites+4));
00393 
00394     // start to calculate the voronoi
00395     Site *newsite, *bot, *top, *temp, *p, *v, *bottomsite;
00396     Vector2D newintstar;
00397     int pm;
00398     Halfedge *lbnd, *rbnd, *llbnd, *rrbnd, *bisector;
00399     Edge *e;
00400 
00401     newintstar.x = newintstar.y = 0.0;
00402 
00403     std::map<Vector2D, Site*>::iterator itSortedSites = sortedSites.begin();
00404 
00405     geom.initialize(deltax, deltay, thisSite.coord, old_pos, new_pos, AOI_size);
00406     heap.PQinitialize(sqrt_nsites, ymin, deltay);
00407     bottomsite = itSortedSites->second;
00408     ++itSortedSites;
00409     edgelist.initialize(sqrt_nsites, xmin, deltax, bottomsite);
00410 
00411     newsite = itSortedSites->second;
00412     ++itSortedSites;
00413     while(true) {
00414         if(!heap.PQempty()) newintstar = heap.PQ_min();
00415 
00416         if(newsite != NULL && (heap.PQempty() ||
00417            newsite->coord.y < newintstar.y ||
00418            (newsite->coord.y == newintstar.y && newsite->coord.x < newintstar.x))) {
00419             lbnd = edgelist.ELleftbnd(&(newsite->coord));
00420             rbnd = edgelist.ELright(lbnd);
00421             bot = edgelist.rightreg(lbnd);
00422             e = geom.bisect(bot, newsite);
00423             bisector = edgelist.HEcreate(e, le);
00424             edgelist.ELinsert(lbnd, bisector);
00425             if ((p = geom.intersect(lbnd, bisector)) != NULL) {
00426                 heap.PQdelete(lbnd);
00427                 heap.PQinsert(lbnd, p, geom.dist(p, newsite));
00428             }
00429             lbnd = bisector;
00430             bisector = edgelist.HEcreate(e, re);
00431             edgelist.ELinsert(lbnd, bisector);
00432             if ((p = geom.intersect(bisector, rbnd)) != NULL) heap.PQinsert(bisector, p, geom.dist(p, newsite));
00433             if(itSortedSites != sortedSites.end()) {
00434                 newsite = itSortedSites->second;
00435                 ++itSortedSites;
00436             }
00437             else newsite = NULL;
00438         }
00439         else if (!heap.PQempty()) {
00440             lbnd = heap.PQextractmin();
00441             llbnd = edgelist.ELleft(lbnd);
00442             rbnd = edgelist.ELright(lbnd);
00443             rrbnd = edgelist.ELright(rbnd);
00444             bot = edgelist.leftreg(lbnd);
00445             top = edgelist.rightreg(rbnd);
00446             v = lbnd->vertex;
00447             geom.endpoint(lbnd->ELedge, lbnd->ELpm, v);
00448             geom.endpoint(rbnd->ELedge, rbnd->ELpm, v);
00449             edgelist.ELdelete(lbnd);
00450             heap.PQdelete(rbnd);
00451             edgelist.ELdelete(rbnd);
00452             pm = le;
00453             if (bot->coord.y > top->coord.y) {
00454                 temp = bot;
00455                 bot = top;
00456                 top = temp;
00457                 pm = re;
00458             }
00459             e = geom.bisect(bot, top);
00460             bisector = edgelist.HEcreate(e, pm);
00461             edgelist.ELinsert(llbnd, bisector);
00462             geom.endpoint(e, re-pm, v);
00463             if((p = geom.intersect(llbnd, bisector)) != NULL) {
00464                 heap.PQdelete(llbnd);
00465                 heap.PQinsert(llbnd, p, geom.dist(p, bot));
00466             }
00467             if ((p = geom.intersect(bisector, rrbnd)) != NULL) heap.PQinsert(bisector, p, geom.dist(p, bot));
00468         }
00469         else break;
00470     }
00471 
00472     // process the generated edgelist
00473     for(lbnd = edgelist.ELright(edgelist.ELleftend); lbnd != edgelist.ELrightend; lbnd = edgelist.ELright(lbnd)) {
00474         e = lbnd -> ELedge;
00475         geom.processEdge(e);
00476     }
00477     // process sites in order to determine our neighbors
00478     for(SiteMap::iterator itTemp = Sites.begin(); itTemp != Sites.end(); ++itTemp) {
00479         if(itTemp->second->innerEdge[0]) {
00480             if(itTemp->second->outerEdge) {
00481                 itTemp->second->type |= BOUNDARY;
00482                 // Debug output
00483                 if(debugOutput)
00484                     EV << "[NeighborsList::buildVoronoi()]\n"
00485                        << "    Site at [" << itTemp->second->coord.x << ", "
00486                        << itTemp->second->coord.y << "] is a boundary neighbor."
00487                        << endl;
00488             }
00489             else {
00490                 itTemp->second->type |= NEIGHBOR;
00491                 // Debug output
00492                 if(debugOutput)
00493                     EV << "[NeighborsList::buildVoronoi()]\n"
00494                        << "    Site at [" << itTemp->second->coord.x << ", "
00495                        << itTemp->second->coord.y << "] is a neighbor."
00496                        << endl;
00497             }
00498         }
00499         if(!itTemp->second->innerEdge[1] && itTemp->second->innerEdge[2]) {
00500             itTemp->second->type |= NEW;
00501             // Debug output
00502             if(debugOutput)
00503                 EV << "[NeighborsList::buildVoronoi()]\n"
00504                    << "    Site at [" << itTemp->second->coord.x << ", "
00505                    << itTemp->second->coord.y << "] is a new neighbor for site at " << new_pos.x << ":" << new_pos.y << "."
00506                    << endl;
00507         }
00508         // reset inner- and outeredge indicator
00509         itTemp->second->innerEdge[0] = false;
00510         itTemp->second->innerEdge[1] = false;
00511         itTemp->second->innerEdge[2] = false;
00512         itTemp->second->outerEdge = false;
00513     }
00514     // clean up
00515     edgelist.reset();
00516     heap.PQreset();
00517     geom.reset();
00518 }
00519 
00520 void Vast::buildVoronoi()
00521 {
00522     buildVoronoi(thisSite.coord, thisSite.coord);
00523 }
00524 
00525 void Vast::removeNeighbors()
00526 {
00527     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end();) {
00528         // if current site is no neighbor remove it else go on to next site
00529         if(itSites->second->type == UNDEF) {
00530             // Debug output
00531             if(debugOutput)  EV << "[NeighborsList::removeNeighbors()]\n"
00532                                 << "    Site at [" << itSites->second->coord.x << ", " << itSites->second->coord.y
00533                                 << "] has been removed from list."
00534                                 << endl;
00535             Positions.erase(itSites->second->coord);
00536             delete itSites->second;
00537             Sites.erase(itSites++);
00538         }
00539         else ++itSites;
00540     }
00541 }
00542 
00543 void Vast::handleNodeLeaveNotification()
00544 {
00545     if(state == READY) {
00546         // debug output
00547         if(debugOutput) {
00548             EV << "[Vast::receiveChangeNotification() @ " << thisSite.addr.ip
00549                << " (" << thisSite.addr.key.toString(16) << ")]\n"
00550                << "    Node " << thisSite.addr.ip << " is leaving the overlay."
00551                << endl;
00552         }
00553 
00554         CompReadyMessage* readyMsg = new CompReadyMessage("OVERLAY_FINISHED");
00555         readyMsg->setReady(false);
00556         readyMsg->setComp(getThisCompType());
00557         sendToApp(readyMsg);
00558     }
00559 }
00560 
00561 void Vast::handleNodeGracefulLeaveNotification()
00562 {
00563      if(state == READY) {
00564         // generate node leave messages
00565         VastListMessage *vastListMsg = new VastListMessage("NODE_LEAVE");
00566         vastListMsg->setCommand(NODE_LEAVE);
00567         // fill neighbors list
00568         vastListMsg->setNeighborNodeArraySize(Sites.size());
00569         vastListMsg->setNeighborPosArraySize(Sites.size());
00570         int i = 0;
00571         for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00572             if(itSites->second->type & ENCLOSING) {
00573                 vastListMsg->setNeighborNode(i, itSites->second->addr);
00574                 vastListMsg->setNeighborPos(i, itSites->second->coord);
00575                 ++i;
00576             }
00577         }
00578         vastListMsg->setNeighborNodeArraySize(i);
00579         vastListMsg->setNeighborPosArraySize(i);
00580 
00581         vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
00582         if(vastListMsg->getNeighborNodeArraySize() > 0) {
00583             for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00584                 VastListMessage *vastCopyMsg = new VastListMessage(*vastListMsg);
00585                sendMessage(vastCopyMsg, itSites->second->addr);
00586             }
00587         }
00588         delete vastListMsg;
00589         changeState(INIT);
00590     }
00591 }
00592 
00593 void Vast::processJoinTimer()
00594 {
00595     GameAPIMessage *sgcMsg = new GameAPIMessage("MOVEMENT_REQUEST");
00596     sgcMsg->setCommand(MOVEMENT_REQUEST);
00597     sendToApp(sgcMsg);
00598 }
00599 
00600 void Vast::processPingTimer()
00601 {
00602     bool abnormalLeave = false;
00603     bool boundaryLeave = false;
00604     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00605         if(itSites->second->tstamp < 0.0) { // node is dropped cause no pong has been received see below
00606             abnormalLeave = true;
00607             if(!(itSites->second->type & NEIGHBOR)) boundaryLeave = true;
00608             itSites->second->type = UNDEF;
00609         }
00610         else if(itSites->second->tstamp < simTime() - pingTimeout) { // node showed no activity for some time request pong and mark it to be dropped next time
00611             VastMessage *vastMsg = new VastMessage("PING");
00612             vastMsg->setCommand(PING);
00613             vastMsg->setBitLength(VAST_L(vastMsg));
00614             sendMessage(vastMsg, itSites->second->addr);
00615             itSites->second->tstamp = -1.0;
00616         }
00617     }
00618     if(abnormalLeave) {
00619         synchronizeApp();
00620         removeNeighbors();
00621         if(boundaryLeave) {
00622             for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00623                 if(itSites->second->type & BOUNDARY) {
00624                     VastMessage *vastMsg = new VastMessage("ENCLOSING_NEIGHBORS_REQUEST");
00625                     vastMsg->setCommand(ENCLOSING_NEIGHBORS_REQUEST);
00626                     vastMsg->setBitLength(VAST_L(vastMsg));
00627                     sendMessage(vastMsg, itSites->second->addr);
00628                 }
00629             }
00630         }
00631         buildVoronoi();
00632         //removeNeighbors(); should be superfluous
00633     }
00634 }
00635 
00636 void Vast::processSecTimer()
00637 {
00638     if(bytesPerSecond > maxBytesPerSecondSent) {
00639         maxBytesPerSecondSent = bytesPerSecond;
00640     }
00641     averageBytesPerSecondSent += bytesPerSecond;
00642     bytesPerSecond = 0;
00643 }
00644 
00645 void Vast::processCheckCriticalTimer()
00646 {
00647     double NeighborLevel;
00648     int NeighborSum = 0;
00649     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00650         if(itSites->second->neighborCount > 0) {
00651             NeighborSum += itSites->second->neighborCount;
00652         }
00653     }
00654     NeighborLevel = (double)(Sites.size() * Sites.size()) / (double)NeighborSum;
00655 
00656     if(NeighborLevel < criticalThreshold) {
00657         VastListMessage *vastListMsg = new VastListMessage("BACKUP_NEIGHBORS");
00658         vastListMsg->setCommand(BACKUP_NEIGHBORS);
00659         // fill neighbors list
00660         vastListMsg->setNeighborNodeArraySize(Sites.size());
00661         vastListMsg->setNeighborPosArraySize(Sites.size());
00662         int i = 0;
00663         for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00664             vastListMsg->setNeighborNode(i, itSites->second->addr);
00665             vastListMsg->setNeighborPos(i, itSites->second->coord);
00666             ++i;
00667         }
00668         vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
00669         for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00670             VastListMessage *vastCopyMsg = new VastListMessage(*vastListMsg);
00671             sendMessage(vastCopyMsg, itSites->second->addr);
00672         }
00673         delete vastListMsg;
00674     }
00675 }
00676 
00677 void Vast::processDiscoveryTimer()
00678 {
00679     for(StockList::iterator itStock = Stock.begin(); itStock != Stock.end(); ++itStock) {
00680         VastMoveMessage *vastMoveMsg = new VastMoveMessage("NODE_MOVE");
00681         vastMoveMsg->setCommand(NODE_MOVE);
00682         vastMoveMsg->setNewPos(thisSite.coord);
00683         vastMoveMsg->setRequest_list(true);
00684         vastMoveMsg->setBitLength(VASTMOVE_L(vastMoveMsg));
00685         sendMessage(vastMoveMsg, *itStock);
00686     }
00687 }
00688 
00689 void Vast::handleJoin(GameAPIPositionMessage *sgcMsg)
00690 {
00691     TransportAddress joinNode = bootstrapList->getBootstrapNode();
00692     thisSite.coord = sgcMsg->getPosition();
00693     // check if this is the only node in the overlay
00694     if(joinNode.isUnspecified()) {
00695         changeState(READY);
00696     }
00697     else {
00698         VastMessage *vastMsg = new VastMessage("JOIN_REQUEST");
00699         vastMsg->setCommand(JOIN_REQUEST);
00700         vastMsg->setBitLength(VAST_L(vastMsg));
00701         sendMessage(vastMsg, joinNode);
00702     }
00703 }
00704 
00705 void Vast::handleMove(GameAPIPositionMessage* sgcMsg)
00706 {
00707     Vector2D pos = sgcMsg->getPosition();
00708     // test if new position is legal
00709     if(Positions.find(pos) != Positions.end()) {
00710         GameAPIMessage *gameMsg = new GameAPIMessage("MOVEMENT_REQUEST");
00711         gameMsg->setCommand(MOVEMENT_REQUEST);
00712         sendToApp(gameMsg);
00713         return;
00714     }
00715     // send position update to neighbors
00716     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00717         VastMoveMessage *vastMoveMsg = new VastMoveMessage("NODE_MOVE");
00718         vastMoveMsg->setCommand(NODE_MOVE);
00719         vastMoveMsg->setNewPos(pos);
00720         vastMoveMsg->setIs_boundary(itSites->second->type & BOUNDARY);
00721         vastMoveMsg->setBitLength(VASTMOVE_L(vastMoveMsg));
00722         sendMessage(vastMoveMsg, itSites->second->addr);
00723     }
00724     // set new position
00725     thisSite.coord = pos;
00726     // update voronoi
00727     buildVoronoi();
00728     synchronizeApp();
00729     removeNeighbors();
00730 }
00731 
00732 void Vast::handleEvent( GameAPIMessage* msg )
00733 {
00734     // send event to neighbors
00735     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00736         VastEventMessage *vastMsg = new VastEventMessage("EVENT");
00737         vastMsg->setCommand(VAST_EVENT);
00738         vastMsg->encapsulate((cPacket*)msg->dup());
00739         // FIXME: Message length!
00740         sendMessage(vastMsg, itSites->second->addr);
00741     }
00742 }
00743 
00744 void Vast::handleJoinRequest(VastMessage *vastMsg)
00745 {
00746     Site *forwardSite = NULL;
00747     // start with this node
00748     double min_dist = thisSite.coord.distanceSqr(vastMsg->getPos());
00749     forwardSite = &thisSite;
00750     // iterate through all neighbors
00751     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00752         // dont forward to nodes which are still joining
00753         if(itSites->second->coord.distanceSqr(vastMsg->getPos()) < min_dist && itSites->second->neighborCount >= 0) {
00754             min_dist = itSites->second->coord.distanceSqr(vastMsg->getPos());
00755             forwardSite = itSites->second;
00756         }
00757     }
00758     // do nothing and let node retry with new position if current position is illegal
00759     if(min_dist == 0.0) {
00760         delete vastMsg;
00761     }
00762     else {
00763         // send an acknowledge or forward request if any of our neighbors is closer to joining node
00764         if(forwardSite->type & THIS) {
00765             VastListMessage *vastListMsg = new VastListMessage("JOIN_ACKNOWLEDGE");
00766             vastListMsg->setCommand(JOIN_ACKNOWLEDGE);
00767             // fill neighbors list
00768             vastListMsg->setNeighborNodeArraySize(Sites.size());
00769             vastListMsg->setNeighborPosArraySize(Sites.size());
00770             int i = 0;
00771             for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00772                 vastListMsg->setNeighborNode(i, itSites->second->addr);
00773                 vastListMsg->setNeighborPos(i, itSites->second->coord);
00774                 ++i;
00775             }
00776 
00777             vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
00778             sendMessage(vastListMsg, vastMsg->getSourceNode());
00779 
00780             // add node to list to propagte its position early
00781             // nieghborCount is set to -1 to indicate node is still joining
00782             addNode(vastMsg->getPos(), vastMsg->getSourceNode(), -1);
00783             // update voronoi with new neighbors
00784             buildVoronoi();
00785             synchronizeApp();
00786             removeNeighbors();
00787             delete vastMsg;
00788         }
00789         else {
00790             sendMessage(vastMsg, forwardSite->addr);
00791         }
00792     }
00793 }
00794 
00795 void Vast::handleJoinAcknowledge(VastListMessage *vastListMsg)
00796 {
00797     // add acceptor node
00798     changeState(READY);
00799     addNode(vastListMsg->getPos(), vastListMsg->getSourceNode(), vastListMsg->getNeighborCount());
00800     // add new neighbors
00801     for(unsigned int i=0; i<vastListMsg->getNeighborNodeArraySize(); i++) {
00802         addNode(vastListMsg->getNeighborPos(i), vastListMsg->getNeighborNode(i));
00803     }
00804     // update voronoi with new neighbors
00805     buildVoronoi();
00806     synchronizeApp();
00807     removeNeighbors();
00808     // contact new neighbors
00809     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00810         VastMoveMessage *vastMoveMsg = new VastMoveMessage("NODE_MOVE");
00811         vastMoveMsg->setCommand(NODE_MOVE);
00812         vastMoveMsg->setNewPos(thisSite.coord);
00813         vastMoveMsg->setIs_boundary(itSites->second->type & BOUNDARY);
00814         vastMoveMsg->setRequest_list(true);
00815         vastMoveMsg->setBitLength(VASTMOVE_L(vastMoveMsg));
00816         sendMessage(vastMoveMsg, itSites->second->addr);
00817     }
00818 }
00819 
00820 void Vast::handleNodeMove(VastMoveMessage *vastMoveMsg)
00821 {
00822     RECORD_STATS(
00823             globalStatistics->addStdDev(
00824                 "Vast: MoveDelay",
00825                 SIMTIME_DBL(simTime()) - SIMTIME_DBL(vastMoveMsg->getCreationTime())
00826                 );
00827             );
00828 
00829     Vector2D old_p, new_p;
00830     old_p = vastMoveMsg->getPos();
00831     new_p = vastMoveMsg->getNewPos();
00832     addNode(new_p, vastMoveMsg->getSourceNode(), vastMoveMsg->getNeighborCount());
00833     // update voronoi with new neighbor detection or without
00834     if(vastMoveMsg->getIs_boundary() || vastMoveMsg->getRequest_list()) {
00835         if(!vastMoveMsg->getRequest_list()) {
00836             buildVoronoi(old_p, new_p);
00837             synchronizeApp(vastMoveMsg);
00838             removeNeighbors();
00839         }
00840         // send new neighbors
00841         VastListMessage *vastListMsg = new VastListMessage("NEW_NEIGHBORS");
00842         vastListMsg->setCommand(NEW_NEIGHBORS);
00843 
00844         vastListMsg->setNeighborNodeArraySize(Sites.size());
00845         vastListMsg->setNeighborPosArraySize(Sites.size());
00846 
00847         int i = 0;
00848         for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00849             if(itSites->second->type & NEW || vastMoveMsg->getRequest_list()) {
00850                 vastListMsg->setNeighborNode(i, itSites->second->addr);
00851                 vastListMsg->setNeighborPos(i, itSites->second->coord);
00852                 ++i;
00853             }
00854         }
00855         vastListMsg->setNeighborNodeArraySize(i);
00856         vastListMsg->setNeighborPosArraySize(i);
00857         vastListMsg->setRequestEnclosingNeighbors(true);
00858 
00859         vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
00860         if(vastListMsg->getNeighborNodeArraySize() > 0) {
00861             sendMessage(vastListMsg, vastMoveMsg->getSourceNode());
00862         }
00863         else {
00864             delete vastListMsg;
00865         }
00866     }
00867     else {
00868         buildVoronoi();
00869         synchronizeApp(vastMoveMsg);
00870         removeNeighbors();
00871     }
00872 }
00873 
00874 void Vast::handleNewNeighbors(VastListMessage *vastListMsg)
00875 {
00876     // add new neighbors
00877     for(unsigned int i=0; i<vastListMsg->getNeighborNodeArraySize(); i++) {
00878         addNode(vastListMsg->getNeighborPos(i), vastListMsg->getNeighborNode(i));
00879 
00880         if(vastListMsg->getRequestEnclosingNeighbors()) {
00881             VastMessage *vastMsg = new VastMessage("ENCLOSING_NEIGHBORS_REQUEST");
00882             vastMsg->setCommand(ENCLOSING_NEIGHBORS_REQUEST);
00883             vastMsg->setBitLength(VAST_L(vastMsg));
00884             sendMessage(vastMsg, vastListMsg->getNeighborNode(i));
00885         }
00886     }
00887     // update voronoi with new neighbors
00888     buildVoronoi();
00889     synchronizeApp();
00890     removeNeighbors();
00891 }
00892 
00893 void Vast::handleNodeLeave(VastListMessage *vastListMsg)
00894 {
00895     removeNode(vastListMsg->getSourceNode());
00896     // add possible new neighbors
00897     for(unsigned int i=0; i<vastListMsg->getNeighborNodeArraySize(); i++) {
00898         addNode(vastListMsg->getNeighborPos(i), vastListMsg->getNeighborNode(i));
00899     }
00900     // update voronoi with new neighbors
00901     buildVoronoi();
00902     synchronizeApp();
00903     removeNeighbors();
00904 }
00905 
00906 void Vast::handleEnclosingNeighborsRequest(VastMessage *vastMsg)
00907 {
00908     // send new neighbors
00909     VastListMessage *vastListMsg = new VastListMessage("NEW_NEIGHBORS");
00910     vastListMsg->setCommand(NEW_NEIGHBORS);
00911 
00912     vastListMsg->setNeighborNodeArraySize(Sites.size());
00913     vastListMsg->setNeighborPosArraySize(Sites.size());
00914 
00915     int i = 0;
00916     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
00917         if((itSites->second->type & ENCLOSING) && itSites->second->addr != vastMsg->getSourceNode()) {
00918             vastListMsg->setNeighborNode(i, itSites->second->addr);
00919             vastListMsg->setNeighborPos(i, itSites->second->coord);
00920             ++i;
00921         }
00922     }
00923     vastListMsg->setNeighborNodeArraySize(i);
00924     vastListMsg->setNeighborPosArraySize(i);
00925 
00926     vastListMsg->setBitLength(VASTLIST_L(vastListMsg));
00927     if(vastListMsg->getNeighborNodeArraySize() > 0) {
00928         sendMessage(vastListMsg, vastMsg->getSourceNode());
00929     }
00930     else {
00931         delete vastListMsg;
00932     }
00933 }
00934 
00935 void Vast::handleBackupNeighbors(VastListMessage *vastListMsg)
00936 {
00937     // add new neighbors to stock list
00938     for(unsigned int i=0; i<vastListMsg->getNeighborNodeArraySize(); i++) {
00939         if(Sites.find(vastListMsg->getNeighborNode(i)) == Sites.end()) {
00940             addNodeToStock(vastListMsg->getNeighborNode(i));
00941         }
00942     }
00943 }
00944 
00945 void Vast::handlePing(VastMessage *vastMsg)
00946 {
00947     VastMessage *vastPongMsg = new VastMessage("PONG");
00948     vastPongMsg->setCommand(PONG);
00949     vastPongMsg->setBitLength(VAST_L(vastPongMsg));
00950     sendMessage(vastPongMsg, vastMsg->getSourceNode());
00951 }
00952 
00953 void Vast::handlePong(VastMessage *vastMsg)
00954 {
00955     // replace entry cause it was probably outdated
00956     addNode(vastMsg->getPos(), vastMsg->getSourceNode(), vastMsg->getNeighborCount());
00957     // update voronoi
00958     buildVoronoi();
00959     synchronizeApp();
00960     removeNeighbors();
00961 }
00962 
00963 void Vast::handleDiscardNode(VastDiscardMessage *vastMsg)
00964 {
00965     // discard outdated entry
00966     removeNode(vastMsg->getDiscardNode());
00967     // update voronoi
00968     buildVoronoi();
00969     synchronizeApp();
00970     removeNeighbors();
00971 }
00972 
00973 void Vast::sendDiscardNode(VastMessage *vastMsg)
00974 {
00975     NodeHandle discardNode;
00976     discardNode.ip = thisSite.addr.ip;
00977     discardNode.key = vastMsg->getDestKey();
00978     // send message
00979     VastDiscardMessage *vastDiscardMsg = new VastDiscardMessage("DISCARD_NODE");
00980     vastDiscardMsg->setCommand(DISCARD_NODE);
00981     vastDiscardMsg->setDiscardNode(discardNode);
00982     // debug output
00983     if(debugOutput) EV << "[Vast::sendDiscardNode() @ " << thisSite.addr.ip
00984                        << " (" << thisSite.addr.key.toString(16) << ")]\n"
00985                        << "    Node " << thisSite.addr.ip << " is leaving the overlay."
00986                        << endl;
00987     vastDiscardMsg->setBitLength(VASTDISCARD_L(vastDiscardMsg));
00988     sendMessage(vastDiscardMsg, vastMsg->getSourceNode());
00989 }
00990 
00991 void Vast::synchronizeApp(VastMoveMessage *vastMoveMsg)
00992 {
00993     GameAPIListMessage *sgcMsg = new GameAPIListMessage("NEIGHBOR_UPDATE");
00994     sgcMsg->setCommand(NEIGHBOR_UPDATE);
00995 
00996     sgcMsg->setRemoveNeighborArraySize(Sites.size());
00997     sgcMsg->setAddNeighborArraySize(Sites.size() + 1);
00998     sgcMsg->setNeighborPositionArraySize(Sites.size() + 1);
00999 
01000     int remSize, addSize;
01001     remSize = addSize = 0;
01002     for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
01003         if(itSites->second->type == UNDEF) {
01004             sgcMsg->setRemoveNeighbor(remSize, itSites->second->addr);
01005             ++remSize;
01006         }
01007         else if(!itSites->second->isAdded) {
01008             sgcMsg->setAddNeighbor(addSize, itSites->second->addr);
01009             sgcMsg->setNeighborPosition(addSize, itSites->second->coord);
01010             itSites->second->isAdded = true;
01011             ++addSize;
01012         }
01013     }
01014 
01015     if(vastMoveMsg &&
01016        Sites.find(vastMoveMsg->getSourceNode()) != Sites.end() &&
01017        Sites.find(vastMoveMsg->getSourceNode())->second->isAdded) {
01018         sgcMsg->setAddNeighbor(addSize, vastMoveMsg->getSourceNode());
01019         sgcMsg->setNeighborPosition(addSize, vastMoveMsg->getNewPos());
01020         ++addSize;
01021     }
01022 
01023     sgcMsg->setRemoveNeighborArraySize(remSize);
01024     sgcMsg->setAddNeighborArraySize(addSize);
01025     sgcMsg->setNeighborPositionArraySize(addSize);
01026 
01027     if(sgcMsg->getAddNeighborArraySize() || sgcMsg->getRemoveNeighborArraySize()) {
01028         sendToApp(sgcMsg);
01029     }
01030     else {
01031         delete sgcMsg;
01032     }
01033 }
01034 
01035 void Vast::sendToApp(cMessage *msg)
01036 {
01037     // debug output
01038     if(debugOutput) EV << "[Vast::sendToApp() @ " << thisSite.addr.ip
01039                        << " (" << thisSite.addr.key.toString(16) << ")]\n"
01040                        << "    Node " << thisSite.addr.ip << " sending " << msg->getName() << " to application."
01041                        << endl;
01042     send(msg, "appOut");
01043 }
01044 
01045 void Vast::sendMessage(VastMessage *vastMsg, NodeHandle destAddr)
01046 {
01047     // collect statistics
01048     switch(vastMsg->getCommand()) {
01049         case JOIN_REQUEST: {
01050             joinRequestBytesSent += vastMsg->getByteLength();
01051         } break;
01052         case JOIN_ACKNOWLEDGE: {
01053             joinAcknowledgeBytesSent += vastMsg->getByteLength();
01054         } break;
01055         case NODE_MOVE: {
01056             nodeMoveBytesSent += vastMsg->getByteLength();
01057         } break;
01058         case NEW_NEIGHBORS: {
01059             newNeighborsBytesSent += vastMsg->getByteLength();
01060         } break;
01061         case NODE_LEAVE: {
01062             nodeLeaveBytesSent += vastMsg->getByteLength();
01063         } break;
01064         case ENCLOSING_NEIGHBORS_REQUEST: {
01065             enclosingNeighborsRequestBytesSent += vastMsg->getByteLength();
01066         } break;
01067         case PING: {
01068             pingBytesSent += vastMsg->getByteLength();
01069         } break;
01070         case PONG: {
01071             pongBytesSent += vastMsg->getByteLength();
01072         } break;
01073         case DISCARD_NODE: {
01074             discardNodeBytesSent += vastMsg->getByteLength();
01075         } break;
01076     }
01077     bytesPerSecond += vastMsg->getByteLength();
01078 
01079     // debug output
01080     if(debugOutput) EV << "[Vast::sendMessage() @ " << thisSite.addr.ip
01081                        << " (" << thisSite.addr.key.toString(16) << ")]\n"
01082                        << "    Node " << thisSite.addr.ip << " sending " << vastMsg->getName() << " to " << destAddr.ip << "."
01083                        << endl;
01084     // set vastbase message stuff
01085     vastMsg->setDestKey(destAddr.key);
01086     // fill in sender information only if we are not forwarding a message from another node
01087     // e.g. a joining node
01088     if(vastMsg->getSourceNode().isUnspecified()) {
01089         vastMsg->setSourceNode(thisSite.addr);
01090         vastMsg->setPos(thisSite.coord);
01091         vastMsg->setNeighborCount(Sites.size());
01092     }
01093 
01094     sendMessageToUDP(destAddr, vastMsg);
01095 }
01096 
01097 void Vast::setBootstrapedIcon()
01098 {
01099     if(ev.isGUI()) {
01100         if(state == READY) {
01101             getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "green");
01102             getDisplayString().setTagArg("i", 1, "green");
01103         }
01104         else if(state == JOINING) {
01105             getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "yellow");
01106             getDisplayString().setTagArg("i", 1, "yellow");
01107         }
01108         else {
01109             getParentModule()->getParentModule()->getDisplayString().setTagArg("i2", 1, "red");
01110             getDisplayString().setTagArg("i", 1, "red");
01111         }
01112     }
01113 }
01114 
01115 void Vast::finishOverlay()
01116 {
01117     globalNodeList->removePeer(thisSite.addr);
01118 
01119     simtime_t time = globalStatistics->calcMeasuredLifetime(creationTime);
01120     if(time == 0) return;
01121 
01122     // collect statistics
01123     globalStatistics->addStdDev("Vast: JOIN_REQUEST bytes sent/s", joinRequestBytesSent/time);
01124     globalStatistics->addStdDev("Vast: JOIN_ACKNOWLEDGE bytes sent/s", joinAcknowledgeBytesSent/time);
01125     globalStatistics->addStdDev("Vast: NODE_MOVE bytes sent/s", nodeMoveBytesSent/time);
01126     globalStatistics->addStdDev("Vast: NEW_NEIGHBORS bytes sent/s", newNeighborsBytesSent/time);
01127     globalStatistics->addStdDev("Vast: NODE_LEAVE bytes sent/s", nodeLeaveBytesSent/time);
01128     globalStatistics->addStdDev("Vast: ENCLOSING_NEIGHBORS_REQUEST bytes sent/s", enclosingNeighborsRequestBytesSent/time);
01129     globalStatistics->addStdDev("Vast: PING bytes sent/s", pingBytesSent/time);
01130     globalStatistics->addStdDev("Vast: PONG bytes sent/s", pongBytesSent/time);
01131     globalStatistics->addStdDev("Vast: DISCARD_NODE bytes sent/s", discardNodeBytesSent/time);
01132 
01133     globalStatistics->addStdDev("max bytes/second sent", maxBytesPerSecondSent);
01134     globalStatistics->addStdDev("average bytes/second sent", averageBytesPerSecondSent / time);
01135 }
01136 
01137 double Vast::getAOI()
01138 {
01139     Enter_Method_Silent();
01140     return AOI_size;
01141 }
01142 
01143 Vector2D Vast::getPosition()
01144 {
01145     Enter_Method_Silent();
01146     return thisSite.coord;
01147 }
01148 
01149 NodeHandle Vast::getHandle()
01150 {
01151     Enter_Method_Silent();
01152     return thisSite.addr;
01153 }
01154 
01155 double Vast::getAreaDimension()
01156 {
01157     Enter_Method_Silent();
01158     return areaDimension;
01159 }
01160 
01161 Vast::~Vast()
01162 {
01163     if(Sites.size()) {
01164         for(SiteMap::iterator itSites = Sites.begin(); itSites != Sites.end(); ++itSites) {
01165             delete itSites->second;
01166         }
01167         Sites.clear();
01168         Positions.clear();
01169     }
01170     // destroy self timer messages
01171     cancelAndDelete(join_timer);
01172     cancelAndDelete(ping_timer);
01173     cancelAndDelete(sec_timer);
01174     cancelAndDelete(discovery_timer);
01175     cancelAndDelete(checkcritical_timer);
01176 }

Generated on Wed Mar 25 16:32:50 2009 for OverSim by  doxygen 1.5.5