INET Framework for OMNeT++/OMNEST
ChannelControl Class Reference

Monitors which hosts are "in range". Supports multiple channels. More...

#include <ChannelControl.h>

List of all members.

Classes

struct  HostEntry

Public Types

typedef HostEntryHostRef
typedef std::vector< HostRefHostRefVector
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 TransmissionListgetOngoingTransmissions (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 CoordgetHostPosition (HostRef h)
 Returns the host's position.
const HostRefVectorgetNeighbors (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 CoordgetPgs ()
 Returns the playground size.
const int getNumChannels ()
 Returns the number of radio channels (frequencies) simulated.

Static Public Member Functions

static ChannelControlget ()
 Finds the channelControl module in the network.

Protected Types

typedef std::list< HostEntryHostList
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 &)

Detailed Description

Monitors which hosts are "in range". Supports multiple channels.

See also:
ChannelAccess

Definition at line 38 of file ChannelControl.h.


Member Typedef Documentation

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)

Definition at line 73 of file ChannelControl.h.

typedef std::list<HostEntry> ChannelControl::HostList [protected]

Definition at line 41 of file ChannelControl.h.

Definition at line 45 of file ChannelControl.h.

typedef std::vector<HostRef> ChannelControl::HostRefVector

Definition at line 46 of file ChannelControl.h.

Definition at line 47 of file ChannelControl.h.


Constructor & Destructor Documentation

Definition at line 42 of file ChannelControl.cc.

{
}

Definition at line 46 of file ChannelControl.cc.

{
    for (unsigned int i = 0; i < transmissions.size(); i++)
        for (TransmissionList::iterator it = transmissions[i].begin(); it != transmissions[i].end(); it++)
            delete *it;
}

Member Function Documentation

void ChannelControl::addOngoingTransmission ( HostRef  h,
AirFrame frame 
) [virtual]

Notifies the channel control with an ongoing transmission.

Definition at line 245 of file ChannelControl.cc.

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

Definition at line 113 of file ChannelControl.cc.

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.

Definition at line 215 of file ChannelControl.cc.

Referenced by getOngoingTransmissions(), and updateHostChannel().

{
    if (channel >= numChannels || channel < 0)
        error("Invalid channel, must be between 0 and %d", numChannels);
}

Finds the channelControl module in the network.

Definition at line 53 of file ChannelControl.cc.

Referenced by ChannelAccess::initialize(), BasicMobility::initialize(), Ieee80211MgmtSTA::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.

Definition at line 156 of file ChannelControl.h.

Referenced by BasicMobility::updatePosition().

cModule* ChannelControl::getHost ( HostRef  h) const [inline]

Returns the module that was registered as HostRef h.

Definition at line 123 of file ChannelControl.h.

{return h->host;}
int ChannelControl::getHostChannel ( HostRef  h) const [inline]

Returns the channel the given host listens on.

Definition at line 129 of file ChannelControl.h.

{return h->channel;}

Returns the host's position.

Definition at line 147 of file ChannelControl.h.

{return h->pos;}

Get the list of modules in range of the given host.

Definition at line 167 of file ChannelControl.cc.

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.

Definition at line 164 of file ChannelControl.h.

Referenced by SnrEval::changeChannel(), and AbstractRadio::changeChannel().

{return numChannels;}

Provides a list of transmissions currently on the air.

Definition at line 236 of file ChannelControl.cc.

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.

Definition at line 161 of file ChannelControl.h.

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.

Definition at line 126 of file ChannelControl.h.

{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

calcInterfDist

Definition at line 69 of file ChannelControl.cc.

{
    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.

Definition at line 158 of file ChannelControl.cc.

Referenced by ChannelAccess::initialize(), and registerHost().

{
    Enter_Method_Silent();
    for (HostList::iterator it = hosts.begin(); it != hosts.end(); it++)
        if (it->host == host)
            return &(*it);
    return 0;
}
void ChannelControl::purgeOngoingTransmissions ( ) [protected, virtual]

Throws away expired transmissions.

Definition at line 271 of file ChannelControl.cc.

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.

Definition at line 139 of file ChannelControl.cc.

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.

Definition at line 290 of file ChannelControl.cc.

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]

Definition at line 180 of file ChannelControl.cc.

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"

Definition at line 96 of file ChannelControl.cc.

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.

Definition at line 228 of file ChannelControl.cc.

Referenced by SnrEval::changeChannel(), AbstractRadio::changeChannel(), AbstractRadio::initialize(), and SnrEval::initialize().

{
    Enter_Method_Silent();
    checkChannel(channel);

    h->channel = channel;
}
void ChannelControl::updateHostPosition ( HostRef  h,
const Coord pos 
) [virtual]

To be called when the host moved; updates proximity info.

Definition at line 221 of file ChannelControl.cc.

Referenced by BasicMobility::updatePosition().

{
    Enter_Method_Silent();
    h->pos = pos;
    updateConnections(h);
}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const HostEntry h 
) [friend]

Definition at line 28 of file ChannelControl.cc.

{
    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]

Definition at line 35 of file ChannelControl.cc.

{
    for (ChannelControl::TransmissionList::const_iterator it = tl.begin(); it != tl.end(); ++it)
        os << endl << *it;
    return os;
}

Member Data Documentation

bool ChannelControl::coreDebug [protected]

Set debugging for the basic module.

Definition at line 83 of file ChannelControl.h.

Referenced by initialize().

Definition at line 67 of file ChannelControl.h.

Referenced by initialize(), lookupHost(), registerHost(), and updateConnections().

used to clear the transmission list from time to time

Definition at line 77 of file ChannelControl.h.

Referenced by addOngoingTransmission(), and initialize().

the biggest interference distance in the network.

Definition at line 89 of file ChannelControl.h.

Referenced by initialize(), and updateConnections().

int ChannelControl::numChannels [protected]

the number of controlled channels

Definition at line 92 of file ChannelControl.h.

Referenced by addOngoingTransmission(), checkChannel(), initialize(), and purgeOngoingTransmissions().

x and y size of the area the nodes are in (in meters)

Definition at line 86 of file ChannelControl.h.

Referenced by initialize(), and updateDisplayString().


The documentation for this class was generated from the following files: