Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions

BaseConnectionManager Class Reference
[connectionManager - channel and connection related classes]

Module to control the channel and handle all connection related stuff. More...

#include <BaseConnectionManager.h>

Inherited by ConnectionManager.

Collaboration diagram for BaseConnectionManager:
Collaboration graph
[legend]

List of all members.

Classes

class  CoordSet
 Represents an minimalistic (hash)set of GridCoords. More...
class  GridCoord
 Represents a position inside a grid. More...

Public Member Functions

virtual int numInitStages () const
 Needs two initialization stages.
virtual void initialize (int stage)
 Reads init parameters and calculates a maximal interference distance.
bool registerNic (cModule *nic, ChannelAccess *chAccess, const Coord *nicPos)
 Registers a nic to have its connections managed by ConnectionManager.
bool unregisterNic (cModule *nic)
 Unregisters a NIC such that its connections aren't managed by the CM anymore.
void updateNicPos (int nicID, const Coord *newPos)
 Updates the position information of a registered nic.
const NicEntry::GateListgetGateList (int nicID)
 Returns the ingates of all nics in range.
const cGate * getOutGateTo (const NicEntry *nic, const NicEntry *targetNic)
 Returns the ingate of the with id==targetID, or 0 if not in range.

Protected Types

typedef std::map< int, NicEntry * > NicEntries
 Type for map from nic-module id to nic-module pointer.
typedef std::vector< NicEntriesRowVector
 Type for 1-dimensional array of NicEntries.
typedef std::vector< RowVectorNicMatrix
 Type for 2-dimensional array of NicEntries.
typedef std::vector< NicMatrixNicCube
 Type for 3-dimensional array of NicEntries.

Protected Member Functions

virtual double calcInterfDist ()=0
 Calculate interference distance.
virtual void registerNicExt (int nicID)
 Called by "registerNic()" after the nic has been registered. That means that the NicEntry for the nic has already been created and added to nics map.
virtual void updateConnections (int nicID, const Coord *oldPos, const Coord *newPos)
 Updates the connections of the nic with "nicID".

Protected Attributes

NicEntries nics
 Map from nic-module ids to nic-module pointers.
bool coreDebug
 Set debugging for the basic module.
bool sendDirect
 Does the ConnectionManager use sendDirect or not?
const CoordplaygroundSize
 Stores the size of the playground.
double maxInterferenceDistance
 the biggest interference distance in the network.
double maxDistSquared
 Square of maxInterferenceDistance cache a value that is often used.
bool useTorus
 Stores the useTorus flag of the WorldUtility.
bool drawMIR
 Stores if maximum interference distance should be displayed in TkEnv.
NicCube nicGrid
 Register of all nics.
Coord findDistance
 Distance that helps to find a node under a certain position.
GridCoord gridDim
 The size of the grid.

Private Member Functions

void updateNicConnections (NicEntries &nmap, NicEntry *nic)
 Manages the connections of a registered nic.
void checkGrid (GridCoord &oldCell, GridCoord &newCell, int id)
 Check connections of a nic in the grid.
GridCoord getCellForCoordinate (const Coord &c)
 Calculates the corresponding cell of a coordinate.
NicEntriesgetCellEntries (GridCoord &cell)
 Returns the NicEntries of the cell with specified coordinate.
int wrapIfTorus (int value, int max)
void fillUnionWithNeighbors (CoordSet &gridUnion, GridCoord cell)
 Adds every direct Neighbor of a GridCoord to a union of coords.

Detailed Description

Module to control the channel and handle all connection related stuff.

The central module that coordinates the connections between all nodes, and handles dynamic gate creation. BaseConnectionManager therefore periodically communicates with the ChannelAccess modules

You may not instantiate BaseConnectionManager! Use ConnectionManager instead.

Author:
Steffen Sroka, Daniel Willkomm, Karl Wessel
Christoph Sommer ("unregisterNic()"-method)
See also:
ChannelAccess

Definition at line 24 of file BaseConnectionManager.h.


Member Function Documentation

virtual double BaseConnectionManager::calcInterfDist (  )  [protected, pure virtual]

Calculate interference distance.

Called by BaseConnectionManager already during initialization stage 0. Implementations therefore have to make sure that everything necessary for calculation is either already initialized or has to be initialized in this method!

This method has to be overridden by any derived class.

Implemented in ConnectionManager, and UnitDisk.

Referenced by initialize().

bool BaseConnectionManager::registerNic ( cModule *  nic,
ChannelAccess chAccess,
const Coord nicPos 
)

Registers a nic to have its connections managed by ConnectionManager.

If you want to do your own stuff at the registration of a nic see "registerNicExt()".

Definition at line 301 of file BaseConnectionManager.cc.

References NicEntry::chAccess, coreDebug, drawMIR, NicEntry::hostId, maxInterferenceDistance, NicEntry::nicId, NicEntry::nicPtr, nics, NicEntry::pos, registerNicExt(), sendDirect, and updateConnections().

Referenced by ChannelAccess::receiveBBItem().

{
  assert(nic != 0);

  int nicID = nic->getId();
  ccEV << " registering nic #" << nicID << endl;

  // create new NicEntry
  NicEntry *nicEntry;

  if(sendDirect)
    nicEntry = new NicEntryDirect(coreDebug);
  else
    nicEntry = new NicEntryDebug(coreDebug);

  // fill nicEntry
  nicEntry->nicPtr = nic;
  nicEntry->nicId = nicID;
  nicEntry->hostId = nic->getParentModule()->getId();
  nicEntry->pos = nicPos;
  nicEntry->chAccess = chAccess;

  // add to map
  nics[nicID] = nicEntry;

  registerNicExt(nicID);

  updateConnections(nicID, nicPos, nicPos);

  if(drawMIR) {
    nic->getParentModule()->getDisplayString().setTagArg("r", 0, maxInterferenceDistance);
  }

  return sendDirect;
}

