Vast Class Reference

#include <Vast.h>

Inheritance diagram for Vast:

BaseOverlay BaseRpc RpcListener List of all members.

Detailed Description

An overlay network based on voronoi diagrams.


Public Member Functions

virtual ~Vast ()
virtual void initializeOverlay (int stage)
 Initializes derived-class-attributes.
virtual void finishOverlay ()
 collects statistical data in derived class
virtual void handleUDPMessage (BaseOverlayMessage *msg)
 Processes messages from underlay.
virtual void handleTimerEvent (cMessage *msg)
 Processes "timer" self-messages.
virtual void handleAppMessage (cMessage *msg)
 Processes non-commonAPI messages.
virtual void receiveChangeNotification (int category, cPolymorphic *details)
int getState ()
double getAOI ()
Point getPosition ()
NeighborsListgetList ()

Protected Member Functions

void sendToApp (SimpleClientMessage *scMsg)
void sendMessage (VastMessage *vastMsg, NodeHandle destAddr)
void setBootstrapedIcon ()
void changeState (int state)
double distance_square (Site s, VastMessage *msg)
void processJoinTimer ()
void processPingTimer ()
void processSecTimer ()
void handleJoin (SimpleClientMoveMessage *scMsg)
void handleMove (SimpleClientMoveMessage *scMsg)
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 handlePing (VastMessage *vastMsg)
void handlePong (VastMessage *vastMsg)
void handleDiscardNode (VastDiscardMessage *vastMsg)
void sendDiscardNode (VastMessage *vastMsg)
void synchronizeApp ()

Protected Attributes

double AOI_size
Point position
NeighborsListneighborsList
int state
long joinRequestBytesSent
long joinAcknowledgeBytesSent
long nodeMoveBytesSent
long newNeighborsBytesSent
long nodeLeaveBytesSent
long enclosingNeighborsRequestBytesSent
long pingBytesSent
long pongBytesSent
long discardNodeBytesSent
long maxBytesPerSecondSent
long averageBytesPerSecondSent
long bytesPerSecond
bool debugVoronoiOutput
double joinTimeout
double pingTimeout
cMessage * join_timer
cMessage * ping_timer
cMessage * sec_timer


Constructor & Destructor Documentation

Vast::~Vast (  )  [virtual]

00859 {
00860     // destroy self timer messages
00861     cancelAndDelete(join_timer);
00862     cancelAndDelete(ping_timer);
00863     cancelAndDelete(sec_timer);
00864 }


Member Function Documentation

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.

00029 {
00030     // because of IPAddressResolver, we need to wait until interfaces are registered,
00031     // address auto-assignment takes place etc.
00032     if(stage != MIN_STAGE_OVERLAY) return;
00033 
00034     // fetch parameters
00035     debugVoronoiOutput = par("debugVastOutput");
00036     AOI_size = par("AOI_size");
00037     joinTimeout = par("joinTimeout");
00038     pingTimeout = par("pingTimeout");
00039     onlyCommonAPIMessages = false;
00040 
00041     // find friend modules
00042     neighborsList = check_and_cast<NeighborsList*>(parentModule()->submodule("neighborsList"));
00043 
00044     // set node key
00045     thisNode.key = OverlayKey::random();
00046 
00047     // initialize neighborsList
00048     neighborsList->setDebug(debugVoronoiOutput);
00049 
00050     // self-messages
00051     join_timer = new cMessage("join_timer");
00052     ping_timer = new cMessage("ping_timer");
00053     sec_timer = new cMessage("sec_timer");
00054 
00055     // statistics
00056     joinRequestBytesSent = 0;
00057     joinAcknowledgeBytesSent = 0;
00058     nodeMoveBytesSent = 0;
00059     newNeighborsBytesSent = 0;
00060     nodeLeaveBytesSent = 0;
00061     enclosingNeighborsRequestBytesSent = 0;
00062     pingBytesSent = 0;
00063     pongBytesSent = 0;
00064     discardNodeBytesSent = 0;
00065 
00066     maxBytesPerSecondSent = 0;
00067     averageBytesPerSecondSent = 0;
00068     bytesPerSecond = 0;
00069 
00070     // watch some variables
00071     WATCH(position);
00072     WATCH(thisNode);
00073     WATCH(AOI_size);
00074 
00075     WATCH(joinRequestBytesSent);
00076     WATCH(joinAcknowledgeBytesSent);
00077     WATCH(nodeMoveBytesSent);
00078     WATCH(newNeighborsBytesSent);
00079     WATCH(nodeLeaveBytesSent);
00080     WATCH(enclosingNeighborsRequestBytesSent);
00081     WATCH(pingBytesSent);
00082     WATCH(pongBytesSent);
00083     WATCH(discardNodeBytesSent);
00084 
00085     WATCH(maxBytesPerSecondSent);
00086     WATCH(bytesPerSecond);
00087 
00088     // set initial state
00089     changeState(INIT);
00090     changeState(JOINING);
00091 }

