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

#include <GridNeighborCache.h>

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

Classes

class  GridNeighborCacheVisitor
 

Public Types

typedef std::vector< const IRadio * > Radios
 
- Public Types inherited from inet::physicallayer::IPrintableObject
enum  PrintLevel {
  PRINT_LEVEL_TRACE, PRINT_LEVEL_DEBUG, PRINT_LEVEL_DETAIL, PRINT_LEVEL_INFO,
  PRINT_LEVEL_COMPLETE = INT_MIN
}
 

Public Member Functions

 GridNeighborCache ()
 
virtual ~GridNeighborCache ()
 
virtual std::ostream & printToStream (std::ostream &stream, int level) 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 IRadioFrame *frame, 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::physicallayer::IPrintableObject
virtual ~IPrintableObject ()
 
virtual std::string getInfoStringRepresentation () const
 
virtual std::string getDetailStringRepresentation () const
 
virtual std::string getDebugStringRepresentation () const
 
virtual std::string getTraceStringRepresentation () const
 
virtual std::string getCompleteStringRepresentation () 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
 
RadioMediumradioMedium
 
Coord constraintAreaMin
 
Coord constraintAreaMax
 
cMessage * refillCellsTimer
 
double refillPeriod
 
double maxSpeed
 
Coord cellSize
 

Member Typedef Documentation

Constructor & Destructor Documentation

inet::physicallayer::GridNeighborCache::GridNeighborCache ( )
27  :
28  grid(nullptr),
29  radioMedium(nullptr),
32  refillCellsTimer(nullptr),
34  maxSpeed(NaN),
36 {
37 }
cMessage * refillCellsTimer
Definition: GridNeighborCache.h:51
static const Coord NIL
Constant with all values set to 0.
Definition: Coord.h:40
SpatialGrid * grid
Definition: GridNeighborCache.h:47
Coord constraintAreaMin
Definition: GridNeighborCache.h:50
#define NaN
Definition: INETMath.h:103
RadioMedium * radioMedium
Definition: GridNeighborCache.h:49
Coord constraintAreaMax
Definition: GridNeighborCache.h:50
Coord cellSize
Definition: GridNeighborCache.h:54
double maxSpeed
Definition: GridNeighborCache.h:53
double refillPeriod
Definition: GridNeighborCache.h:52
inet::physicallayer::GridNeighborCache::~GridNeighborCache ( )
virtual
154 {
155  cancelAndDelete(refillCellsTimer);
156  delete grid;
157 }
cMessage * refillCellsTimer
Definition: GridNeighborCache.h:51
SpatialGrid * grid
Definition: GridNeighborCache.h:47

Member Function Documentation

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

Implements inet::physicallayer::INeighborCache.