void BaseConnectionManager::registerNicExt ( int  nicID  )  [protected, virtual]

Called by "registerNic()" after the nic has been registered. That means that the NicEntry for the nic has already been created and added to nics map.

You better know what you are doing if you want to override this method. Most time you won't need to.

See ConnectionManager::registerNicExt() for an example.

Parameters:
nicID - the id of the NicEntry

Definition at line 154 of file BaseConnectionManager.cc.

References getCellEntries(), getCellForCoordinate(), BaseConnectionManager::GridCoord::info(), nics, and NicEntry::pos.

Referenced by registerNic().

{
  NicEntry* nicEntry = nics[nicID];

  GridCoord cell = getCellForCoordinate(nicEntry->pos);

  ccEV <<" registering (ext) nic at loc " << cell.info() << std::endl;

  // add to matrix
  NicEntries& cellEntries = getCellEntries(cell);
    cellEntries[nicID] = nicEntry;
}

bool BaseConnectionManager::unregisterNic ( cModule *  nic  ) 

Unregisters a NIC such that its connections aren't managed by the CM anymore.

NOTE: This method asserts that the passed NIC module was previously registered with this ConnectionManager!

This method should be used for dynamic networks were hosts can actually disappear.

Parameters:
nic the NIC module to be unregistered
Returns:
returns true if the NIC was unregistered successfully

Definition at line 339 of file BaseConnectionManager.cc.

References BaseConnectionManager::CoordSet::add(), NicEntry::disconnectFrom(), fillUnionWithNeighbors(), getCellEntries(), getCellForCoordinate(), gridDim, BaseConnectionManager::GridCoord::info(), NicEntry::isConnected(), BaseConnectionManager::CoordSet::next(), and nics.

{
  assert(nicModule != 0);

  // find nicEntry
  int nicID = nicModule->getId();
  ccEV << " unregistering nic #" << nicID << endl;

  //we assume that the module was previously registered with this CM
  //TODO: maybe change this to an omnet-error instead of an assertion
  assert(nics.find(nicID) != nics.end());
  NicEntry* nicEntry = nics[nicID];

  // get all affected grid squares
  CoordSet gridUnion(74);
  GridCoord cell = getCellForCoordinate(nicEntry->pos);
  if((gridDim.x == 1) && (gridDim.y == 1) && (gridDim.z == 1)) {
    gridUnion.add(cell);
  } else {
    fillUnionWithNeighbors(gridUnion, cell);
  }

  // disconnect from all NICs in these grid squares
  GridCoord* c = gridUnion.next();
  while(c != 0) {
    ccEV << "Update cons in [" << c->info() << "]" << endl;
    NicEntries& nmap = getCellEntries(*c);
    for(NicEntries::iterator i = nmap.begin(); i != nmap.end(); ++i) {
      NicEntry* other = i->second;
      if (other == nicEntry) continue;
      if (!other->isConnected(nicEntry)) continue;
      other->disconnectFrom(nicEntry);
      nicEntry->disconnectFrom(other);
    }
    c = gridUnion.next();
  }

  // erase from grid
  NicEntries& cellEntries = getCellEntries(cell);
  cellEntries.erase(nicID);

  // erase from list of known nics
  nics.erase(nicID);

  return true;
}

void BaseConnectionManager::updateConnections ( int  nicID,
const Coord oldPos,
const Coord newPos 
) [protected, virtual]

Updates the connections of the nic with "nicID".

This method is called by "updateNicPos()" after the new Position is stored in the corresponding nic.

Most time you won't need to override this method.

Parameters:
nicID the id of the NicEntry
oldPos the old position of the nic
newPos the new position of the nic

Definition at line 138 of file BaseConnectionManager.cc.

References checkGrid(), and getCellForCoordinate().

Referenced by registerNic(), and updateNicPos().

{
  GridCoord oldCell = getCellForCoordinate(*oldPos);
    GridCoord newCell = getCellForCoordinate(*newPos);

  checkGrid(oldCell, newCell, nicID );
}

int BaseConnectionManager::wrapIfTorus ( int  value,
int  max 
) [private]

If the value is outside of its bounds (zero and max) this function returns -1 if useTorus is false and the wrapped value if useTorus is true. Otherwise its just returns the value unchanged.

Definition at line 209 of file BaseConnectionManager.cc.

References useTorus.

Referenced by fillUnionWithNeighbors().

                                                         {
  if(value < 0) {
    if(useTorus) {
      return max + value;
    } else {
      return -1;
    }
  } else if(value >= max) {
    if(useTorus) {
      return value - max;
    } else {
      return -1;
    }
  } else {
    return value;
  }
}


Member Data Documentation

Distance that helps to find a node under a certain position.

Can be larger then

See also:
maxInterferenceDistance to allow nodes to be placed into the same square if the playground is too small for the grid speedup to work.

Definition at line 259 of file BaseConnectionManager.h.

Referenced by initialize().

Register of all nics.

This matrix keeps all nics according to their position. It allows to restrict the position update to a subset of all nics.

Definition at line 249 of file BaseConnectionManager.h.

Referenced by initialize().


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