void Vast::finishOverlay (  )  [virtual]

collects statistical data in derived class

Reimplemented from BaseOverlay.

00816 {
00817     // collect statistics
00818         globalStatistics->addStdDev("JOIN_REQUEST bytes sent", joinRequestBytesSent);
00819     globalStatistics->addStdDev("JOIN_ACKNOWLEDGE bytes sent", joinAcknowledgeBytesSent);
00820     globalStatistics->addStdDev("NODE_MOVE bytes sent", nodeMoveBytesSent);
00821     globalStatistics->addStdDev("NEW_NEIGHBORS bytes sent", newNeighborsBytesSent);
00822     globalStatistics->addStdDev("NODE_LEAVE bytes sent", nodeLeaveBytesSent);
00823     globalStatistics->addStdDev("ENCLOSING_NEIGHBORS_REQUEST bytes sent", enclosingNeighborsRequestBytesSent);
00824     globalStatistics->addStdDev("PING bytes sent", pingBytesSent);
00825     globalStatistics->addStdDev("PONG bytes sent", pongBytesSent);
00826     globalStatistics->addStdDev("DISCARD_NODE bytes sent", discardNodeBytesSent);
00827 
00828     globalStatistics->addStdDev("max bytes/second sent", maxBytesPerSecondSent);
00829     globalStatistics->addStdDev("average bytes/second sent", (long)(averageBytesPerSecondSent / simTime()));
00830 
00831     bootstrapOracle->removePeer(thisNode);
00832 }

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

Processes messages from underlay.

Parameters:
msg Message from UDP

Implements BaseOverlay.

00185 {
00186     if(state == INIT) {
00187         delete msg;
00188         return;
00189     }
00190     if(dynamic_cast<VastMessage*>(msg)) {
00191         VastMessage* vastMsg = check_and_cast<VastMessage*>(msg);
00192         if(vastMsg->getDestKey() == thisNode.key) {
00193             // debug output
00194             if(debugOutput) ev << "VAST: Node " << thisNode.ip << " received " << vastMsg->name() << " from " << vastMsg->getSourceNode().ip << "." << endl;
00195             if(state == READY) {
00196                 switch(vastMsg->getCommand()) {
00197                     case JOIN_REQUEST: {
00198                         handleJoinRequest(vastMsg);
00199                     } break;
00200                     case NODE_MOVE: {
00201                         VastMoveMessage* vastMoveMsg = check_and_cast<VastMoveMessage*>(msg);
00202                         handleNodeMove(vastMoveMsg);
00203                     } break;
00204                     case NEW_NEIGHBORS: {
00205                         VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
00206                         handleNewNeighbors(vastListMsg);
00207                     } break;
00208                     case NODE_LEAVE: {
00209                         VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
00210                         handleNodeLeave(vastListMsg);
00211                     } break;
00212                     case ENCLOSING_NEIGHBORS_REQUEST: {
00213                         handleEnclosingNeighborsRequest(vastMsg);
00214                     } break;
00215                     case PING: {
00216                         handlePing(vastMsg);
00217                     } break;
00218                     case PONG: {
00219                         handlePong(vastMsg);
00220                     } break;
00221                     case DISCARD_NODE: {
00222                         VastDiscardMessage* vastDiscardMsg = check_and_cast<VastDiscardMessage*>(msg);
00223                         handleDiscardNode(vastDiscardMsg);
00224                     } break;
00225                 }
00226                 // update timestamp
00227                 if(vastMsg != NULL && vastMsg->getCommand() != JOIN_REQUEST) {
00228                     neighborsList->updateTimeStamp(vastMsg->getSourceNode());
00229                     delete msg;
00230                 }
00231             }
00232             else if(state == JOINING && vastMsg->getCommand() == JOIN_ACKNOWLEDGE) {
00233                 VastListMessage* vastListMsg = check_and_cast<VastListMessage*>(msg);
00234                 handleJoinAcknowledge(vastListMsg);
00235                 delete msg;
00236             }
00237             else delete msg;
00238         }
00239         else {
00240             sendDiscardNode(vastMsg);
00241             delete msg;
00242         }
00243     }
00244     else delete msg;
00245 }

void Vast::handleTimerEvent ( cMessage *  msg  )  [virtual]

Processes "timer" self-messages.

Parameters:
msg A self-message

Reimplemented from BaseOverlay.

00131 {
00132     if(msg->isName("join_timer")) {
00133         //reset timer
00134         cancelEvent(join_timer);
00135         scheduleAt(simulation.simTime() + joinTimeout, msg);
00136         // handle event
00137         processJoinTimer();
00138     }
00139     else if(msg->isName("ping_timer")) {
00140         //reset timer
00141         cancelEvent(ping_timer);
00142         scheduleAt(simulation.simTime() + pingTimeout, msg);
00143         // handle event
00144         processPingTimer();
00145     }
00146     else if(msg->isName("sec_timer")) {
00147         //reset timer
00148         cancelEvent(sec_timer);
00149         scheduleAt(simulation.simTime() + 1, msg);
00150         // handle event
00151         processSecTimer();
00152     }
00153 }

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

