#include <Repository.h>
Public Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
virtual | ~Repository () |
void | setPosition_size (int size) |
int | getPosition_size () |
Vector & | getPosition (int k) |
void | setPosition (int k, const Vector &Position) |
int | getCounter () |
void | setCounter (int Counter) |
Protected Member Functions | |
void | testConnectivity (cTopology::Node *node) |
cTopology::Node * | getNodeByHandle (NodeHandle nodeHandle) |
Protected Attributes | |
NeighborsList * | neighborsList |
Vector * | Position |
int | Position_size |
int | Counter |
int | testCounter |
double | connectivityCheckTimeout |
cMessage * | check_timer |
cTopology | topology |
Repository::~Repository | ( | ) | [virtual] |
void Repository::initialize | ( | ) | [virtual] |
00029 { 00030 Position_size = 0; 00031 Counter = 0; 00032 testCounter = 0; 00033 Position = NULL; 00034 00035 // fetch parameters 00036 connectivityCheckTimeout = par("connectivityCheckTimeout"); 00037 connectivityCheckTimeout *= 60.0; 00038 00039 neighborsList = check_and_cast<NeighborsList*>(parentModule()->submodule("neighborsList")); 00040 neighborsList->setDebug(false); 00041 00042 // self-messages 00043 check_timer = new cMessage("check_timer"); 00044 scheduleAt(simulation.simTime() + connectivityCheckTimeout, check_timer); 00045 }
void Repository::handleMessage | ( | cMessage * | msg | ) | [virtual] |
00057 { 00058 // catch self timer messages 00059 if(msg->isName("check_timer")) { 00060 //reset timer 00061 cancelEvent(check_timer); 00062 scheduleAt(simulation.simTime() + connectivityCheckTimeout, msg); 00063 // handle event 00064 int i, j, connected, localNeighbors, globalNeighbors, superfluousNeighbors, missingNeighbors; 00065 std::stringstream vecName, vecName2; 00066 Vast *vast; 00067 Site *site; 00068 00069 vecName << "Neighbor Count " << ++testCounter; 00070 vecName2 << "Neighbor Deviation " << testCounter; 00071 00072 cOutVector cOV_NeighborCount(vecName.str().c_str()); 00073 cOutVector cOV_NeighborDeviation(vecName2.str().c_str(), 2); 00074 00075 topology.extractFromNetwork(selectFunction, NULL); 00076 // depth-search through topology 00077 if(topology.nodes()) testConnectivity(topology.node(0)); 00078 00079 connected = 0; 00080 for(i=0; i<topology.nodes(); i++) { 00081 if(topology.node(i)->enabled()) { 00082 connected++; 00083 } 00084 } 00085 recordScalar("Topology disconnected nodes", connected); 00086 00087 for(i=0; i<topology.nodes(); i++) { 00088 vast = check_and_cast<Vast*>(topology.node(i)->module()); 00089 neighborsList->initializeList(vast->getPosition(), vast->getThisNode(), vast->getAOI()); 00090 for(j=0; j<topology.nodes(); j++) { 00091 if(j != i) { 00092 vast = check_and_cast<Vast*>(topology.node(j)->module()); 00093 neighborsList->addNode(vast->getPosition(), vast->getThisNode()); 00094 } 00095 } 00096 neighborsList->buildVoronoi(); 00097 neighborsList->removeNeighbors(); 00098 00099 // compare global with local voronoi 00100 vast = check_and_cast<Vast*>(topology.node(i)->module()); 00101 00102 localNeighbors = vast->getList()->getSize(); 00103 globalNeighbors = neighborsList->getSize(); 00104 00105 // output total neighbors 00106 cOV_NeighborCount.record((double)localNeighbors); 00107 00108 // iterate through local voronoi and delete global entries which match 00109 SiteMap::iterator itSites = vast->getList()->Sites.begin(); 00110 while(itSites != vast->getList()->Sites.end()) { 00111 neighborsList->removeNode(itSites->second.addr); 00112 ++itSites; 00113 } 00114 00115 // output results (number of neighbors missing in local voronoi, number of superfluous neighbors in local voronoi 00116 missingNeighbors = neighborsList->getSize(); 00117 superfluousNeighbors = localNeighbors - globalNeighbors + missingNeighbors; 00118 cOV_NeighborDeviation.record((double)missingNeighbors, (double)superfluousNeighbors); 00119 00120 // reset the list 00121 neighborsList->clearList(); 00122 } 00123 topology.clear(); 00124 } 00125 }
void Repository::setPosition_size | ( | int | size | ) |
00157 { 00158 Enter_Method_Silent(); 00159 Vector *Temp = (size == 0) ? NULL : new Vector[size]; 00160 int min_size = Position_size < size ? Position_size : size; 00161 for(int i=0; i<min_size; i++) Temp[i] = this->Position[i]; 00162 Position_size = size; 00163 delete[] this->Position; 00164 this->Position = Temp; 00165 }
int Repository::getPosition_size | ( | ) |
Vector & Repository::getPosition | ( | int | k | ) |
00174 { 00175 Enter_Method_Silent(); 00176 if(k >= Position_size || k < 0) throw new cException("Array out of bounds exception! getPosition(%d)", k); 00177 return Position[k]; 00178 }
void Repository::setPosition | ( | int | k, | |
const Vector & | Position | |||
) |
00181 { 00182 Enter_Method_Silent(); 00183 if(k >= Position_size || k < 0) throw new cException("Array out of bounds exception! setPosition(%d, ...)", k); 00184 this->Position[k] = Position; 00185 }
int Repository::getCounter | ( | ) |
void Repository::setCounter | ( | int | Counter | ) |
void Repository::testConnectivity | ( | cTopology::Node * | node | ) | [protected] |
00140 { 00141 Vast *vast; 00142 Site *site; 00143 00144 node->disable(); 00145 vast = check_and_cast<Vast*>(node->module()); 00146 00147 SiteMap::iterator itSites = vast->getList()->Sites.begin(); 00148 while(itSites != vast->getList()->Sites.end()) { 00149 cTopology::Node *newNode; 00150 newNode = getNodeByHandle(itSites->second.addr); 00151 if(newNode != NULL && newNode->enabled()) testConnectivity(newNode); 00152 ++itSites; 00153 } 00154 }
cTopology::Node * Repository::getNodeByHandle | ( | NodeHandle | nodeHandle | ) | [protected] |
00128 { 00129 Vast *vast; 00130 for(int i=0; i<topology.nodes(); i++) { 00131 vast = check_and_cast<Vast*>(topology.node(i)->module()); 00132 if(vast->getThisNode() == nodeHandle) { 00133 return topology.node(i); 00134 } 00135 } 00136 return NULL; 00137 }
NeighborsList* Repository::neighborsList [protected] |
Vector* Repository::Position [protected] |
int Repository::Position_size [protected] |
int Repository::Counter [protected] |
int Repository::testCounter [protected] |
double Repository::connectivityCheckTimeout [protected] |
cMessage* Repository::check_timer [protected] |
cTopology Repository::topology [protected] |