#include <ChannelControl.h>
Public Types | |
| typedef HostEntry * | HostRef |
| typedef std::vector< cModule * > | ModuleList |
Public Member Functions | |
| HostRef | registerHost (cModule *host, const Coord &initialPos) |
| Registers the given host. | |
| HostRef | lookupHost (cModule *host) |
| Returns the "handle" of a previously registered host. | |
| void | updateHostPosition (HostRef h, const Coord &pos) |
| To be called when the host moved; updates proximity info. | |
| const Coord & | getHostPosition (HostRef h) |
| Returns the host's position. | |
| const ModuleList & | getNeighbors (HostRef h) |
| Get the list of modules in range of the given host. | |
| double | getCommunicationRange (HostRef h) |
| Reads init parameters and calculates a maximal interference distance. | |
| const Coord * | getPgs () |
| Returns the playground size. | |
Protected Member Functions | |
| void | updateConnections (HostRef h) |
| virtual double | calcInterfDist () |
| Calculate interference distance. | |
| void | updateDisplayString (cModule *playgroundMod) |
| Set up playground module's display string. | |
| virtual void | initialize () |
| Reads init parameters and calculates a maximal interference distance. | |
Protected Attributes | |
| typedef std::list< HostEntry > | HostList |
| HostList | hosts |
| bool | coreDebug |
| Set debugging for the basic module. | |
| Coord | playgroundSize |
| x and y size of the area the nodes are in (in meters) | |
| double | maxInterferenceDistance |
| the biggest interference distance in the network. | |
Friends | |
| std::ostream & | operator<< (std::ostream &, const HostEntry &) |
Classes | |
| struct | HostEntry |
|
|
|
|
|
|
|
|
Calculate interference distance. Calculation of the interference distance based on the transmitter power, wavelength, pathloss coefficient and a threshold for the minimal receive Power You may want to overwrite this function in order to do your own interference calculation 00081 {
00082 double SPEED_OF_LIGHT = 300000000.0;
00083 double interfDistance;
00084
00085 //the carrier frequency used
00086 double carrierFrequency = par("carrierFrequency");
00087 //maximum transmission power possible
00088 double pMax = par("pMax");
00089 //signal attenuation threshold
00090 double sat = par("sat");
00091 //path loss coefficient
00092 double alpha = par("alpha");
00093
00094 double waveLength = (SPEED_OF_LIGHT / carrierFrequency);
00095 //minimum power level to be able to physically receive a signal
00096 double minReceivePower = pow(10.0, sat / 10.0);
00097
00098 interfDistance = pow(waveLength * waveLength * pMax /
00099 (16.0 * M_PI * M_PI * minReceivePower), 1.0 / alpha);
00100
00101 coreEV << "max interference distance:" << interfDistance << endl;
00102
00103 return interfDistance;
00104 }
|
|
|
Reads init parameters and calculates a maximal interference distance.
00098 {
00099 return maxInterferenceDistance; // FIXME this is rather the max...
00100 }
|
|
|
Returns the host's position.
00092 {return h->pos;}
|
|
|
Get the list of modules in range of the given host.
00129 {
00130 if (!h->isModuleListValid)
00131 {
00132 h->neighborModules.clear();
00133 for (std::set<HostRef>::const_iterator it = h->neighbors.begin(); it != h->neighbors.end(); it++)
00134 h->neighborModules.push_back((*it)->host);
00135 h->isModuleListValid = true;
00136 }
00137 return h->neighborModules;
00138 }
|
|
|
Returns the playground size.
00103 {return &playgroundSize;}
|
|
|
Reads init parameters and calculates a maximal interference distance. Sets up the playgroundSize and calculates the maxInterferenceDistance 00043 {
00044 coreDebug = hasPar("coreDebug") ? (bool) par("coreDebug") : false;
00045
00046 coreEV << "initializing ChannelControl\n";
00047
00048 playgroundSize.x = par("playgroundSizeX");
00049 playgroundSize.y = par("playgroundSizeY");
00050
00051 maxInterferenceDistance = calcInterfDist();
00052
00053 WATCH(maxInterferenceDistance);
00054 WATCH_LIST(hosts);
00055
00056 updateDisplayString(parentModule());
00057 }
|
|
|
Returns the "handle" of a previously registered host.
00121 {
00122 for (HostList::iterator it = hosts.begin(); it != hosts.end(); it++)
00123 if (it->host == host)
00124 return &(*it);
00125 return 0;
00126 }
|
|
||||||||||||
|
Registers the given host.
00107 {
00108 if (lookupHost(host) != NULL)
00109 error("ChannelControl::registerHost(): host (%s)%s already registered",
00110 host->className(), host->fullPath().c_str());
00111
00112 HostEntry he;
00113 he.host = host;
00114 he.pos = initialPos;
00115 he.isModuleListValid = false;
00116 hosts.push_back(he);
00117 return &hosts.back(); // last element
00118 }
|
|
|
00141 {
00142 Coord& hpos = h->pos;
00143 double maxDistSquared = maxInterferenceDistance * maxInterferenceDistance;
00144 for (HostList::iterator it = hosts.begin(); it != hosts.end(); ++it)
00145 {
00146 HostEntry *hi = &(*it);
00147 if (hi == h)
00148 continue;
00149
00150 // get the distance between the two hosts.
00151 // (omitting the square root (calling sqrdist() instead of distance()) saves about 5% CPU)
00152 bool inRange = hpos.sqrdist(hi->pos) < maxDistSquared;
00153
00154 if (inRange)
00155 {
00156 // nodes within communication range: connect
00157 if (h->neighbors.insert(hi).second == true)
00158 {
00159 hi->neighbors.insert(h);
00160 h->isModuleListValid = hi->isModuleListValid = false;
00161 }
00162 }
00163 else
00164 {
00165 // out of range: disconnect
00166 if (h->neighbors.erase(hi))
00167 {
00168 hi->neighbors.erase(h);
00169 h->isModuleListValid = hi->isModuleListValid = false;
00170 }
00171 }
00172 }
00173 }
|
|
|
Set up playground module's display string. Sets up background size by adding the following tags: "p=0,0;b=$playgroundSizeX,$playgroundSizeY" 00064 {
00065 cDisplayString& d = playgroundMod->backgroundDisplayString();
00066 d.setTagArg("p", 0, 0L);
00067 d.setTagArg("p", 1, 0L);
00068 d.setTagArg("b", 0, playgroundSize.x);
00069 d.setTagArg("b", 1, playgroundSize.y);
00070 }
|
|
||||||||||||
|
To be called when the host moved; updates proximity info.
00086 {
00087 h->pos = pos;
00088 updateConnections(h);
00089 }
|
|
||||||||||||
|
00029 {
00030 os << h.host->fullPath() << " (x=" << h.pos.x << ",y=" << h.pos.y << "), "
00031 << h.neighbors.size() << " neighbor(s)";
00032 return os;
00033 }
|
|
|
Set debugging for the basic module.
|
|
|
|
|
|
|
|
|
the biggest interference distance in the network.
|
|
|
x and y size of the area the nodes are in (in meters)
|
1.4.1