Processes non-commonAPI messages.


Processes non-commonAPI messages if parameter "onlyCommonAPIMessages" is false.

Parameters:
msg non-commonAPIMessage

Reimplemented from BaseOverlay.

00156 {
00157     if(dynamic_cast<SimpleClientMessage*>(msg)) {
00158         SimpleClientMessage* simpleClientMsg = check_and_cast<SimpleClientMessage*>(msg);
00159         // debug output
00160         if(debugOutput) ev << "VAST: Node " << thisNode.ip << " received " << simpleClientMsg->name() << " from application." << endl;
00161         switch(simpleClientMsg->getCommand()) {
00162             case MOVE_INDICATION: {
00163                 SimpleClientMoveMessage* simpleClientMoveMsg = check_and_cast<SimpleClientMoveMessage*>(msg);
00164                 if(state == JOINING) {
00165                     handleJoin(simpleClientMoveMsg);
00166                     delete msg;
00167                 }
00168                 else if(state == READY) {
00169                     handleMove(simpleClientMoveMsg);
00170                     delete msg;
00171                 }
00172             } break;
00173             //case EVENT: {
00174                 // insert handling for additional application messages like events etc. here
00175             //} break;
00176             default: {
00177                 delete msg;
00178             }
00179         }
00180     }
00181     else delete msg;
00182 }

void Vast::receiveChangeNotification ( int  category,
cPolymorphic *  details 
) [virtual]

00248 {
00249     /*if(category == NF_OVERLAY_NODE_LEAVE && state == READY) {
00250         int i;
00251         // debug output
00252         if(debugOutput) ev << "OVERLAY: Node " << thisNode.ip << " is leaving the overlay." << endl;
00253 
00254         // generate node leave messages
00255         VoronoiListMessage *voroListMsg = new VoronoiListMessage("NODE_LEAVE");
00256         voroListMsg->setCommand(NODE_LEAVE);
00257         voroListMsg->setSourceNode(thisNode);
00258         voroListMsg->setPosX(position.x);
00259         voroListMsg->setPosY(position.y);
00260 
00261         voroListMsg->setNeighborNodeArraySize(neighborsList->getSize());
00262         voroListMsg->setNeighbor_posXArraySize(neighborsList->getSize());
00263         voroListMsg->setNeighbor_posYArraySize(neighborsList->getSize());
00264 
00265         i = 0;
00266         neighborsList->initIterator();
00267         Site *currentSite = neighborsList->next();
00268         while(currentSite) {
00269             if(currentSite->type & ENCLOSING) {
00270                 voroListMsg->setNeighborNode(i, currentSite->addr);
00271                 voroListMsg->setNeighbor_posX(i, currentSite->coord.x);
00272                 voroListMsg->setNeighbor_posY(i, currentSite->coord.y);
00273                 ++i;
00274             }
00275             currentSite = neighborsList->next();
00276         }
00277         voroListMsg->setEntry_count(i);
00278         voroListMsg->setNeighborNodeArraySize(i);
00279         voroListMsg->setNeighbor_posXArraySize(i);
00280         voroListMsg->setNeighbor_posYArraySize(i);
00281 
00282         voroListMsg->setLength(BASE_L + COUNT_L + voroListMsg->getEntry_count() * ENTRY_L);
00283         if(voroListMsg->getEntry_count() > 0) {
00284             neighborsList->initIterator();
00285             currentSite = neighborsList->next();
00286             while(currentSite) {
00287                 if(!(currentSite->type & THIS)) {
00288                     VoronoiListMessage *voroCopyMsg = new VoronoiListMessage(*voroListMsg);
00289                     // prevent notification board from taking the message
00290                     take(voroCopyMsg);
00291                     sendMessage(voroCopyMsg, currentSite->addr);
00292                 }
00293                 currentSite = neighborsList->next();
00294             }
00295         }
00296         delete voroListMsg;
00297 
00298         changeState(INIT);
00299     }*/
00300 }

int Vast::getState (  ) 

00835 {
00836     Enter_Method_Silent();
00837     return state;
00838 }

double Vast::getAOI (  ) 

00841 {
00842     Enter_Method_Silent();
00843     return AOI_size;
00844 }

Point Vast::getPosition (  ) 

00847 {
00848     Enter_Method_Silent();
00849     return position;
00850 }

NeighborsList * Vast::getList (  ) 

00853 {
00854     Enter_Method_Silent();
00855     return neighborsList;
00856 }

void Vast::sendToApp ( SimpleClientMessage *  scMsg  )  [protected]

00732 {
00733     // debug output
00734     if(debugOutput) ev << "VAST: Node " << thisNode.ip << " sending " << scMsg->name() << " to application." << endl;
00735     send(scMsg, "to_app");
00736 }

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

