|
INET Framework for OMNeT++/OMNEST
|
Monitors which hosts are "in range". Supports multiple channels. More...
#include <ChannelControl.h>
Classes | |
| struct | HostEntry |
Public Types | |
| typedef HostEntry * | HostRef |
| typedef std::vector< HostRef > | HostRefVector |
| typedef std::list< AirFrame * > | TransmissionList |
Public Member Functions | |
| ChannelControl () | |
| virtual | ~ChannelControl () |
| virtual HostRef | registerHost (cModule *host, const Coord &initialPos, cGate *radioInGate=NULL) |
| Registers the given host. If radioInGate==NULL, the "radioIn" gate is assumed. | |
| cModule * | getHost (HostRef h) const |
| Returns the module that was registered as HostRef h. | |
| cGate * | getRadioGate (HostRef h) const |
| Returns the input gate of the host for receiving AirFrames. | |
| int | getHostChannel (HostRef h) const |
| Returns the channel the given host listens on. | |
| 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 HostRefVector & | getNeighbors (HostRef h) |
| Get the list of modules in range of the given host. | |
| virtual void | sendToChannel (cSimpleModule *srcRadioMod, HostRef srcHost, AirFrame *airFrame) |
| Called from ChannelAccess, to transmit a frame to the hosts in range, on the frame's channel. | |
| 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 &) |
Monitors which hosts are "in range". Supports multiple channels.
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)
typedef std::list<HostEntry> ChannelControl::HostList [protected] |
| typedef HostEntry* ChannelControl::HostRef |
| typedef std::vector<HostRef> ChannelControl::HostRefVector |
| typedef std::list<AirFrame*> ChannelControl::TransmissionList |
| ChannelControl::ChannelControl | ( | ) |
{
}
| ChannelControl::~ChannelControl | ( | ) | [virtual] |
{
for (unsigned int i = 0; i < transmissions.size(); i++)
for (TransmissionList::iterator it = transmissions[i].begin(); it != transmissions[i].end(); it++)
delete *it;
}
| void ChannelControl::addOngoingTransmission | ( | HostRef | h, |
| AirFrame * | frame | ||
| ) | [virtual] |
Notifies the channel control with an ongoing transmission.
Referenced by sendToChannel().
{
Enter_Method_Silent();
// we only keep track of ongoing transmissions so that we can support
// NICs switching channels -- so there's no point doing it if there's only
// one channel
if (numChannels==1)
{
delete frame;
return;
}
// purge old transmissions from time to time
if (simTime() - lastOngoingTransmissionsUpdate > TRANSMISSION_PURGE_INTERVAL)
{
purgeOngoingTransmissions();
lastOngoingTransmissionsUpdate = simTime();
}
// register ongoing transmission
take(frame);
frame->setTimestamp(); // store time of transmission start
transmissions[frame->getChannelNumber()].push_back(frame);
}
| 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().
{
double SPEED_OF_LIGHT = 300000000.0;
double interfDistance;
//the carrier frequency used
double carrierFrequency = par("carrierFrequency");
//maximum transmission power possible
double pMax = par("pMax");
//signal attenuation threshold
double sat = par("sat");
//path loss coefficient
double alpha = par("alpha");
double waveLength = (SPEED_OF_LIGHT / carrierFrequency);
//minimum power level to be able to physically receive a signal
double minReceivePower = pow(10.0, sat / 10.0);
interfDistance = pow(waveLength * waveLength * pMax /
(16.0 * M_PI * M_PI * minReceivePower), 1.0 / alpha);
coreEV << "max interference distance:" << interfDistance << endl;
return interfDistance;
}
| void ChannelControl::checkChannel | ( | const int | channel | ) | [protected, virtual] |
Validate the channel identifier.
Referenced by getOngoingTransmissions(), and updateHostChannel().
{
if (channel >= numChannels || channel < 0)
error("Invalid channel, must be between 0 and %d", numChannels);
}
| ChannelControl * ChannelControl::get | ( | ) | [static] |
Finds the channelControl module in the network.
Referenced by Ieee80211MgmtSTA::initialize(), ChannelAccess::initialize(), BasicMobility::initialize(), and PathLossReceptionModel::initializeFrom().
{
ChannelControl *cc = dynamic_cast<ChannelControl *>(simulation.getModuleByPath("channelcontrol"));
if (!cc)
cc = dynamic_cast<ChannelControl *>(simulation.getModuleByPath("channelControl"));
if (!cc)
throw cRuntimeError("Could not find ChannelControl module");
return cc;
}
| virtual double ChannelControl::getCommunicationRange | ( | HostRef | h | ) | [inline, virtual] |
Reads init parameters and calculates a maximal interference distance.
Referenced by BasicMobility::updatePosition().
{
return maxInterferenceDistance;
}
| cModule* ChannelControl::getHost | ( | HostRef | h | ) | const [inline] |
Returns the module that was registered as HostRef h.
{return h->host;}
| int ChannelControl::getHostChannel | ( | HostRef | h | ) | const [inline] |
Returns the channel the given host listens on.
{return h->channel;}
Returns the host's position.
{return h->pos;}
| const ChannelControl::HostRefVector & ChannelControl::getNeighbors | ( | HostRef | h | ) |
Get the list of modules in range of the given host.
Referenced by sendToChannel().
{
Enter_Method_Silent();
if (!h->isNeighborListValid)
{
h->neighborList.clear();
for (std::set<HostRef>::const_iterator it = h->neighbors.begin(); it != h->neighbors.end(); it++)
h->neighborList.push_back(*it);
h->isNeighborListValid = true;
}
return h->neighborList;
}
| const int ChannelControl::getNumChannels | ( | ) | [inline] |
Returns the number of radio channels (frequencies) simulated.
Referenced by SnrEval::changeChannel(), and AbstractRadio::changeChannel().
{return numChannels;}
| const ChannelControl::TransmissionList & ChannelControl::getOngoingTransmissions | ( | const int | channel | ) |
Provides a list of transmissions currently on the air.
Referenced by SnrEval::changeChannel(), and AbstractRadio::changeChannel().
{
Enter_Method_Silent();
checkChannel(channel);
purgeOngoingTransmissions();
return transmissions[channel];
}
| const Coord* ChannelControl::getPgs | ( | ) | [inline] |
Returns the playground size.
Referenced by BasicMobility::getRandomPosition(), and BasicMobility::initialize().
{return &playgroundSize;}
| cGate* ChannelControl::getRadioGate | ( | HostRef | h | ) | const [inline] |
Returns the input gate of the host for receiving AirFrames.
{return h->radioInGate;}
| void ChannelControl::initialize | ( | ) | [protected, virtual] |
Reads init parameters and calculates a maximal interference distance.
Sets up the playgroundSize and calculates the maxInterferenceDistance
{
coreDebug = hasPar("coreDebug") ? (bool) par("coreDebug") : false;
coreEV << "initializing ChannelControl\n";
playgroundSize.x = par("playgroundSizeX");
playgroundSize.y = par("playgroundSizeY");
numChannels = par("numChannels");
transmissions.resize(numChannels);
lastOngoingTransmissionsUpdate = 0;
maxInterferenceDistance = calcInterfDist();
WATCH(maxInterferenceDistance);
WATCH_LIST(hosts);
WATCH_VECTOR(transmissions);
updateDisplayString(getParentModule());
}
| ChannelControl::HostRef ChannelControl::lookupHost | ( | cModule * | host | ) | [virtual] |
Returns the "handle" of a previously registered host.
Referenced by ChannelAccess::initialize(), and registerHost().
| void ChannelControl::purgeOngoingTransmissions | ( | ) | [protected, virtual] |
Throws away expired transmissions.
Referenced by addOngoingTransmission(), and getOngoingTransmissions().
{
for (int i = 0; i < numChannels; i++)
{
for (TransmissionList::iterator it = transmissions[i].begin(); it != transmissions[i].end();)
{
TransmissionList::iterator curr = it;
AirFrame *frame = *it;
it++;
if (frame->getTimestamp() + frame->getDuration() + TRANSMISSION_PURGE_INTERVAL < simTime())
{
delete frame;
transmissions[i].erase(curr);
}
}
}
}
| ChannelControl::HostRef ChannelControl::registerHost | ( | cModule * | host, |
| const Coord & | initialPos, | ||
| cGate * | radioInGate = NULL |
||
| ) | [virtual] |
Registers the given host. If radioInGate==NULL, the "radioIn" gate is assumed.
Referenced by BasicMobility::initialize().
{
Enter_Method_Silent();
if (lookupHost(host) != NULL)
error("ChannelControl::registerHost(): host (%s)%s already registered",
host->getClassName(), host->getFullPath().c_str());
if (!radioInGate)
radioInGate = host->gate("radioIn"); // throws error if gate does not exist
HostEntry he;
he.host = host;
he.radioInGate = radioInGate;
he.pos = initialPos;
he.isNeighborListValid = false;
he.channel = 0; // for now
hosts.push_back(he);
return &hosts.back(); // last element
}
| void ChannelControl::sendToChannel | ( | cSimpleModule * | srcRadioMod, |
| HostRef | srcHost, | ||
| AirFrame * | airFrame | ||
| ) | [virtual] |
Called from ChannelAccess, to transmit a frame to the hosts in range, on the frame's channel.
Referenced by ChannelAccess::sendToChannel().
{
// NOTE: no Enter_Method()! We pretend this method is part of ChannelAccess
// loop through all hosts in range
const HostRefVector& neighbors = getNeighbors(srcHost);
int n = neighbors.size();
int channel = airFrame->getChannelNumber();
for (int i=0; i<n; i++)
{
HostRef h = neighbors[i];
if (h->channel == channel)
{
coreEV << "sending message to host listening on the same channel\n";
// account for propagation delay, based on distance in meters
// Over 300m, dt=1us=10 bit times @ 10Mbps
simtime_t delay = srcHost->pos.distance(h->pos) / LIGHT_SPEED;
srcRadioMod->sendDirect(airFrame->dup(), delay, airFrame->getDuration(), h->radioInGate);
}
else
coreEV << "skipping host listening on a different channel\n";
}
// register transmission
addOngoingTransmission(srcHost, airFrame);
}
| void ChannelControl::updateConnections | ( | HostRef | h | ) | [protected, virtual] |
Referenced by updateHostPosition().
{
Coord& hpos = h->pos;
double maxDistSquared = maxInterferenceDistance * maxInterferenceDistance;
for (HostList::iterator it = hosts.begin(); it != hosts.end(); ++it)
{
HostEntry *hi = &(*it);
if (hi == h)
continue;
// get the distance between the two hosts.
// (omitting the square root (calling sqrdist() instead of distance()) saves about 5% CPU)
bool inRange = hpos.sqrdist(hi->pos) < maxDistSquared;
if (inRange)
{
// nodes within communication range: connect
if (h->neighbors.insert(hi).second == true)
{
hi->neighbors.insert(h);
h->isNeighborListValid = hi->isNeighborListValid = false;
}
}
else
{
// out of range: disconnect
if (h->neighbors.erase(hi))
{
hi->neighbors.erase(h);
h->isNeighborListValid = hi->isNeighborListValid = false;
}
}
}
}
| 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().
{
cDisplayString& d = playgroundMod->getDisplayString();
d.setTagArg("bgp", 0, 0L);
d.setTagArg("bgp", 1, 0L);
d.setTagArg("bgb", 0, (long) playgroundSize.x);
d.setTagArg("bgb", 1, (long) playgroundSize.y);
}
| 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().
{
Enter_Method_Silent();
checkChannel(channel);
h->channel = channel;
}
To be called when the host moved; updates proximity info.
Referenced by BasicMobility::updatePosition().
{
Enter_Method_Silent();
h->pos = pos;
updateConnections(h);
}
| std::ostream& operator<< | ( | std::ostream & | os, |
| const HostEntry & | h | ||
| ) | [friend] |
{
os << h.host->getFullPath() << " (x=" << h.pos.x << ",y=" << h.pos.y << "), "
<< h.neighbors.size() << " neighbor(s)";
return os;
}
| std::ostream& operator<< | ( | std::ostream & | os, |
| const TransmissionList & | tl | ||
| ) | [friend] |
{
for (ChannelControl::TransmissionList::const_iterator it = tl.begin(); it != tl.end(); ++it)
os << endl << *it;
return os;
}
bool ChannelControl::coreDebug [protected] |
Set debugging for the basic module.
Referenced by initialize().
HostList ChannelControl::hosts [protected] |
Referenced by initialize(), lookupHost(), registerHost(), and updateConnections().
simtime_t ChannelControl::lastOngoingTransmissionsUpdate [protected] |
used to clear the transmission list from time to time
Referenced by addOngoingTransmission(), and initialize().
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().
Coord ChannelControl::playgroundSize [protected] |
x and y size of the area the nodes are in (in meters)
Referenced by initialize(), and updateDisplayString().
Referenced by addOngoingTransmission(), getOngoingTransmissions(), initialize(), purgeOngoingTransmissions(), and ~ChannelControl().