28 #include <NotifierConsts.h>
150 case INIT: ev <<
"INIT";
break;
151 case JOIN: ev <<
"JOIN";
break;
152 case READY: ev <<
"READY";
break;
154 ev <<
" state." << endl;
160 if(msg->isName(
"join_timer")) {
167 else if(msg->isName(
"ping_timer")) {
174 else if(msg->isName(
"sec_timer")) {
177 scheduleAt(simTime() + 1, msg);
181 else if(msg->isName(
"checkcritical_timer")) {
188 else if(msg->isName(
"discovery_timer")) {
199 if(dynamic_cast<GameAPIMessage*>(msg)) {
204 <<
" Node " <<
thisSite.
addr.
getIp() <<
" received " << gameAPIMsg->getName() <<
" from application."
238 if(dynamic_cast<VastMessage*>(msg)) {
248 bool doUpdate =
true;
293 if(itSites !=
Sites.end()) {
294 itSites->second->tstamp = simTime();
319 temp_site->
coord = p;
320 temp_site->
addr = node;
323 Sites.insert(std::make_pair(temp_site->
addr, temp_site));
327 SiteMap::iterator itSites =
Sites.find(node);
329 itSites->second->coord = p;
330 Positions.insert(itSites->second->coord);
331 if(NeighborCount != 0) {
332 itSites->second->neighborCount = NeighborCount;
341 for(StockList::iterator itTemp =
Stock.begin(); itTemp !=
Stock.end(); ++itTemp) {
342 if(*itTemp == node) {
346 Stock.push_front(node);
355 SiteMap::iterator itSites =
Sites.find(node);
356 if(itSites !=
Sites.end()) {
358 delete itSites->second;
359 Sites.erase(itSites);
366 double xmin, xmax, ymin, ymax;
367 double deltax, deltay;
370 if(
Sites.size() == 0)
return;
375 std::map<Vector2D, Site*> sortedSites;
378 for(SiteMap::iterator itTemp =
Sites.begin(); itTemp !=
Sites.end(); ++itTemp) {
380 if(itTemp->second->coord.x < xmin) xmin = itTemp->second->coord.x;
381 if(itTemp->second->coord.x > xmax) xmax = itTemp->second->coord.x;
382 if(itTemp->second->coord.y < ymin) ymin = itTemp->second->coord.y;
383 if(itTemp->second->coord.y > ymax) ymax = itTemp->second->coord.y;
385 itTemp->second->type =
UNDEF;
387 itTemp->second->enclosingSet.clear();
389 sortedSites.insert(std::make_pair(itTemp->second->coord, itTemp->second));
394 deltax = xmax - xmin;
395 deltay = ymax - ymin;
396 sqrt_nsites = (int)sqrt((
double)(sqrt_nsites+4));
399 Site *newsite, *bot, *top, *temp, *p, *v, *bottomsite;
402 Halfedge *lbnd, *rbnd, *llbnd, *rrbnd, *bisector;
405 newintstar.
x = newintstar.
y = 0.0;
407 std::map<Vector2D, Site*>::iterator itSortedSites = sortedSites.begin();
411 bottomsite = itSortedSites->second;
415 newsite = itSortedSites->second;
421 newsite->
coord.
y < newintstar.
y ||
422 (newsite->
coord.
y == newintstar.
y && newsite->
coord.
x < newintstar.
x))) {
437 if(itSortedSites != sortedSites.end()) {
438 newsite = itSortedSites->second;
482 for(SiteMap::iterator itTemp =
Sites.begin(); itTemp !=
Sites.end(); ++itTemp) {
483 if(itTemp->second->innerEdge[0]) {
484 if(itTemp->second->outerEdge) {
488 EV <<
"[NeighborsList::buildVoronoi()]\n"
489 <<
" Site at [" << itTemp->second->coord.x <<
", "
490 << itTemp->second->coord.y <<
"] is a boundary neighbor."
497 EV <<
"[NeighborsList::buildVoronoi()]\n"
498 <<
" Site at [" << itTemp->second->coord.x <<
", "
499 << itTemp->second->coord.y <<
"] is a neighbor."
508 EV <<
"[NeighborsList::buildVoronoi()]\n"
509 <<
" Site at [" << itTemp->second->coord.x <<
", "
510 << itTemp->second->coord.y <<
"] is a boundary neighbor."
513 if(!itTemp->second->innerEdge[1] && itTemp->second->innerEdge[2]) {
514 itTemp->second->type |=
NEW;
517 EV <<
"[NeighborsList::buildVoronoi()]\n"
518 <<
" Site at [" << itTemp->second->coord.x <<
", "
519 << itTemp->second->coord.y <<
"] is a new neighbor for site at " << new_pos.
x <<
":" << new_pos.
y <<
"."
524 Site* tempSite =
Sites.find(enclosingCheck)->second;
525 for(EnclosingSet::iterator itSet = tempSite->
enclosingSet.begin(); itSet != tempSite->
enclosingSet.end(); ++itSet) {
528 Sites.find(*itSet)->second->type |=
NEW;
534 itTemp->second->innerEdge[0] =
false;
535 itTemp->second->innerEdge[1] =
false;
536 itTemp->second->innerEdge[2] =
false;
537 itTemp->second->outerEdge =
false;
552 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end();) {
554 if(itSites->second->type ==
UNDEF) {
556 if(
debugOutput) EV <<
"[NeighborsList::removeNeighbors()]\n"
557 <<
" Site at [" << itSites->second->coord.x <<
", " << itSites->second->coord.y
558 <<
"] has been removed from list."
561 delete itSites->second;
562 Sites.erase(itSites++);
596 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
606 vastListMsg->setBitLength(
VASTLIST_L(vastListMsg));
608 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
627 bool abnormalLeave =
false;
628 bool boundaryLeave =
false;
629 std::set<NodeHandle> removeSet;
630 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
631 if(itSites->second->tstamp < 0.0) {
632 abnormalLeave =
true;
633 if(!(itSites->second->type &
NEIGHBOR)) boundaryLeave =
true;
634 itSites->second->type =
UNDEF;
635 removeSet.insert( itSites->first );
637 else if(itSites->second->tstamp < simTime() -
pingTimeout) {
640 vastMsg->setBitLength(
VAST_L(vastMsg));
642 itSites->second->tstamp = -1.0;
647 for( std::set<NodeHandle>::iterator it = removeSet.begin(); it != removeSet.end(); ++it) {
652 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
653 if(itSites->second->type &
BOUNDARY) {
656 vastMsg->setBitLength(
VAST_L(vastMsg));
680 double NeighborLevel;
682 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
683 if(itSites->second->neighborCount > 0) {
684 NeighborSum += itSites->second->neighborCount;
687 NeighborLevel = (double)(
Sites.size() *
Sites.size()) / (
double)NeighborSum;
696 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
701 vastListMsg->setBitLength(
VASTLIST_L(vastListMsg));
702 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
715 for(StockList::iterator itStock =
Stock.begin(); itStock !=
Stock.end(); ++itStock) {
720 vastMoveMsg->setBitLength(
VASTMOVE_L(vastMoveMsg));
739 vastMsg->setBitLength(
VAST_L(vastMsg));
761 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
766 vastMoveMsg->setBitLength(
VASTMOVE_L(vastMoveMsg));
774 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
777 vastMsg->encapsulate((cPacket*)msg->
dup());
785 Site *forwardSite = NULL;
790 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
792 if(itSites->second->coord.distanceSqr(vastMsg->
getPos()) < min_dist && itSites->second->neighborCount >= 0) {
794 forwardSite = itSites->second;
798 if(min_dist == 0.0) {
810 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
816 vastListMsg->setBitLength(
VASTLIST_L(vastListMsg));
848 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
854 vastMoveMsg->setBitLength(
VASTMOVE_L(vastMoveMsg));
864 SIMTIME_DBL(simTime()) - SIMTIME_DBL(vastMoveMsg->getCreationTime())
869 old_p = vastMoveMsg->
getPos();
885 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
896 vastListMsg->setBitLength(
VASTLIST_L(vastListMsg));
923 vastMsg->setBitLength(
VAST_L(vastMsg));
956 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
966 vastListMsg->setBitLength(
VASTLIST_L(vastListMsg));
989 vastPongMsg->setBitLength(
VAST_L(vastPongMsg));
1027 vastDiscardMsg->setBitLength(
VASTDISCARD_L(vastDiscardMsg));
1040 int remSize, addSize;
1041 remSize = addSize = 0;
1042 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
1043 if(itSites->second->type ==
UNDEF) {
1047 else if(!itSites->second->isAdded) {
1050 itSites->second->isAdded =
true;
1080 <<
" Node " <<
thisSite.
addr.
getIp() <<
" sending " << msg->getName() <<
" to application."
1082 send(msg,
"appOut");
1124 <<
" Node " <<
thisSite.
addr.
getIp() <<
" sending " << vastMsg->getName() <<
" to " << destAddr.
getIp() <<
"."
1143 getParentModule()->getParentModule()->getDisplayString().setTagArg(
"i2", 1,
"green");
1144 getDisplayString().setTagArg(
"i", 1,
"green");
1147 getParentModule()->getParentModule()->getDisplayString().setTagArg(
"i2", 1,
"yellow");
1148 getDisplayString().setTagArg(
"i", 1,
"yellow");
1151 getParentModule()->getParentModule()->getDisplayString().setTagArg(
"i2", 1,
"red");
1152 getDisplayString().setTagArg(
"i", 1,
"red");
1183 Enter_Method_Silent();
1189 Enter_Method_Silent();
1195 Enter_Method_Silent();
1201 Enter_Method_Silent();
1208 for(SiteMap::iterator itSites =
Sites.begin(); itSites !=
Sites.end(); ++itSites) {
1209 delete itSites->second;