00739 {
00740     // collect statistics
00741     switch(vastMsg->getType()) {
00742         case JOIN_REQUEST: {
00743             joinRequestBytesSent += vastMsg->byteLength();
00744         } break;
00745         case JOIN_ACKNOWLEDGE: {
00746             joinAcknowledgeBytesSent += vastMsg->byteLength();
00747         } break;
00748         case NODE_MOVE: {
00749             nodeMoveBytesSent += vastMsg->byteLength();
00750         } break;
00751         case NEW_NEIGHBORS: {
00752             newNeighborsBytesSent += vastMsg->byteLength();
00753         } break;
00754         case NODE_LEAVE: {
00755             nodeLeaveBytesSent += vastMsg->byteLength();
00756         } break;
00757         case ENCLOSING_NEIGHBORS_REQUEST: {
00758             enclosingNeighborsRequestBytesSent += vastMsg->byteLength();
00759         } break;
00760         case PING: {
00761             pingBytesSent += vastMsg->byteLength();
00762         } break;
00763         case PONG: {
00764             pongBytesSent += vastMsg->byteLength();
00765         } break;
00766         case DISCARD_NODE: {
00767             discardNodeBytesSent += vastMsg->byteLength();
00768         } break;
00769     }
00770     bytesPerSecond += vastMsg->byteLength();
00771 
00772     // debug output
00773     if(debugOutput) ev << "VAST: Node " << thisNode.ip << " sending " << vastMsg->name() << " to " << destAddr.ip << "." << endl;
00774     vastMsg->setDestKey(destAddr.key);
00775     sendMessageToUDP(destAddr, vastMsg);
00776 
00777     //set UDP control info
00778     /*vastMsg->setKind(UDP_C_DATA);
00779 
00780     UDPControlInfo* ctrl = new UDPControlInfo();
00781     ctrl->setSrcAddr(thisNode.ip);
00782     ctrl->setSrcPort(thisNode.port);
00783     ctrl->setDestAddr(destAddr.ip);
00784     ctrl->setDestPort(thisNode.port);
00785     vastMsg->setControlInfo(ctrl);
00786     send(vastMsg, "to_udp");*/
00787 }

void Vast::setBootstrapedIcon (  )  [protected]

00798 {
00799     if(ev.isGUI()) {
00800         if(state == READY) {
00801             parentModule()->parentModule()->displayString().setTagArg("i2", 1, "green");
00802             displayString().setTagArg("i", 1, "green");
00803         }
00804         else if(state == JOINING) {
00805             parentModule()->parentModule()->displayString().setTagArg("i2", 1, "yellow");
00806             displayString().setTagArg("i", 1, "yellow");
00807         }
00808         else {
00809             parentModule()->parentModule()->displayString().setTagArg("i2", 1, "red");
00810             displayString().setTagArg("i", 1, "red");
00811         }
00812     }
00813 }

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

00094 {
00095     switch(state) {
00096         case INIT: {
00097             this->state = INIT;
00098             bootstrapOracle->removePeer(thisNode);
00099         } break;
00100         case JOINING: {
00101             this->state = JOINING;
00102             scheduleAt(simulation.simTime(), join_timer);
00103             scheduleAt(simulation.simTime() + 1.0, sec_timer);
00104         } break;
00105         case READY: {
00106             this->state = READY;
00107             cancelEvent(join_timer);
00108             neighborsList->initializeList(position, thisNode, AOI_size);
00109             bootstrapOracle->registerPeer(thisNode);
00110             scheduleAt(simulation.simTime() + pingTimeout, ping_timer);
00111             // tell the application we are ready
00112             SimpleClientMessage *scMsg = new SimpleClientMessage("OVERLAY_READY");
00113             scMsg->setCommand(OVERLAY_READY);
00114             sendToApp(scMsg);
00115         } break;
00116     }
00117     setBootstrapedIcon();
00118     // debug output
00119     if(debugOutput) {
00120         ev << "VAST: Node " << thisNode.ip << " entered ";
00121         switch(state) {
00122             case INIT: ev << "INIT"; break;
00123             case JOINING: ev << "JOINING"; break;
00124             case READY: ev << "READY"; break;
00125         }
00126         ev << " state." << endl;
00127     }
00128 }

double Vast::distance_square ( Site  s,
VastMessage *  msg 
) [protected]

00790 {
00791     double dx, dy;
00792     dx = s.coord.x - msg->getPosX();
00793     dy = s.coord.y - msg->getPosY();
00794     return dx*dx + dy*dy;
00795 }

void Vast::processJoinTimer (  )  [protected]

00303 {
00304     SimpleClientMessage *scMsg = new SimpleClientMessage("MOVE_REQUEST");
00305     scMsg->setCommand(MOVE_REQUEST);
00306     sendToApp(scMsg);
00307 }

void Vast::processPingTimer (  )  [protected]

