OverSim
ConnectivityProbeApp.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
25 #include "ConnectivityProbeApp.h"
26 
28 
30 {
32  probeIntervall = par("connectivityProbeIntervall");
33  probeTimer = new cMessage("probeTimer");
34 
35  if(probeIntervall > 0.0) {
36  scheduleAt(simTime() + probeIntervall, probeTimer);
37 
38  cOV_NodeCount.setName("total node count");
39  cOV_ZeroMissingNeighbors.setName("neighbor-error free nodes");
40  cOV_AverageMissingNeighbors.setName("average missing neighbors per node");
41  cOV_MaxMissingNeighbors.setName("largest missing neighbors count");
42  cOV_AverageDrift.setName("average drift");
43  }
44 
45 }
46 
48 {
49  // fill topology with all modules
51 
52  if(Topology.size() == 0) {
53  return;
54  }
55 
56  // catch self timer messages
57  if(msg->isName("probeTimer")) {
58  //reset timer
59  cancelEvent(probeTimer);
60  scheduleAt(simTime() + probeIntervall, msg);
61 
62  int mnMax = 0;
63  int mnZero = 0;
64  int driftCount = 0;
65  double mnAverage = 0.0;
66  double drift = 0.0;
67 
68  for(std::map<NodeHandle, SimpleGameClient*>::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
69  int missing = 0;
70  Vector2D pos = itTopology->second->getPosition();
71  double AOIWidth = itTopology->second->getAOI();
72  for(std::map<NodeHandle, SimpleGameClient*>::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
73  if(itI != itTopology && pos.distanceSqr(itI->second->getPosition()) <= AOIWidth*AOIWidth) {
74  NeighborMap::iterator currentSite = itTopology->second->Neighbors.find(itI->second->getThisNode());
75  if(currentSite == itTopology->second->Neighbors.end()) {
76  ++missing;
77  }
78  else {
79  drift += sqrt(currentSite->second.position.distanceSqr(itI->second->getPosition()));
80  ++driftCount;
81  }
82  }
83  }
84 
85  mnAverage += missing;
86  if(mnMax < missing) {
87  mnMax = missing;
88  }
89  if(missing == 0) {
90  ++mnZero;
91  }
92  }
93  mnAverage /= (double)Topology.size();
94  if(driftCount > 0) {
95  drift /= (double)driftCount;
96  }
97 
98  cOV_ZeroMissingNeighbors.record((double)mnZero);
99  RECORD_STATS (
100  globalStatistics->addStdDev("ConnectivityProbe: percentage zero missing neighbors", (double)mnZero * 100.0 / (double)Topology.size());
101  globalStatistics->addStdDev("ConnectivityProbe: average drift", drift);
102  );
103  cOV_AverageMissingNeighbors.record(mnAverage);
104  cOV_MaxMissingNeighbors.record((double)mnMax);
105  cOV_AverageDrift.record(drift);
106  }
107  Topology.clear();
108 }
109 
111 {
112  for(int i=0; i<=simulation.getLastModuleId(); i++) {
113  cModule* module = simulation.getModule(i);
114  SimpleGameClient* client;
115  if((client = dynamic_cast<SimpleGameClient*>(module))) {
116 
117  if(client->isOverlayReady()) {
118  Topology.insert(std::make_pair(client->getThisNode(), client));
119  }
120  }
121  }
122 }
123 
125 {
126  // destroy self timer messages
127  cancelAndDelete(probeTimer);
128 }