INET Framework for OMNeT++/OMNEST
inet::physicallayer::GridNeighborCache Class Reference

#include <GridNeighborCache.h>

Inheritance diagram for inet::physicallayer::GridNeighborCache:
inet::physicallayer::INeighborCache inet::IPrintableObject

Classes

class  GridNeighborCacheVisitor
 

Public Types

typedef std::vector< const IRadio * > Radios
 
- Public Types inherited from inet::IPrintableObject
enum  PrintLevel {
  PRINT_LEVEL_TRACE, PRINT_LEVEL_DEBUG, PRINT_LEVEL_DETAIL, PRINT_LEVEL_INFO,
  PRINT_LEVEL_COMPLETE = INT_MIN
}
 
enum  PrintFlag { PRINT_FLAG_FORMATTED = (1 << 0), PRINT_FLAG_MULTILINE = (1 << 1) }
 

Public Member Functions

 GridNeighborCache ()
 
virtual ~GridNeighborCache ()
 
virtual std::ostream & printToStream (std::ostream &stream, int level, int evFlags=0) const override
 Prints this object to the provided output stream. More...
 
virtual void addRadio (const IRadio *radio) override
 
virtual void removeRadio (const IRadio *radio) override
 
virtual void sendToNeighbors (IRadio *transmitter, const IWirelessSignal *signal, double range) const override
 Sends the provided frame (using the radio medium) to all neighbors within the given range. More...
 
- Public Member Functions inherited from inet::IPrintableObject
virtual ~IPrintableObject ()
 
virtual std::string printToString () const
 
virtual std::string printToString (int level, int evFlags=0) const
 
virtual std::string getInfoStringRepresentation (int evFlags=0) const
 
virtual std::string getDetailStringRepresentation (int evFlags=0) const
 
virtual std::string getDebugStringRepresentation (int evFlags=0) const
 
virtual std::string getTraceStringRepresentation (int evFlags=0) const
 
virtual std::string getCompleteStringRepresentation (int evFlags=0) const
 

Protected Member Functions

virtual int numInitStages () const override
 
virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *msg) override
 
void fillCubeVector ()
 

Protected Attributes

SpatialGridgrid
 
Radios radios
 
ModuleRefByPar< RadioMediumradioMedium
 
Coord constraintAreaMin
 
Coord constraintAreaMax
 
cMessage * refillCellsTimer
 
double refillPeriod
 
double maxSpeed
 
Coord cellSize
 

Member Typedef Documentation

◆ Radios

Constructor & Destructor Documentation

◆ GridNeighborCache()

inet::physicallayer::GridNeighborCache::GridNeighborCache ( )
18  :
19  grid(nullptr),
22  refillCellsTimer(nullptr),
24  maxSpeed(NaN),
26 {
27 }

◆ ~GridNeighborCache()

inet::physicallayer::GridNeighborCache::~GridNeighborCache ( )
virtual
142 {
143  cancelAndDelete(refillCellsTimer);
144  delete grid;
145 }

Member Function Documentation

◆ addRadio()

void inet::physicallayer::GridNeighborCache::addRadio ( const IRadio radio)
overridevirtual

Implements inet::physicallayer::INeighborCache.

86 {
87  radios.push_back(radio);
88  Coord radioPos = radio->getAntenna()->getMobility()->getCurrentPosition();
89  maxSpeed = radioMedium->getMediumLimitCache()->getMaxSpeed().get();
90  if (maxSpeed != 0 && !refillCellsTimer->isScheduled() && initialized())
91  scheduleAfter(refillPeriod, refillCellsTimer);
92  Coord newConstraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
93  Coord newConstraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
94  // If the constraintArea changed we must rebuild the grid
95  if (newConstraintAreaMin != constraintAreaMin || newConstraintAreaMax != constraintAreaMax) {
96  constraintAreaMin = newConstraintAreaMin;
97  constraintAreaMax = newConstraintAreaMax;
98  if (initialized())
100  }
101  else if (initialized())
102  grid->insertPoint(check_and_cast<const cObject *>(radio), radioPos);
103 }