00310 {
00311     bool abnormalLeave = false;
00312     bool boundaryLeave = false;
00313     SiteMap::iterator itSites = neighborsList->Sites.begin();
00314     while(itSites != neighborsList->Sites.end()) {
00315         if(itSites->second.tstamp < 0.0) { // node is dropped cause no pong has been received see below
00316             abnormalLeave = true;
00317             if(!(itSites->second.type & NEIGHBOR)) boundaryLeave = true;
00318             itSites->second.type = UNDEF;
00319         }
00320         else if(itSites->second.tstamp < simulation.simTime() - pingTimeout) { // node showed no activity for some time request pong and mark it to be dropped next time
00321             VastMessage *vastMsg = new VastMessage("PING");
00322             vastMsg->setCommand(PING);
00323             vastMsg->setSourceNode(thisNode);
00324             vastMsg->setPosX(position.x);
00325             vastMsg->setPosY(position.y);
00326             vastMsg->setLength(VAST_L(vastMsg));
00327             sendMessage(vastMsg, itSites->second.addr);
00328             itSites->second.tstamp = -1.0;
00329         }
00330         ++itSites;
00331     }
00332     if(abnormalLeave) {
00333         synchronizeApp();
00334         neighborsList->removeNeighbors();
00335         if(boundaryLeave) {
00336             itSites = neighborsList->Sites.begin();
00337             while(itSites != neighborsList->Sites.end()) {
00338                 if(itSites->second.type & BOUNDARY) {
00339                     VastMessage *vastMsg = new VastMessage("ENCLOSING_NEIGHBORS_REQUEST");
00340                     vastMsg->setCommand(ENCLOSING_NEIGHBORS_REQUEST);
00341                     vastMsg->setSourceNode(thisNode);
00342                     vastMsg->setPosX(position.x);
00343                     vastMsg->setPosY(position.y);
00344                     vastMsg->setLength(VAST_L(vastMsg));
00345                     sendMessage(vastMsg, itSites->second.addr);
00346                 }
00347                 ++itSites;
00348             }
00349         }
00350         neighborsList->buildVoronoi();
00351         //neighborsList->removeNeighbors(); should be superfluous
00352     }
00353 }

void Vast::processSecTimer (  )  [protected]

void Vast::handleJoin ( SimpleClientMoveMessage *  scMsg  )  [protected]

00365 {
00366     NodeHandle joinNode = bootstrapOracle->getBootstrapNode();
00367     position.x = scMsg->getPosX();
00368     position.y = scMsg->getPosY();
00369     // check if this is the only node in the overlay
00370     if(joinNode.isUnspecified()) {
00371         changeState(READY);
00372     }
00373     else {
00374         VastMessage *vastMsg = new VastMessage("JOIN_REQUEST");
00375         vastMsg->setCommand(JOIN_REQUEST);
00376         vastMsg->setSourceNode(thisNode);
00377         vastMsg->setPosX(position.x);
00378         vastMsg->setPosY(position.y);
00379         vastMsg->setLength(VAST_L(vastMsg));
00380         sendMessage(vastMsg, joinNode);
00381     }
00382 }

void Vast::handleMove ( SimpleClientMoveMessage *  scMsg  )  [protected]

00385 {
00386     Point pos;
00387     pos.x = scMsg->getPosX();
00388     pos.y = scMsg->getPosY();
00389     // test if new position is legal
00390     if(!neighborsList->validatePosition(pos)) {
00391         SimpleClientMessage *scMsg = new SimpleClientMessage("MOVE_REQUEST");
00392         scMsg->setCommand(MOVE_REQUEST);
00393         sendToApp(scMsg);
00394         return;
00395     }
00396     // send position update to neighbors
00397     SiteMap::iterator itSites = neighborsList->Sites.begin();
00398     while(itSites != neighborsList->Sites.end()) {
00399         VastMoveMessage *vastMoveMsg = new VastMoveMessage("NODE_MOVE");
00400         vastMoveMsg->setCommand(NODE_MOVE);
00401         vastMoveMsg->setSourceNode(thisNode);
00402         vastMoveMsg->setPosX(position.x);
00403         vastMoveMsg->setPosY(position.y);
00404         vastMoveMsg->setNew_posX(pos.x);
00405         vastMoveMsg->setNew_posY(pos.y);
00406         vastMoveMsg->setIs_boundary(itSites->second.type & BOUNDARY);
00407         vastMoveMsg->setLength(VASTMOVE_L(vastMoveMsg));
00408         sendMessage(vastMoveMsg, itSites->second.addr);
00409         ++itSites;
00410     }
00411     // set new position
00412     position = pos;
00413     neighborsList->changePosition(pos);
00414     // update voronoi
00415     neighborsList->buildVoronoi();
00416     synchronizeApp();
00417     neighborsList->removeNeighbors();
00418 }

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

