#include <ChannelControl.h>
Public Types | |
typedef HostEntry * | HostRef |
typedef std::vector< cModule * > | ModuleList |
typedef std::list< AirFrame * > | TransmissionList |
Public Member Functions | |
ChannelControl () | |
~ChannelControl () | |
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. | |
void | updateHostChannel (HostRef h, const int channel) |
Called when host switches channel. | |
const TransmissionList & | getOngoingTransmissions (const int channel) |
Provides a list of transmissions currently on the air. | |
void | addOngoingTransmission (HostRef h, AirFrame *frame) |
Notifies the channel control with an ongoing transmission. | |
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. | |
const int | getNumChannels () |
Returns the number of radio channels (frequencies) simulated. | |
Protected Types | |
typedef std::list< HostEntry > | HostList |
typedef std::vector< TransmissionList > | ChannelTransmissionLists |
keeps track of ongoing transmissions; this is needed when a host switches to another channel (then it needs to know whether the target channel is empty or busy) | |
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. | |
void | purgeOngoingTransmissions () |
Throws away expired transmissions. | |
void | checkChannel (const int channel) |
Validate the channel identifier. | |
Protected Attributes | |
HostList | hosts |
ChannelTransmissionLists | transmissions |
double | lastOngoingTransmissionsUpdate |
used to clear the transmission list from time to time | |
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. | |
int | numChannels |
the number of controlled channels | |
Friends | |
std::ostream & | operator<< (std::ostream &, const HostEntry &) |
std::ostream & | operator<< (std::ostream &, const TransmissionList &) |
Classes | |
struct | HostEntry |
|
keeps track of ongoing transmissions; this is needed when a host switches to another channel (then it needs to know whether the target channel is empty or busy)
|
|
|
|
|
|
|
|
|
|
00043 { 00044 }
|
|
00047 { 00048 for (unsigned int i = 0; i < transmissions.size(); i++) 00049 for (TransmissionList::iterator it = transmissions[i].begin(); it != transmissions[i].end(); it++) 00050 delete *it; 00051 }
|
|
Notifies the channel control with an ongoing transmission.
00234 { 00235 Enter_Method_Silent(); 00236 00237 // we only keep track of ongoing transmissions so that we can support 00238 // NICs switching channels -- so there's no point doing it if there's only 00239 // one channel 00240 if (numChannels==1) 00241 { 00242 delete frame; 00243 return; 00244 } 00245 00246 // purge old transmissions from time to time 00247 if (simTime() - lastOngoingTransmissionsUpdate > TRANSMISSION_PURGE_INTERVAL) 00248 { 00249 purgeOngoingTransmissions(); 00250 lastOngoingTransmissionsUpdate = simTime(); 00251 } 00252 00253 // register ongoing transmission 00254 take(frame); 00255 frame->setTimestamp(); // store time of transmission start 00256 transmissions[frame->getChannelNumber()].push_back(frame); 00257 }
|
|
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 00104 { 00105 double SPEED_OF_LIGHT = 300000000.0; 00106 double interfDistance; 00107 00108 //the carrier frequency used 00109 double carrierFrequency = par("carrierFrequency"); 00110 //maximum transmission power possible 00111 double pMax = par("pMax"); 00112 //signal attenuation threshold 00113 double sat = par("sat"); 00114 //path loss coefficient 00115 double alpha = par("alpha"); 00116 00117 double waveLength = (SPEED_OF_LIGHT / carrierFrequency); 00118 //minimum power level to be able to physically receive a signal 00119 double minReceivePower = pow(10.0, sat / 10.0); 00120 00121 interfDistance = pow(waveLength * waveLength * pMax / 00122 (16.0 * M_PI * M_PI * minReceivePower), 1.0 / alpha); 00123 00124 coreEV << "max interference distance:" << interfDistance << endl; 00125 00126 return interfDistance; 00127 }
|
|
Validate the channel identifier.
00204 {
00205 if (channel >= numChannels || channel < 0)
00206 error("Invalid channel, must be between 0 and %d", numChannels);
00207 }
|
|
Reads init parameters and calculates a maximal interference distance.
00140 { 00141 return maxInterferenceDistance; 00142 }
|
|
Returns the host's position.
00134 {return h->pos;}
|
|
Get the list of modules in range of the given host.
00156 { 00157 Enter_Method_Silent(); 00158 if (!h->isModuleListValid) 00159 { 00160 h->neighborModules.clear(); 00161 for (std::set<HostRef>::const_iterator it = h->neighbors.begin(); it != h->neighbors.end(); it++) 00162 h->neighborModules.push_back((*it)->host); 00163 h->isModuleListValid = true; 00164 } 00165 return h->neighborModules; 00166 }
|
|
Returns the number of radio channels (frequencies) simulated.
00148 {return numChannels;}
|
|
Provides a list of transmissions currently on the air.
00225 { 00226 Enter_Method_Silent(); 00227 00228 checkChannel(channel); 00229 purgeOngoingTransmissions(); 00230 return transmissions[channel]; 00231 }
|
|
Returns the playground size.
00145 {return &playgroundSize;}
|
|
Reads init parameters and calculates a maximal interference distance. Sets up the playgroundSize and calculates the maxInterferenceDistance 00060 { 00061 coreDebug = hasPar("coreDebug") ? (bool) par("coreDebug") : false; 00062 00063 coreEV << "initializing ChannelControl\n"; 00064 00065 playgroundSize.x = par("playgroundSizeX"); 00066 playgroundSize.y = par("playgroundSizeY"); 00067 00068 numChannels = par("numChannels"); 00069 transmissions.resize(numChannels); 00070 00071 lastOngoingTransmissionsUpdate = 0; 00072 00073 maxInterferenceDistance = calcInterfDist(); 00074 00075 WATCH(maxInterferenceDistance); 00076 WATCH_LIST(hosts); 00077 WATCH_VECTOR(transmissions); 00078 00079 updateDisplayString(parentModule()); 00080 }
|
|
Returns the "handle" of a previously registered host.
00147 { 00148 Enter_Method_Silent(); 00149 for (HostList::iterator it = hosts.begin(); it != hosts.end(); it++) 00150 if (it->host == host) 00151 return &(*it); 00152 return 0; 00153 }
|
|
Throws away expired transmissions.
00260 { 00261 for (int i = 0; i < numChannels; i++) 00262 { 00263 for (TransmissionList::iterator it = transmissions[i].begin(); it != transmissions[i].end();) 00264 { 00265 TransmissionList::iterator curr = it; 00266 AirFrame *frame = *it; 00267 it++; 00268 00269 if (frame->timestamp() + frame->getDuration() + TRANSMISSION_PURGE_INTERVAL < simTime()) 00270 { 00271 delete frame; 00272 transmissions[i].erase(curr); 00273 } 00274 } 00275 } 00276 }
|
|
Registers the given host.
00130 { 00131 Enter_Method_Silent(); 00132 if (lookupHost(host) != NULL) 00133 error("ChannelControl::registerHost(): host (%s)%s already registered", 00134 host->className(), host->fullPath().c_str()); 00135 00136 HostEntry he; 00137 he.host = host; 00138 he.pos = initialPos; 00139 he.isModuleListValid = false; 00140 // TODO: get it from caller 00141 he.channel = 0; 00142 hosts.push_back(he); 00143 return &hosts.back(); // last element 00144 }
|
|
00169 { 00170 Coord& hpos = h->pos; 00171 double maxDistSquared = maxInterferenceDistance * maxInterferenceDistance; 00172 for (HostList::iterator it = hosts.begin(); it != hosts.end(); ++it) 00173 { 00174 HostEntry *hi = &(*it); 00175 if (hi == h) 00176 continue; 00177 00178 // get the distance between the two hosts. 00179 // (omitting the square root (calling sqrdist() instead of distance()) saves about 5% CPU) 00180 bool inRange = hpos.sqrdist(hi->pos) < maxDistSquared; 00181 00182 if (inRange) 00183 { 00184 // nodes within communication range: connect 00185 if (h->neighbors.insert(hi).second == true) 00186 { 00187 hi->neighbors.insert(h); 00188 h->isModuleListValid = hi->isModuleListValid = false; 00189 } 00190 } 00191 else 00192 { 00193 // out of range: disconnect 00194 if (h->neighbors.erase(hi)) 00195 { 00196 hi->neighbors.erase(h); 00197 h->isModuleListValid = hi->isModuleListValid = false; 00198 } 00199 } 00200 } 00201 }
|
|
Set up playground module's display string. Sets up background size by adding the following tags: "p=0,0;b=$playgroundSizeX,$playgroundSizeY" 00087 { 00088 cDisplayString& d = playgroundMod->backgroundDisplayString(); 00089 d.setTagArg("p", 0, 0L); 00090 d.setTagArg("p", 1, 0L); 00091 d.setTagArg("b", 0, (long) playgroundSize.x); 00092 d.setTagArg("b", 1, (long) playgroundSize.y); 00093 }
|
|
Called when host switches channel.
00217 { 00218 Enter_Method_Silent(); 00219 checkChannel(channel); 00220 00221 h->channel = channel; 00222 }
|
|
To be called when the host moved; updates proximity info.
00210 { 00211 Enter_Method_Silent(); 00212 h->pos = pos; 00213 updateConnections(h); 00214 }
|
|
00036 { 00037 for (ChannelControl::TransmissionList::const_iterator it = tl.begin(); it != tl.end(); ++it) 00038 os << endl << *it; 00039 return os; 00040 }
|
|
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.
|
|
|
|
used to clear the transmission list from time to time
|
|
the biggest interference distance in the network.
|
|
the number of controlled channels
|
|
x and y size of the area the nodes are in (in meters)
|
|
|