◆ fillCubeVector()

void inet::physicallayer::GridNeighborCache::fillCubeVector ( )
protected
75 {
76  delete grid;
77  grid = new SpatialGrid(cellSize, constraintAreaMin, constraintAreaMax);
78  for (auto& elem : radios) {
79  const IRadio *radio = elem;
80  Coord radioPos = radio->getAntenna()->getMobility()->getCurrentPosition();
81  grid->insertPoint(check_and_cast<const cObject *>(radio), radioPos);
82  }
83 }

Referenced by addRadio(), handleMessage(), initialize(), and removeRadio().

◆ handleMessage()

void inet::physicallayer::GridNeighborCache::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
56 {
57  if (!msg->isSelfMessage())
58  throw cRuntimeError("This module only handles self messages");
59  EV_DETAIL << "Updating the grid cells" << endl;
61  scheduleAfter(refillPeriod, msg);
62 }

◆ initialize()

void inet::physicallayer::GridNeighborCache::initialize ( int  stage)
overrideprotectedvirtual
30 {
31  if (stage == INITSTAGE_LOCAL) {
32  radioMedium.reference(this, "radioMediumModule", true);
33  cellSize.x = par("cellSizeX");
34  cellSize.y = par("cellSizeY");
35  cellSize.z = par("cellSizeZ");
36  refillPeriod = par("refillPeriod");
37  refillCellsTimer = new cMessage("refillCellsTimer");
38  }
39  else if (stage == INITSTAGE_PHYSICAL_LAYER_NEIGHBOR_CACHE) {
40  constraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
41  constraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
42  maxSpeed = radioMedium->getMediumLimitCache()->getMaxSpeed().get();
43  const Coord constraintAreaSize = constraintAreaMax - constraintAreaMin;
44  if (std::isnan(cellSize.x))
45  cellSize.x = constraintAreaSize.x / par("cellCountX").doubleValue();
46  if (std::isnan(cellSize.y))
47  cellSize.y = constraintAreaSize.y / par("cellCountY").doubleValue();
48  if (std::isnan(cellSize.z))
49  cellSize.z = constraintAreaSize.z / par("cellCountZ").doubleValue();
51  scheduleAfter(refillPeriod, refillCellsTimer);
52  }
53 }

◆ numInitStages()

virtual int inet::physicallayer::GridNeighborCache::numInitStages ( ) const
inlineoverrideprotectedvirtual
47 { return NUM_INIT_STAGES; }

◆ printToStream()

std::ostream & inet::physicallayer::GridNeighborCache::printToStream ( std::ostream &  stream,
int  level,
int  evFlags = 0 
) const
overridevirtual

Prints this object to the provided output stream.

Reimplemented from inet::IPrintableObject.

65 {
66  stream << "GridNeighborCache";
67  if (level <= PRINT_LEVEL_TRACE)
68  stream << EV_FIELD(cellSize)
70  << EV_FIELD(maxSpeed);
71  return stream;
72 }

◆ removeRadio()

void inet::physicallayer::GridNeighborCache::removeRadio ( const IRadio radio)
overridevirtual

Implements inet::physicallayer::INeighborCache.

106 {
107  auto it = find(radios, radio);
108  if (it != radios.end()) {
109  radios.erase(it);
110  Coord newConstraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
111  Coord newConstraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
112  if (newConstraintAreaMin != constraintAreaMin || newConstraintAreaMax != constraintAreaMax) {
113  constraintAreaMin = newConstraintAreaMin;
114  constraintAreaMax = newConstraintAreaMax;
115  }
116  maxSpeed = radioMedium->getMediumLimitCache()->getMaxSpeed().get();
117  fillCubeVector();
118  if (maxSpeed == 0 && initialized())
119  cancelEvent(refillCellsTimer);
120  }
121  else {
122  throw cRuntimeError("You can't remove radio: %d because it is not in our radio vector", radio->getId());
123  }
124 }

◆ sendToNeighbors()

void inet::physicallayer::GridNeighborCache::sendToNeighbors ( IRadio transmitter,
const IWirelessSignal signal,
double  range 
) const
overridevirtual