00421 {
00422     Site *forwardSite = NULL;
00423     double min_dist;
00424     // start with this node
00425     min_dist = distance_square(neighborsList->thisSite, vastMsg);
00426     forwardSite = &neighborsList->thisSite;
00427     // iterate through all neighbors
00428     SiteMap::iterator itSites = neighborsList->Sites.begin();
00429     while(itSites != neighborsList->Sites.end()) {
00430         if(distance_square(itSites->second, vastMsg) < min_dist) {
00431             min_dist = distance_square(itSites->second, vastMsg);
00432             forwardSite = &itSites->second;
00433         }
00434         ++itSites;
00435     }
00436     // do nothing and let node retry with new position if current position is illegal
00437     if(min_dist == 0.0) {
00438         delete vastMsg;
00439         vastMsg = NULL;
00440     }
00441     else {
00442         // send an acknowledge or forward request if any of our neighbors is closer to joining node
00443         if(forwardSite->type & THIS) {
00444             VastListMessage *vastListMsg = new VastListMessage("JOIN_ACKNOWLEDGE");
00445             vastListMsg->setCommand(JOIN_ACKNOWLEDGE);
00446             vastListMsg->setSourceNode(thisNode);
00447             vastListMsg->setPosX(position.x);
00448             vastListMsg->setPosY(position.y);
00449             // fill neighbors list
00450             vastListMsg->setNeighborNodeArraySize(neighborsList->getSize());
00451             vastListMsg->setNeighbor_posXArraySize(neighborsList->getSize());
00452             vastListMsg->setNeighbor_posYArraySize(neighborsList->getSize());
00453             int i = 0;
00454             itSites = neighborsList->Sites.begin();
00455             while(itSites != neighborsList->Sites.end()) {
00456                 vastListMsg->setNeighborNode(i, itSites->second.addr);
00457                 vastListMsg->setNeighbor_posX(i, itSites->second.coord.x);
00458                 vastListMsg->setNeighbor_posY(i, itSites->second.coord.y);
00459                 ++i;
00460                 ++itSites;
00461             }
00462             vastListMsg->setEntry_count(i);
00463             vastListMsg->setNeighborNodeArraySize(i);
00464             vastListMsg->setNeighbor_posXArraySize(i);
00465             vastListMsg->setNeighbor_posYArraySize(i);
00466 
00467             vastListMsg->setLength(VASTLIST_L(vastListMsg));
00468             sendMessage(vastListMsg, vastMsg->getSourceNode());
00469             delete vastMsg;
00470             vastMsg = NULL;
00471         }
00472         else {
00473             sendMessage(vastMsg, forwardSite->addr);
00474         }
00475     }
00476 }

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

00479 {
00480     Point p, p_join;
00481     p_join.x = vastListMsg->getPosX();
00482     p_join.y = vastListMsg->getPosY();
00483     // add acceptor node
00484     neighborsList->addNode(p_join, vastListMsg->getSourceNode());
00485     changeState(READY);
00486     // add new neighbors
00487     for(int i=0; i<vastListMsg->getEntry_count(); i++) {
00488         p.x = vastListMsg->getNeighbor_posX(i);
00489         p.y = vastListMsg->getNeighbor_posY(i);
00490         neighborsList->addNode(p, vastListMsg->getNeighborNode(i));
00491     }
00492     // update voronoi with new neighbors
00493     neighborsList->buildVoronoi();
00494     synchronizeApp();
00495     neighborsList->removeNeighbors();
00496     // contact new neighbors
00497     SiteMap::iterator itSites = neighborsList->Sites.begin();
00498     while(itSites != neighborsList->Sites.end()) {
00499         VastMoveMessage *vastMoveMsg = new VastMoveMessage("NODE_MOVE");
00500         vastMoveMsg->setCommand(NODE_MOVE);
00501         vastMoveMsg->setSourceNode(thisNode);
00502         vastMoveMsg->setPosX(p_join.x);
00503         vastMoveMsg->setPosY(p_join.y);
00504         vastMoveMsg->setNew_posX(position.x);
00505         vastMoveMsg->setNew_posY(position.y);
00506         vastMoveMsg->setIs_boundary(itSites->second.type & BOUNDARY);
00507         vastMoveMsg->setLength(VASTMOVE_L(vastMoveMsg));
00508         sendMessage(vastMoveMsg, itSites->second.addr);
00509         ++itSites;
00510     }
00511 }

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