96 {
97  radios.push_back(radio);
98  Coord radioPos = radio->getAntenna()->getMobility()->getCurrentPosition();
100  if (maxSpeed != 0 && !refillCellsTimer->isScheduled() && initialized())
101  scheduleAt(simTime() + refillPeriod, refillCellsTimer);
102  Coord newConstraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
103  Coord newConstraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
104  // If the constraintArea changed we must rebuild the grid
105  if (newConstraintAreaMin != constraintAreaMin || newConstraintAreaMax != constraintAreaMax)
106  {
107  constraintAreaMin = newConstraintAreaMin;
108  constraintAreaMax = newConstraintAreaMax;
109  if (initialized())
110  fillCubeVector();
111  }
112  else if(initialized())
113  grid->insertPoint(check_and_cast<const cObject *>(radio),radioPos);
114 }
virtual Coord getMinConstraintArea() const =0
Returns the minimum possible position among the radios, the coordinate values are in the range (-infi...
Radios radios
Definition: GridNeighborCache.h:48
cMessage * refillCellsTimer
Definition: GridNeighborCache.h:51
const value_type & get() const
Definition: Units.h:89
bool insertPoint(const cObject *point, const Coord &pos)
Definition: SpatialGrid.cc:69
SpatialGrid * grid
Definition: GridNeighborCache.h:47
Coord constraintAreaMin
Definition: GridNeighborCache.h:50
RadioMedium * radioMedium
Definition: GridNeighborCache.h:49
Coord constraintAreaMax
Definition: GridNeighborCache.h:50
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
double maxSpeed
Definition: GridNeighborCache.h:53
double refillPeriod
Definition: GridNeighborCache.h:52
virtual Coord getMaxConstraintArea() const =0
Returns the maximum possible position among the radios, the coordinate values are in the range (-infi...
void fillCubeVector()
Definition: GridNeighborCache.cc:84
virtual mps getMaxSpeed() const =0
Returns the maximum possible speed among the radios, the value is in the range [0, +infinity) or NaN if unspecified.
void inet::physicallayer::GridNeighborCache::fillCubeVector ( )
protected

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

85 {
86  delete grid;
87  grid = new SpatialGrid(cellSize, constraintAreaMin, constraintAreaMax);
88  for (auto & elem : radios) {
89  const IRadio *radio = elem;
90  Coord radioPos = radio->getAntenna()->getMobility()->getCurrentPosition();
91  grid->insertPoint(check_and_cast<const cObject *>(radio), radioPos);
92  }
93 }
Radios radios
Definition: GridNeighborCache.h:48
bool insertPoint(const cObject *point, const Coord &pos)
Definition: SpatialGrid.cc:69
SpatialGrid * grid
Definition: GridNeighborCache.h:47
Coord constraintAreaMin
Definition: GridNeighborCache.h:50
Coord constraintAreaMax
Definition: GridNeighborCache.h:50
Coord cellSize
Definition: GridNeighborCache.h:54
void inet::physicallayer::GridNeighborCache::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
66 {
67  if (!msg->isSelfMessage())
68  throw cRuntimeError("This module only handles self messages");
69  EV_DETAIL << "Updating the grid cells" << endl;
71  scheduleAt(simTime() + refillPeriod, msg);
72 }
double refillPeriod
Definition: GridNeighborCache.h:52
void fillCubeVector()
Definition: GridNeighborCache.cc:84
void inet::physicallayer::GridNeighborCache::initialize ( int  stage)
overrideprotectedvirtual
40 {
41  if (stage == INITSTAGE_LOCAL) {
42  radioMedium = getModuleFromPar<RadioMedium>(par("radioMediumModule"), this);
43  cellSize.x = par("cellSizeX");
44  cellSize.y = par("cellSizeY");
45  cellSize.z = par("cellSizeZ");
46  refillPeriod = par("refillPeriod");
47  refillCellsTimer = new cMessage("refillCellsTimer");
48  }
49  else if (stage == INITSTAGE_LINK_LAYER_2) {
53  const Coord constraintAreaSize = constraintAreaMax - constraintAreaMin;
54  if (std::isnan(cellSize.x))
55  cellSize.x = constraintAreaSize.x / par("cellCountX").doubleValue();
56  if (std::isnan(cellSize.y))
57  cellSize.y = constraintAreaSize.y / par("cellCountY").doubleValue();
58  if (std::isnan(cellSize.z))
59  cellSize.z = constraintAreaSize.z / par("cellCountZ").doubleValue();
61  scheduleAt(simTime() + refillPeriod, refillCellsTimer);
62  }
63 }
virtual Coord getMinConstraintArea() const =0
Returns the minimum possible position among the radios, the coordinate values are in the range (-infi...
cMessage * refillCellsTimer
Definition: GridNeighborCache.h:51
double z
Definition: Coord.h:51
const value_type & get() const
Definition: Units.h:89
Coord constraintAreaMin
Definition: GridNeighborCache.h:50
Local initializations.
Definition: InitStages.h:35
RadioMedium * radioMedium
Definition: GridNeighborCache.h:49
Coord constraintAreaMax
Definition: GridNeighborCache.h:50
Coord cellSize
Definition: GridNeighborCache.h:54
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
double maxSpeed
Definition: GridNeighborCache.h:53
double y
Definition: Coord.h:50
double refillPeriod
Definition: GridNeighborCache.h:52
double x
Definition: Coord.h:49
virtual Coord getMaxConstraintArea() const =0
Returns the maximum possible position among the radios, the coordinate values are in the range (-infi...
Additional link-layer initializations that depend on the previous stage.
Definition: InitStages.h:64
void fillCubeVector()
Definition: GridNeighborCache.cc:84
virtual mps getMaxSpeed() const =0
Returns the maximum possible speed among the radios, the value is in the range [0, +infinity) or NaN if unspecified.
virtual int inet::physicallayer::GridNeighborCache::numInitStages ( ) const
inlineoverrideprotectedvirtual
57 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
std::ostream & inet::physicallayer::GridNeighborCache::printToStream ( std::ostream &  stream,
int  level 
) const
overridevirtual

Prints this object to the provided output stream.

Function calls to operator<< with pointers or references either const or not are all forwarded to this function.

Reimplemented from inet::physicallayer::IPrintableObject.

75 {
76  stream << "GridNeighborCache";
77  if (level <= PRINT_LEVEL_TRACE)
78  stream << ", cellSize = " << cellSize
79  << ", refillPeriod = " << refillPeriod
80  << ", maxSpeed = " << maxSpeed;
81  return stream;
82 }
Coord cellSize
Definition: GridNeighborCache.h:54
double maxSpeed
Definition: GridNeighborCache.h:53
double refillPeriod
Definition: GridNeighborCache.h:52
void inet::physicallayer::GridNeighborCache::removeRadio ( const IRadio radio)
overridevirtual

Implements inet::physicallayer::INeighborCache.

117 {
118  auto it = find(radios.begin(), radios.end(), radio);
119  if (it != radios.end()) {
120  radios.erase(it);
121  Coord newConstraintAreaMin = radioMedium->getMediumLimitCache()->getMinConstraintArea();
122  Coord newConstraintAreaMax = radioMedium->getMediumLimitCache()->getMaxConstraintArea();
123  if (newConstraintAreaMin != constraintAreaMin || newConstraintAreaMax != constraintAreaMax)
124  {
125  constraintAreaMin = newConstraintAreaMin;
126  constraintAreaMax = newConstraintAreaMax;
127  }
129  fillCubeVector();
130  if (maxSpeed == 0 && initialized())
131  cancelEvent(refillCellsTimer);
132  }
133  else {
134  throw cRuntimeError("You can't remove radio: %d because it is not in our radio vector", radio->getId());
135  }
136 }
virtual Coord getMinConstraintArea() const =0
Returns the minimum possible position among the radios, the coordinate values are in the range (-infi...
Radios radios
Definition: GridNeighborCache.h:48
cMessage * refillCellsTimer
Definition: GridNeighborCache.h:51
const value_type & get() const
Definition: Units.h:89
Coord constraintAreaMin
Definition: GridNeighborCache.h:50
RadioMedium * radioMedium
Definition: GridNeighborCache.h:49
Coord constraintAreaMax
Definition: GridNeighborCache.h:50
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
double maxSpeed
Definition: GridNeighborCache.h:53
virtual Coord getMaxConstraintArea() const =0
Returns the maximum possible position among the radios, the coordinate values are in the range (-infi...
void fillCubeVector()
Definition: GridNeighborCache.cc:84
virtual mps getMaxSpeed() const =0
Returns the maximum possible speed among the radios, the value is in the range [0, +infinity) or NaN if unspecified.
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::physicallayer::GridNeighborCache::sendToNeighbors ( IRadio transmitter,
const IRadioFrame frame,
double  range 
) const
overridevirtual

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

Implements inet::physicallayer::INeighborCache.

139 {
140  double radius = range + (maxSpeed * refillPeriod);
141  Coord transmitterPos = transmitter->getAntenna()->getMobility()->getCurrentPosition();
142  GridNeighborCacheVisitor visitor(radioMedium, transmitter, frame);
143  grid->rangeQuery(transmitterPos, radius, &visitor);
144 }
void rangeQuery(const Coord &pos, double range, const IVisitor *visitor) const
Definition: SpatialGrid.cc:91
SpatialGrid * grid
Definition: GridNeighborCache.h:47
RadioMedium * radioMedium
Definition: GridNeighborCache.h:49
double maxSpeed
Definition: GridNeighborCache.h:53
double refillPeriod
Definition: GridNeighborCache.h:52

Member Data Documentation

Coord inet::physicallayer::GridNeighborCache::cellSize
protected
Coord inet::physicallayer::GridNeighborCache::constraintAreaMax
protected
Coord inet::physicallayer::GridNeighborCache::constraintAreaMin
protected
SpatialGrid* inet::physicallayer::GridNeighborCache::grid
protected
double inet::physicallayer::GridNeighborCache::maxSpeed
protected
RadioMedium* inet::physicallayer::GridNeighborCache::radioMedium
protected
Radios inet::physicallayer::GridNeighborCache::radios
protected
cMessage* inet::physicallayer::GridNeighborCache::refillCellsTimer
protected
double inet::physicallayer::GridNeighborCache::refillPeriod
protected

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