ConnectivityProbe.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include "ConnectivityProbe.h"
00025
00026 Define_Module(ConnectivityProbe);
00027
00028 VTopologyNode::VTopologyNode(int moduleID)
00029 {
00030 this->moduleID = moduleID;
00031 visited = false;
00032 }
00033
00034 Vast* VTopologyNode::getModule() const
00035 {
00036 return check_and_cast<Vast*>(simulation.getModule(moduleID));
00037 }
00038
00039 void ConnectivityProbe::initialize()
00040 {
00041 globalStatistics = GlobalStatisticsAccess().get();
00042 probeIntervall = par("connectivityProbeIntervall");
00043 plotIntervall = par("visualizeNetworkIntervall");
00044 probeTimer = new cMessage("probeTimer");
00045 plotTimer = new cMessage("plotTimer");
00046 plotConnections = par("plotConnections");
00047 plotMissing= par("plotMissing");
00048
00049 if(probeIntervall > 0.0) {
00050 scheduleAt(simTime() + probeIntervall, probeTimer);
00051
00052 cOV_NodeCount.setName("total node count");
00053 cOV_MaximumComponent.setName("largest connected component");
00054 cOV_MaxConnectivity.setName("connectivity in percent");
00055 cOV_ZeroMissingNeighbors.setName("neighbor-error free nodes");
00056 cOV_AverageMissingNeighbors.setName("average missing neighbors per node");
00057 cOV_MaxMissingNeighbors.setName("largest missing neighbors count");
00058 cOV_AverageDrift.setName("average drift");
00059 }
00060
00061 if(plotIntervall > 0.0) {
00062 scheduleAt(simTime() + plotIntervall, plotTimer);
00063 }
00064 }
00065
00066 void ConnectivityProbe::handleMessage(cMessage* msg)
00067 {
00068
00069 extractTopology();
00070
00071 if(Topology.size() == 0) {
00072 return;
00073 }
00074
00075
00076 if(msg->isName("probeTimer")) {
00077
00078 cancelEvent(probeTimer);
00079 scheduleAt(simTime() + probeIntervall, msg);
00080
00081 unsigned int maxComponent = 0;
00082 for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00083 unsigned int count = getComponentSize(itTopology->second.getModule()->getHandle().getKey());
00084 if(count > maxComponent) {
00085 maxComponent = count;
00086 }
00087 resetTopologyNodes();
00088 if(count == Topology.size()) {
00089 break;
00090 }
00091 }
00092
00093 cOV_NodeCount.record((double)Topology.size());
00094 cOV_MaximumComponent.record((double)maxComponent);
00095 cOV_MaxConnectivity.record((double)maxComponent * 100.0 / (double)Topology.size());
00096 RECORD_STATS (
00097 globalStatistics->addStdDev("ConnectivityProbe: max connectivity", (double)maxComponent * 100.0 / (double)Topology.size());
00098 );
00099
00100 int mnMax = 0;
00101 int mnZero = 0;
00102 int driftCount = 0;
00103 double mnAverage = 0.0;
00104 double drift = 0.0;
00105
00106 for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00107 double AOIWidthSqr = itTopology->second.getModule()->getAOI();
00108 AOIWidthSqr *= AOIWidthSqr;
00109 Vector2D vastPosition = itTopology->second.getModule()->getPosition();
00110 int missing = 0;
00111 for(VTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00112 if(itI != itTopology && vastPosition.distanceSqr(itI->second.getModule()->getPosition()) <= AOIWidthSqr) {
00113 SiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getHandle());
00114 if(currentSite == itTopology->second.getModule()->Sites.end()) {
00115 ++missing;
00116 }
00117 else {
00118 drift += sqrt(currentSite->second->coord.distanceSqr(itI->second.getModule()->getPosition()));
00119 ++driftCount;
00120 }
00121 }
00122 }
00123
00124 mnAverage += missing;
00125 if(mnMax < missing) {
00126 mnMax = missing;
00127 }
00128 if(missing == 0) {
00129 ++mnZero;
00130 }
00131 }
00132 mnAverage /= (double)Topology.size();
00133 if(driftCount > 0) {
00134 drift /= (double)driftCount;
00135 }
00136
00137 cOV_ZeroMissingNeighbors.record((double)mnZero);
00138 RECORD_STATS (
00139 globalStatistics->addStdDev("ConnectivityProbe: percentage zero missing neighbors", (double)mnZero * 100.0 / (double)Topology.size());
00140 globalStatistics->addStdDev("ConnectivityProbe: average drift", drift);
00141 );
00142 cOV_AverageMissingNeighbors.record(mnAverage);
00143 cOV_MaxMissingNeighbors.record((double)mnMax);
00144 cOV_AverageDrift.record(drift);
00145 }
00146 else if(msg->isName("plotTimer")) {
00147
00148 cancelEvent(plotTimer);
00149 scheduleAt(simTime() + plotIntervall, msg);
00150
00151 bool missingFound = false;
00152 if(plotMissing) {
00153 for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00154 double AOIWidthSqr = itTopology->second.getModule()->getAOI();
00155 AOIWidthSqr *= AOIWidthSqr;
00156 Vector2D vastPosition = itTopology->second.getModule()->getPosition();
00157 for(VTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00158 if(itI != itTopology && vastPosition.distanceSqr(itI->second.getModule()->getPosition()) <= AOIWidthSqr) {
00159 SiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getHandle());
00160 if(currentSite == itTopology->second.getModule()->Sites.end()) {
00161 missingFound=true;
00162 }
00163 }
00164 }
00165 }
00166 }
00167
00168 if(!plotMissing || missingFound) {
00169
00170 int range = (int)Topology.begin()->second.getModule()->getAreaDimension();
00171 std::stringstream oss;
00172 std::string filename;
00173 int simTimeInt, stellen = 1;
00174 simTimeInt = (int)SIMTIME_DBL(simTime());
00175 oss << "plot";
00176 for(int i=0; i<6; i++) {
00177 if(!(simTimeInt / stellen)) {
00178 oss << "0";
00179 }
00180 stellen *= 10;
00181 }
00182 oss << simTimeInt;
00183
00184
00185 filename = oss.str() + ".plot";
00186 pltNetwork.open(filename.c_str(), std::ios::out);
00187 pltNetwork << "set xrange [0:" << range << "]" << endl;
00188 pltNetwork << "set yrange [0:" << range << "]" << endl;
00189 pltNetwork << "set nokey" << endl;
00190
00191
00192 filename = oss.str() + ".point";
00193 pltData.open(filename.c_str(), std::ios::out);
00194
00195 pltNetwork << "plot '" << filename << "' using 1:2 with points pointtype 7,\\" << endl;
00196
00197
00198 filename = oss.str() + ".arrow";
00199 pltVector.open(filename.c_str(), std::ios::out);
00200
00201 pltNetwork << " '" << filename << "' using 1:2:3:4 with vectors linetype 1" << endl;
00202 pltNetwork.close();
00203
00204
00205 for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00206 pltData << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << endl;
00207 }
00208 pltData.close();
00209
00210
00211 if(!plotMissing) {
00212 for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00213 for(SiteMap::iterator itSites = itTopology->second.getModule()->Sites.begin(); itSites != itTopology->second.getModule()->Sites.end(); ++itSites) {
00214 if(plotConnections) {
00215 VTopology::iterator destNode = Topology.find(itSites->second->addr.getKey());
00216 if(destNode != Topology.end()) {
00217 Vector2D relPos = destNode->second.getModule()->getPosition() - itTopology->second.getModule()->getPosition();
00218 pltVector << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << "\t"
00219 << relPos.x << "\t" << relPos.y << endl;
00220 }
00221 }
00222 else {
00223 Vector2D relPos = itSites->second->coord - itTopology->second.getModule()->getPosition();
00224 pltVector << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << "\t"
00225 << relPos.x << "\t" << relPos.y << endl;
00226 }
00227 }
00228 }
00229 } else {
00230 for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00231 double AOIWidthSqr = itTopology->second.getModule()->getAOI();
00232 AOIWidthSqr *= AOIWidthSqr;
00233 Vector2D vastPosition = itTopology->second.getModule()->getPosition();
00234 for(VTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00235 if(itI != itTopology && vastPosition.distanceSqr(itI->second.getModule()->getPosition()) <= AOIWidthSqr) {
00236 SiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getHandle());
00237 if(currentSite == itTopology->second.getModule()->Sites.end()) {
00238 Vector2D relPos = itI->second.getModule()->getPosition() - itTopology->second.getModule()->getPosition();
00239 pltVector << itTopology->second.getModule()->getPosition().x << "\t"
00240 << itTopology->second.getModule()->getPosition().y << "\t"
00241 << relPos.x << "\t" << relPos.y << "\t"
00242 << itTopology->second.getModule()->getParentModule()->getParentModule()->getFullName() << ":"
00243 << itTopology->second.getModule()->thisSite.addr.getKey().toString(16) << "\t"
00244 << itI->second.getModule()->getParentModule()->getParentModule()->getFullName() << ":"
00245 << itI->second.getModule()->thisSite.addr.getKey().toString(16) << endl;
00246 }
00247 }
00248 }
00249 }
00250 }
00251 pltVector.close();
00252 }
00253 }
00254 Topology.clear();
00255 }
00256
00257 void ConnectivityProbe::extractTopology()
00258 {
00259 for(int i=0; i<=simulation.getLastModuleId(); i++) {
00260 cModule* module = simulation.getModule(i);
00261 if(module && dynamic_cast<Vast*>(module)) {
00262 Vast* vast = check_and_cast<Vast*>(module);
00263 if(vast->getState() == BaseOverlay::READY) {
00264 VTopologyNode temp(i);
00265 Topology.insert(std::make_pair(vast->getHandle().getKey(), temp));
00266 }
00267 }
00268 }
00269 }
00270
00271 void ConnectivityProbe::resetTopologyNodes()
00272 {
00273 for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00274 itTopology->second.visited = false;
00275 }
00276 }
00277
00278 unsigned int ConnectivityProbe::getComponentSize(OverlayKey key)
00279 {
00280 VTopology::iterator itEntry = Topology.find(key);
00281 if(itEntry != Topology.end() && itEntry->second.visited == false) {
00282 int count = 1;
00283 itEntry->second.visited = true;
00284 Vast* vast = itEntry->second.getModule();
00285 for(SiteMap::iterator itSites = vast->Sites.begin(); itSites != vast->Sites.end(); ++itSites) {
00286 count += getComponentSize(itSites->first.getKey());
00287 }
00288 return count;
00289 }
00290 return 0;
00291 }
00292
00293 ConnectivityProbe::~ConnectivityProbe()
00294 {
00295
00296 cancelAndDelete(probeTimer);
00297 cancelAndDelete(plotTimer);
00298 }