00514 {
00515     Point old_p, new_p;
00516     old_p.x = vastMoveMsg->getPosX();
00517     old_p.y = vastMoveMsg->getPosY();
00518     new_p.x = vastMoveMsg->getNew_posX();
00519     new_p.y = vastMoveMsg->getNew_posY();
00520     neighborsList->addNode(new_p, vastMoveMsg->getSourceNode());
00521     // update voronoi with new neighbor detection or without
00522     if(vastMoveMsg->getIs_boundary()) {
00523         neighborsList->buildVoronoi(old_p, new_p);
00524         synchronizeApp();
00525         neighborsList->removeNeighbors();
00526         // send new neighbors
00527         VastListMessage *vastListMsg = new VastListMessage("NEW_NEIGHBORS");
00528         vastListMsg->setCommand(NEW_NEIGHBORS);
00529         vastListMsg->setSourceNode(thisNode);
00530         vastListMsg->setPosX(position.x);
00531         vastListMsg->setPosY(position.y);
00532 
00533         vastListMsg->setNeighborNodeArraySize(neighborsList->getSize());
00534         vastListMsg->setNeighbor_posXArraySize(neighborsList->getSize());
00535         vastListMsg->setNeighbor_posYArraySize(neighborsList->getSize());
00536 
00537         int i = 0;
00538         SiteMap::iterator itSites = neighborsList->Sites.begin();
00539         while(itSites != neighborsList->Sites.end()) {
00540             if(itSites->second.type & NEW) {
00541                 vastListMsg->setNeighborNode(i, itSites->second.addr);
00542                 vastListMsg->setNeighbor_posX(i, itSites->second.coord.x);
00543                 vastListMsg->setNeighbor_posY(i, itSites->second.coord.y);
00544                 ++i;
00545             }
00546             ++itSites;
00547         }
00548         vastListMsg->setEntry_count(i);
00549         vastListMsg->setNeighborNodeArraySize(i);
00550         vastListMsg->setNeighbor_posXArraySize(i);
00551         vastListMsg->setNeighbor_posYArraySize(i);
00552 
00553         vastListMsg->setLength(VASTLIST_L(vastListMsg));
00554         if(vastListMsg->getEntry_count() > 0) {
00555             sendMessage(vastListMsg, vastMoveMsg->getSourceNode());
00556         }
00557         else {
00558             delete vastListMsg;
00559         }
00560     }
00561     else {
00562         neighborsList->buildVoronoi();
00563         synchronizeApp();
00564         neighborsList->removeNeighbors();
00565     }
00566 }

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

00569 {
00570     Point p;
00571     // add new neighbors
00572     for(int i=0; i<vastListMsg->getEntry_count(); i++) {
00573         p.x = vastListMsg->getNeighbor_posX(i);
00574         p.y = vastListMsg->getNeighbor_posY(i);
00575         neighborsList->addNode(p, vastListMsg->getNeighborNode(i));
00576     }
00577     // update voronoi with new neighbors
00578     neighborsList->buildVoronoi();
00579     synchronizeApp();
00580     neighborsList->removeNeighbors();
00581 }

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

00584 {
00585     Point p;
00586     neighborsList->removeNode(vastListMsg->getSourceNode());
00587     // add possible new neighbors
00588     for(int i=0; i<vastListMsg->getEntry_count(); i++) {
00589         p.x = vastListMsg->getNeighbor_posX(i);
00590         p.y = vastListMsg->getNeighbor_posY(i);
00591         neighborsList->addNode(p, vastListMsg->getNeighborNode(i));
00592     }
00593     // update voronoi with new neighbors
00594     neighborsList->buildVoronoi();
00595     synchronizeApp();
00596     neighborsList->removeNeighbors();
00597 }

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

00600 {
00601     // send new neighbors
00602     VastListMessage *vastListMsg = new VastListMessage("NEW_NEIGHBORS");
00603     vastListMsg->setCommand(NEW_NEIGHBORS);
00604     vastListMsg->setSourceNode(thisNode);
00605     vastListMsg->setPosX(position.x);
00606     vastListMsg->setPosY(position.y);
00607 
00608     vastListMsg->setNeighborNodeArraySize(neighborsList->getSize());
00609     vastListMsg->setNeighbor_posXArraySize(neighborsList->getSize());
00610     vastListMsg->setNeighbor_posYArraySize(neighborsList->getSize());
00611 
00612     int i = 0;
00613     SiteMap::iterator itSites = neighborsList->Sites.begin();
00614     while(itSites != neighborsList->Sites.end()) {
00615         if((itSites->second.type & ENCLOSING) && itSites->second.addr != vastMsg->getSourceNode()) {
00616             vastListMsg->setNeighborNode(i, itSites->second.addr);
00617             vastListMsg->setNeighbor_posX(i, itSites->second.coord.x);
00618             vastListMsg->setNeighbor_posY(i, itSites->second.coord.y);
00619             ++i;
00620         }
00621         ++itSites;
00622     }
00623     vastListMsg->setEntry_count(i);
00624     vastListMsg->setNeighborNodeArraySize(i);
00625     vastListMsg->setNeighbor_posXArraySize(i);
00626     vastListMsg->setNeighbor_posYArraySize(i);
00627 
00628     vastListMsg->setLength(VASTLIST_L(vastListMsg));
00629     if(vastListMsg->getEntry_count() > 0) {
00630         sendMessage(vastListMsg, vastMsg->getSourceNode());
00631     }
00632     else {
00633         delete vastListMsg;
00634     }
00635 }

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

00638 {
00639     VastMessage *vastPongMsg = new VastMessage("PONG");
00640     vastPongMsg->setCommand(PONG);
00641     vastPongMsg->setSourceNode(thisNode);
00642     vastPongMsg->setPosX(position.x);
00643     vastPongMsg->setPosY(position.y);
00644     vastPongMsg->setLength(VAST_L(vastPongMsg));
00645     sendMessage(vastPongMsg, vastMsg->getSourceNode());
00646 }

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

