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