Sends the provided frame (using the radio medium) to all neighbors within the given range.

Implements inet::physicallayer::INeighborCache.

127 {
128  double radius = range + (maxSpeed * refillPeriod);
129  Coord transmitterPos = transmitter->getAntenna()->getMobility()->getCurrentPosition();
130  GridNeighborCacheVisitor visitor(radioMedium, transmitter, signal);
131  grid->rangeQuery(transmitterPos, radius, &visitor);
132 }

Member Data Documentation

◆ cellSize

Coord inet::physicallayer::GridNeighborCache::cellSize
protected

◆ constraintAreaMax

Coord inet::physicallayer::GridNeighborCache::constraintAreaMax
protected

◆ constraintAreaMin

Coord inet::physicallayer::GridNeighborCache::constraintAreaMin
protected

◆ grid

SpatialGrid* inet::physicallayer::GridNeighborCache::grid
protected

◆ maxSpeed

double inet::physicallayer::GridNeighborCache::maxSpeed
protected

◆ radioMedium

ModuleRefByPar<RadioMedium> inet::physicallayer::GridNeighborCache::radioMedium
protected

◆ radios

Radios inet::physicallayer::GridNeighborCache::radios
protected

◆ refillCellsTimer

cMessage* inet::physicallayer::GridNeighborCache::refillCellsTimer
protected

◆ refillPeriod

double inet::physicallayer::GridNeighborCache::refillPeriod
protected

The documentation for this class was generated from the following files:
inet::physicallayer::GridNeighborCache::refillCellsTimer
cMessage * refillCellsTimer
Definition: GridNeighborCache.h:41
inet::physicallayer::GridNeighborCache::cellSize
Coord cellSize
Definition: GridNeighborCache.h:44
inet::physicallayer::GridNeighborCache::refillPeriod
double refillPeriod
Definition: GridNeighborCache.h:42
inet::physicallayer::GridNeighborCache::radios
Radios radios
Definition: GridNeighborCache.h:38
inet::physicallayer::GridNeighborCache::fillCubeVector
void fillCubeVector()
Definition: GridNeighborCache.cc:74
inet::physicallayer::GridNeighborCache::constraintAreaMax
Coord constraintAreaMax
Definition: GridNeighborCache.h:40
inet::find
std::vector< T >::iterator find(std::vector< T > &v, const Tk &a)
Definition: stlutils.h:44
inet::Coord::x
double x
Definition: Coord.h:36
inet::SpatialGrid::insertPoint
bool insertPoint(const cObject *point, const Coord &pos)
Definition: SpatialGrid.cc:60
EV_FIELD
#define EV_FIELD(...)
Definition: INETDefs.h:112
inet::physicallayer::GridNeighborCache::maxSpeed
double maxSpeed
Definition: GridNeighborCache.h:43
inet::Coord::z
double z
Definition: Coord.h:38
NaN
#define NaN
Definition: INETMath.h:91
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::IPrintableObject::PRINT_LEVEL_TRACE
@ PRINT_LEVEL_TRACE
Definition: IPrintableObject.h:22
NUM_INIT_STAGES
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
inet::physicallayer::GridNeighborCache::constraintAreaMin
Coord constraintAreaMin
Definition: GridNeighborCache.h:40
inet::SpatialGrid::rangeQuery
void rangeQuery(const Coord &pos, double range, const IVisitor *visitor) const
Definition: SpatialGrid.cc:81
inet::INITSTAGE_PHYSICAL_LAYER_NEIGHBOR_CACHE
INET_API InitStage INITSTAGE_PHYSICAL_LAYER_NEIGHBOR_CACHE
Initialization of physical layer neighbor cache.
inet::Coord::NIL
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:26
inet::physicallayer::GridNeighborCache::grid
SpatialGrid * grid
Definition: GridNeighborCache.h:37
inet::physicallayer::GridNeighborCache::radioMedium
ModuleRefByPar< RadioMedium > radioMedium
Definition: GridNeighborCache.h:39
inet::Coord::y
double y
Definition: Coord.h:37