00649 {
00650     Point p;
00651     // replace entry cause it was probably outdated
00652     p.x = vastMsg->getPosX();
00653     p.y = vastMsg->getPosY();
00654     neighborsList->addNode(p, vastMsg->getSourceNode());
00655     // update voronoi
00656     neighborsList->buildVoronoi();
00657     synchronizeApp();
00658     neighborsList->removeNeighbors();
00659 }

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

00662 {
00663     // discard outdated entry
00664     neighborsList->removeNode(vastMsg->getDiscardNode());
00665     // update voronoi
00666     neighborsList->buildVoronoi();
00667     synchronizeApp();
00668     neighborsList->removeNeighbors();
00669 }

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

00672 {
00673     NodeHandle discardNode;
00674     discardNode.ip = thisNode.ip;
00675     discardNode.key = vastMsg->getDestKey();
00676     // send message
00677     VastDiscardMessage *vastDiscardMsg = new VastDiscardMessage("DISCARD_NODE");
00678     vastDiscardMsg->setCommand(DISCARD_NODE);
00679     vastDiscardMsg->setSourceNode(thisNode);
00680     vastDiscardMsg->setPosX(position.x);
00681     vastDiscardMsg->setPosY(position.y);
00682     vastDiscardMsg->setDiscardNode(discardNode);
00683     // debug output
00684     if(debugOutput) ev << "VAST: Node " << thisNode.ip << " received message for an outdated node from " << vastMsg->getSourceNode().ip << "." << endl;
00685     vastDiscardMsg->setLength(VASTDISCARD_L(vastDiscardMsg));
00686     sendMessage(vastDiscardMsg, vastMsg->getSourceNode());
00687 }

void Vast::synchronizeApp (  )  [protected]

00690 {
00691     SimpleClientListMessage *scMsg = new SimpleClientListMessage("UPDATE_NEIGHBORS");
00692     scMsg->setCommand(UPDATE_NEIGHBORS);
00693 
00694     scMsg->setRemove_neighborArraySize(neighborsList->getSize());
00695     scMsg->setAdd_neighborArraySize(neighborsList->getSize());
00696     scMsg->setAdd_neighbor_posXArraySize(neighborsList->getSize());
00697     scMsg->setAdd_neighbor_posYArraySize(neighborsList->getSize());
00698 
00699     int i, j;
00700     i = j = 0;
00701     SiteMap::iterator itSites = neighborsList->Sites.begin();
00702     while(itSites != neighborsList->Sites.end()) {
00703         if(itSites->second.type == UNDEF) {
00704             scMsg->setRemove_neighbor(i, itSites->second.addr);
00705             ++i;
00706         }
00707         else if(!itSites->second.isAdded) {
00708             scMsg->setAdd_neighbor(j, itSites->second.addr);
00709             scMsg->setAdd_neighbor_posX(j, itSites->second.coord.x);
00710             scMsg->setAdd_neighbor_posY(j, itSites->second.coord.y);
00711             itSites->second.isAdded = true;
00712             ++j;
00713         }
00714         ++itSites;
00715     }
00716     scMsg->setRemove_entry_count(i);
00717     scMsg->setRemove_neighborArraySize(i);
00718     scMsg->setAdd_entry_count(j);
00719     scMsg->setAdd_neighborArraySize(j);
00720     scMsg->setAdd_neighbor_posXArraySize(j);
00721     scMsg->setAdd_neighbor_posYArraySize(j);
00722 
00723     if(scMsg->getAdd_entry_count() || scMsg->getRemove_entry_count()) {
00724         sendToApp(scMsg);
00725     }
00726     else {
00727         delete scMsg;
00728     }
00729 }


Member Data Documentation

double Vast::AOI_size [protected]

Point Vast::position [protected]

NeighborsList* Vast::neighborsList [protected]

int Vast::state [protected]

long Vast::joinRequestBytesSent [protected]

long Vast::joinAcknowledgeBytesSent [protected]

long Vast::nodeMoveBytesSent [protected]

long Vast::newNeighborsBytesSent [protected]

long Vast::nodeLeaveBytesSent [protected]

long Vast::enclosingNeighborsRequestBytesSent [protected]

long Vast::pingBytesSent [protected]

long Vast::pongBytesSent [protected]

long Vast::discardNodeBytesSent [protected]

long Vast::maxBytesPerSecondSent [protected]

long Vast::averageBytesPerSecondSent [protected]

long Vast::bytesPerSecond [protected]

bool Vast::debugVoronoiOutput [protected]

double Vast::joinTimeout [protected]

double Vast::pingTimeout [protected]

cMessage* Vast::join_timer [protected]

cMessage* Vast::ping_timer [protected]

cMessage* Vast::sec_timer [protected]


The documentation for this class was generated from the following files:
Generated on Tue Jul 24 16:51:19 2007 for ITM OverSim by  doxygen 1.5.1