Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

ChannelAccess Class Reference
[connectionManager - channel and connection related classesphyLayer - physical layer modulesbaseModules - base module classes of MiXiM]

Basic class for all physical layers, please don't touch!! More...

#include <ChannelAccess.h>

Inherits BatteryAccess.

Inherited by BasePhyLayer.

Collaboration diagram for ChannelAccess:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void initialize (int stage)
 Register with ConnectionManager and subscribe to hostPos.
virtual void receiveBBItem (int category, const BBItem *details, int scopeModuleId)
 Called by Blackboard to inform of changes.

Static Public Member Functions

static BaseConnectionManagergetConnectionManager (cModule *nic)
 Returns a pointer to the ConnectionManager responsible for the passed NIC module.

Protected Member Functions

simtime_t calculatePropagationDelay (const NicEntry *nic)
 Calculates the propagation delay to the passed receiving nic.
void sendToChannel (cPacket *msg)
 Sends a message to all nics connected to this one.

Protected Attributes

bool useSendDirect
 use sendDirect or not?
BaseConnectionManagercc
 Pointer to the PropagationModel module.
bool coreDebug
 debug this core module?
bool usePropagationDelay
 Defines if the physical layer should simulate propagation delay.
Move move
 Last move of this host.
int catMove
 category number given by bb for RSSI
bool isRegistered
 Is this module already registered with ConnectionManager?
BaseWorldUtilityworld
 Pointer to the World Utility, to obtain some global information.

Detailed Description

Basic class for all physical layers, please don't touch!!

This class is not supposed to work on its own, but it contains functions and lists that cooperate with ConnectionManager to handle the dynamically created gates. This means EVERY physical layer (the lowest layer in a host) has to be derived from this class!!!!

Please don't touch this class.

Author:
Marc Loebbers

Definition at line 52 of file ChannelAccess.h.


Member Function Documentation

BaseConnectionManager * ChannelAccess::getConnectionManager ( cModule *  nic  )  [static]

Returns a pointer to the ConnectionManager responsible for the passed NIC module.

Parameters:
nic a pointer to a NIC module
Returns:
a pointer to a connection manager module or NULL if an error occurred

Definition at line 35 of file ChannelAccess.cc.

Referenced by initialize().

{
  std::string cmName = nic->hasPar("connectionManagerName")
             ? nic->par("connectionManagerName").stringValue()
             : "";
  if (cmName != ""){
    cModule* ccModule = simulation.getModuleByPath(cmName.c_str());

    return dynamic_cast<BaseConnectionManager *>(ccModule);
  }
  else {
    return FindModule<BaseConnectionManager *>::findGlobalModule();
  }
}

void ChannelAccess::initialize ( int  stage  )  [virtual]

Register with ConnectionManager and subscribe to hostPos.

Upon initialization ChannelAccess registers the nic parent module to have all its connections handeled by ConnectionManager

Reimplemented from BaseModule.

Definition at line 50 of file ChannelAccess.cc.

References catMove, cc, coreDebug, BaseModule::findHost(), getConnectionManager(), isRegistered, move, Blackboard::subscribe(), usePropagationDelay, and BaseModule::utility.

{
  BatteryAccess::initialize(stage);

    if( stage == 0 ){
        hasPar("coreDebug") ? coreDebug = par("coreDebug").boolValue() : coreDebug = false;

        cModule* nic = getParentModule();
    cc = getConnectionManager(nic);

        if( cc == 0 ) error("Could not find connectionmanager module");
        // subscribe to position changes
        catMove = utility->subscribe(this, &move, findHost()->getId());
        isRegistered = false;
    }

    usePropagationDelay = par("usePropagationDelay");
}

void ChannelAccess::receiveBBItem ( int  category,
const BBItem details,
int  scopeModuleId 
) [virtual]

Called by Blackboard to inform of changes.

ChannelAccess is subscribed to position changes and informs the ConnectionManager

Reimplemented from BaseModule.

Definition at line 131 of file ChannelAccess.cc.

References catMove, cc, Move::getStartPos(), Move::info(), isRegistered, move, BaseConnectionManager::registerNic(), BaseConnectionManager::updateNicPos(), and useSendDirect.

{
  BatteryAccess::receiveBBItem(category, details, scopeModuleId);

    if(category == catMove)
    {
        Move m(*static_cast<const Move*>(details));

        if(isRegistered) {
            cc->updateNicPos(getParentModule()->getId(), &m.getStartPos());
        }
        else {
            // register the nic with ConnectionManager
            // returns true, if sendDirect is used
            useSendDirect = cc->registerNic(getParentModule(), this, &m.getStartPos());
            isRegistered = true;
        }
        move = m;
        coreEV<<"new HostMove: "<<move.info()<<endl;
    }
}

void ChannelAccess::sendToChannel ( cPacket *  msg  )  [protected]

Sends a message to all nics connected to this one.

This function has to be called whenever a packet is supposed to be sent to the channel. Don't try to figure out what gates you have and which ones are connected, this function does this for you!

depending on which ConnectionManager module is used, the messages are send via sendDirect() or to the respective gates.

Definition at line 71 of file ChannelAccess.cc.

References calculatePropagationDelay(), cc, BaseConnectionManager::getGateList(), and useSendDirect.

Referenced by BasePhyLayer::sendMessageDown().

{
    const NicEntry::GateList& gateList = cc->getGateList( getParentModule()->getId());
    NicEntry::GateList::const_iterator i = gateList.begin();

    if(useSendDirect){
        // use Andras stuff
        if( i != gateList.end() ){
          simtime_t delay = 0;
            for(; i != --gateList.end(); ++i){
              //calculate delay (Propagation) to this receiving nic
              delay = calculatePropagationDelay(i->first);

                int radioStart = i->second->getId();
                int radioEnd = radioStart + i->second->size();
                for (int g = radioStart; g != radioEnd; ++g)
                    sendDirect(static_cast<cPacket*>(msg->dup()),
                               delay, msg->getDuration(), i->second->getOwnerModule(), g);
            }
            //calculate delay (Propagation) to this receiving nic
      delay = calculatePropagationDelay(i->first);

            int radioStart = i->second->getId();
            int radioEnd = radioStart + i->second->size();
            for (int g = radioStart; g != --radioEnd; ++g)
                sendDirect(static_cast<cPacket*>(msg->dup()),
                           delay, msg->getDuration(), i->second->getOwnerModule(), g);

            sendDirect(msg, delay, msg->getDuration(), i->second->getOwnerModule(), radioEnd);
        }
        else{
            coreEV << "Nic is not connected to any gates!" << endl;
            delete msg;
        }
    }
    else{
        // use our stuff
        coreEV <<"sendToChannel: sending to gates\n";
        if( i != gateList.end() ){
          simtime_t delay = 0;
            for(; i != --gateList.end(); ++i){
              //calculate delay (Propagation) to this receiving nic
        delay = calculatePropagationDelay(i->first);

                sendDelayed( static_cast<cPacket*>(msg->dup()),
                             delay, i->second );
            }
            //calculate delay (Propagation) to this receiving nic
      delay = calculatePropagationDelay(i->first);

            sendDelayed( msg, delay, i->second );
        }
        else{
            coreEV << "Nic is not connected to any gates!" << endl;
            delete msg;
        }
    }
}


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