#include <ChannelControl.h>
Public Types | |
typedef HostEntry * | HostRef |
typedef std::vector< cModule * > | ModuleList |
typedef std::list< AirFrame * > | TransmissionList |
Public Member Functions | |
ChannelControl () | |
virtual | ~ChannelControl () |
virtual HostRef | registerHost (cModule *host, const Coord &initialPos) |
Registers the given host. | |
virtual HostRef | lookupHost (cModule *host) |
Returns the "handle" of a previously registered host. | |
virtual void | updateHostPosition (HostRef h, const Coord &pos) |
To be called when the host moved; updates proximity info. | |
virtual 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. | |
virtual 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. | |
virtual 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. | |
Static Public Member Functions | |
static ChannelControl * | get () |
Finds the channelControl module in the network. | |
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 | |
virtual void | updateConnections (HostRef h) |
virtual double | calcInterfDist () |
Calculate interference distance. | |
virtual void | updateDisplayString (cModule *playgroundMod) |
Set up playground module's display string. | |
virtual void | initialize () |
Reads init parameters and calculates a maximal interference distance. | |
virtual void | purgeOngoingTransmissions () |
Throws away expired transmissions. | |
virtual void | checkChannel (const int channel) |
Validate the channel identifier. | |
Protected Attributes | |
HostList | hosts |
ChannelTransmissionLists | transmissions |
simtime_t | 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 |
typedef std::list<HostEntry> ChannelControl::HostList [protected] |
typedef HostEntry* ChannelControl::HostRef |
typedef std::vector<cModule*> ChannelControl::ModuleList |
typedef std::list<AirFrame*> ChannelControl::TransmissionList |
typedef std::vector<TransmissionList> ChannelControl::ChannelTransmissionLists [protected] |
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)
ChannelControl::~ChannelControl | ( | ) | [virtual] |
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 }
void ChannelControl::updateConnections | ( | HostRef | h | ) | [protected, virtual] |
Referenced by updateHostPosition().
00179 { 00180 Coord& hpos = h->pos; 00181 double maxDistSquared = maxInterferenceDistance * maxInterferenceDistance; 00182 for (HostList::iterator it = hosts.begin(); it != hosts.end(); ++it) 00183 { 00184 HostEntry *hi = &(*it); 00185 if (hi == h) 00186 continue; 00187 00188 // get the distance between the two hosts. 00189 // (omitting the square root (calling sqrdist() instead of distance()) saves about 5% CPU) 00190 bool inRange = hpos.sqrdist(hi->pos) < maxDistSquared; 00191 00192 if (inRange) 00193 { 00194 // nodes within communication range: connect 00195 if (h->neighbors.insert(hi).second == true) 00196 { 00197 hi->neighbors.insert(h); 00198 h->isModuleListValid = hi->isModuleListValid = false; 00199 } 00200 } 00201 else 00202 { 00203 // out of range: disconnect 00204 if (h->neighbors.erase(hi)) 00205 { 00206 hi->neighbors.erase(h); 00207 h->isModuleListValid = hi->isModuleListValid = false; 00208 } 00209 } 00210 } 00211 }
double ChannelControl::calcInterfDist | ( | ) | [protected, virtual] |
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
Referenced by initialize().
00114 { 00115 double SPEED_OF_LIGHT = 300000000.0; 00116 double interfDistance; 00117 00118 //the carrier frequency used 00119 double carrierFrequency = par("carrierFrequency"); 00120 //maximum transmission power possible 00121 double pMax = par("pMax"); 00122 //signal attenuation threshold 00123 double sat = par("sat"); 00124 //path loss coefficient 00125 double alpha = par("alpha"); 00126 00127 double waveLength = (SPEED_OF_LIGHT / carrierFrequency); 00128 //minimum power level to be able to physically receive a signal 00129 double minReceivePower = pow(10.0, sat / 10.0); 00130 00131 interfDistance = pow(waveLength * waveLength * pMax / 00132 (16.0 * M_PI * M_PI * minReceivePower), 1.0 / alpha); 00133 00134 coreEV << "max interference distance:" << interfDistance << endl; 00135 00136 return interfDistance; 00137 }
void ChannelControl::updateDisplayString | ( | cModule * | playgroundMod | ) | [protected, virtual] |
Set up playground module's display string.
Sets up background size by adding the following tags: "p=0,0;b=$playgroundSizeX,$playgroundSizeY"
Referenced by initialize().
00097 { 00098 cDisplayString& d = playgroundMod->getDisplayString(); 00099 d.setTagArg("bgp", 0, 0L); 00100 d.setTagArg("bgp", 1, 0L); 00101 d.setTagArg("bgb", 0, (long) playgroundSize.x); 00102 d.setTagArg("bgb", 1, (long) playgroundSize.y); 00103 }
void ChannelControl::initialize | ( | ) | [protected, virtual] |
Reads init parameters and calculates a maximal interference distance.
Sets up the playgroundSize and calculates the maxInterferenceDistance
00070 { 00071 coreDebug = hasPar("coreDebug") ? (bool) par("coreDebug") : false; 00072 00073 coreEV << "initializing ChannelControl\n"; 00074 00075 playgroundSize.x = par("playgroundSizeX"); 00076 playgroundSize.y = par("playgroundSizeY"); 00077 00078 numChannels = par("numChannels"); 00079 transmissions.resize(numChannels); 00080 00081 lastOngoingTransmissionsUpdate = 0; 00082 00083 maxInterferenceDistance = calcInterfDist(); 00084 00085 WATCH(maxInterferenceDistance); 00086 WATCH_LIST(hosts); 00087 WATCH_VECTOR(transmissions); 00088 00089 updateDisplayString(getParentModule()); 00090 }
void ChannelControl::purgeOngoingTransmissions | ( | ) | [protected, virtual] |
Throws away expired transmissions.
Referenced by addOngoingTransmission(), and getOngoingTransmissions().
00270 { 00271 for (int i = 0; i < numChannels; i++) 00272 { 00273 for (TransmissionList::iterator it = transmissions[i].begin(); it != transmissions[i].end();) 00274 { 00275 TransmissionList::iterator curr = it; 00276 AirFrame *frame = *it; 00277 it++; 00278 00279 if (frame->getTimestamp() + frame->getDuration() + TRANSMISSION_PURGE_INTERVAL < simTime()) 00280 { 00281 delete frame; 00282 transmissions[i].erase(curr); 00283 } 00284 } 00285 } 00286 }
void ChannelControl::checkChannel | ( | const int | channel | ) | [protected, virtual] |
Validate the channel identifier.
Referenced by getOngoingTransmissions(), and updateHostChannel().
00214 { 00215 if (channel >= numChannels || channel < 0) 00216 error("Invalid channel, must be between 0 and %d", numChannels); 00217 }
ChannelControl * ChannelControl::get | ( | ) | [static] |
Finds the channelControl module in the network.
Referenced by Ieee80211MgmtSTA::initialize(), ChannelAccess::initialize(), BasicMobility::initialize(), and PathLossReceptionModel::initializeFrom().
00054 { 00055 ChannelControl *cc = dynamic_cast<ChannelControl *>(simulation.getModuleByPath("channelcontrol")); 00056 if (!cc) 00057 cc = dynamic_cast<ChannelControl *>(simulation.getModuleByPath("channelControl")); 00058 if (!cc) 00059 throw cRuntimeError("Could not find ChannelControl module"); 00060 return cc; 00061 }
ChannelControl::HostRef ChannelControl::registerHost | ( | cModule * | host, | |
const Coord & | initialPos | |||
) | [virtual] |
Registers the given host.
Referenced by BasicMobility::initialize().
00140 { 00141 Enter_Method_Silent(); 00142 if (lookupHost(host) != NULL) 00143 error("ChannelControl::registerHost(): host (%s)%s already registered", 00144 host->getClassName(), host->getFullPath().c_str()); 00145 00146 HostEntry he; 00147 he.host = host; 00148 he.pos = initialPos; 00149 he.isModuleListValid = false; 00150 // TODO: get it from caller 00151 he.channel = 0; 00152 hosts.push_back(he); 00153 return &hosts.back(); // last element 00154 }
ChannelControl::HostRef ChannelControl::lookupHost | ( | cModule * | host | ) | [virtual] |
Returns the "handle" of a previously registered host.
Referenced by ChannelAccess::initialize(), registerHost(), and ChannelAccess::sendToChannel().
00157 { 00158 Enter_Method_Silent(); 00159 for (HostList::iterator it = hosts.begin(); it != hosts.end(); it++) 00160 if (it->host == host) 00161 return &(*it); 00162 return 0; 00163 }
To be called when the host moved; updates proximity info.
Referenced by BasicMobility::updatePosition().
00220 { 00221 Enter_Method_Silent(); 00222 h->pos = pos; 00223 updateConnections(h); 00224 }
void ChannelControl::updateHostChannel | ( | HostRef | h, | |
const int | channel | |||
) | [virtual] |
Called when host switches channel.
Referenced by SnrEval::changeChannel(), AbstractRadio::changeChannel(), SnrEval::initialize(), and AbstractRadio::initialize().
00227 { 00228 Enter_Method_Silent(); 00229 checkChannel(channel); 00230 00231 h->channel = channel; 00232 }
const ChannelControl::TransmissionList & ChannelControl::getOngoingTransmissions | ( | const int | channel | ) |
Provides a list of transmissions currently on the air.
Referenced by SnrEval::changeChannel(), and AbstractRadio::changeChannel().
00235 { 00236 Enter_Method_Silent(); 00237 00238 checkChannel(channel); 00239 purgeOngoingTransmissions(); 00240 return transmissions[channel]; 00241 }
void ChannelControl::addOngoingTransmission | ( | HostRef | h, | |
AirFrame * | frame | |||
) | [virtual] |
Notifies the channel control with an ongoing transmission.
Referenced by ChannelAccess::sendToChannel().
00244 { 00245 Enter_Method_Silent(); 00246 00247 // we only keep track of ongoing transmissions so that we can support 00248 // NICs switching channels -- so there's no point doing it if there's only 00249 // one channel 00250 if (numChannels==1) 00251 { 00252 delete frame; 00253 return; 00254 } 00255 00256 // purge old transmissions from time to time 00257 if (simTime() - lastOngoingTransmissionsUpdate > TRANSMISSION_PURGE_INTERVAL) 00258 { 00259 purgeOngoingTransmissions(); 00260 lastOngoingTransmissionsUpdate = simTime(); 00261 } 00262 00263 // register ongoing transmission 00264 take(frame); 00265 frame->setTimestamp(); // store time of transmission start 00266 transmissions[frame->getChannelNumber()].push_back(frame); 00267 }
const ChannelControl::ModuleList & ChannelControl::getNeighbors | ( | HostRef | h | ) |
Get the list of modules in range of the given host.
Referenced by ChannelAccess::sendToChannel().
00166 { 00167 Enter_Method_Silent(); 00168 if (!h->isModuleListValid) 00169 { 00170 h->neighborModules.clear(); 00171 for (std::set<HostRef>::const_iterator it = h->neighbors.begin(); it != h->neighbors.end(); it++) 00172 h->neighborModules.push_back((*it)->host); 00173 h->isModuleListValid = true; 00174 } 00175 return h->neighborModules; 00176 }
virtual double ChannelControl::getCommunicationRange | ( | HostRef | h | ) | [inline, virtual] |
Reads init parameters and calculates a maximal interference distance.
Referenced by BasicMobility::updatePosition().
00142 { 00143 return maxInterferenceDistance; 00144 }
const Coord* ChannelControl::getPgs | ( | ) | [inline] |
Returns the playground size.
Referenced by BasicMobility::getRandomPosition(), and BasicMobility::initialize().
00147 {return &playgroundSize;}
const int ChannelControl::getNumChannels | ( | ) | [inline] |
Returns the number of radio channels (frequencies) simulated.
Referenced by SnrEval::changeChannel(), and AbstractRadio::changeChannel().
00150 {return numChannels;}
std::ostream& operator<< | ( | std::ostream & | os, | |
const HostEntry & | h | |||
) | [friend] |
std::ostream& operator<< | ( | std::ostream & | os, | |
const TransmissionList & | tl | |||
) | [friend] |
HostList ChannelControl::hosts [protected] |
Referenced by initialize(), lookupHost(), registerHost(), and updateConnections().
Referenced by addOngoingTransmission(), getOngoingTransmissions(), initialize(), purgeOngoingTransmissions(), and ~ChannelControl().
simtime_t ChannelControl::lastOngoingTransmissionsUpdate [protected] |
used to clear the transmission list from time to time
Referenced by addOngoingTransmission(), and initialize().
bool ChannelControl::coreDebug [protected] |
Coord ChannelControl::playgroundSize [protected] |
x and y size of the area the nodes are in (in meters)
Referenced by initialize(), and updateDisplayString().
double ChannelControl::maxInterferenceDistance [protected] |
the biggest interference distance in the network.
Referenced by initialize(), and updateConnections().
int ChannelControl::numChannels [protected] |
the number of controlled channels
Referenced by addOngoingTransmission(), checkChannel(), initialize(), and purgeOngoingTransmissions().