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

#include <NeighborListNeighborCache.h>

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

Classes

struct  RadioEntry
 

Public Types

typedef std::vector< RadioEntry * > RadioEntries
 
typedef std::vector< const IRadio * > Radios
 
typedef std::map< const IRadio *, RadioEntry * > RadioEntryCache
 
- 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

 NeighborListNeighborCache ()
 
 ~NeighborListNeighborCache ()
 
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 updateNeighborList (RadioEntry *radioEntry)
 
void updateNeighborLists ()
 
void removeRadioFromNeighborLists (const IRadio *radio)
 

Protected Attributes

RadioMediumradioMedium
 
RadioEntries radios
 
cMessage * updateNeighborListsTimer
 
RadioEntryCache radioToEntry
 
double refillPeriod
 
double range
 
double maxSpeed
 

Member Typedef Documentation

Constructor & Destructor Documentation

inet::physicallayer::NeighborListNeighborCache::NeighborListNeighborCache ( )
27  :
28  radioMedium(nullptr),
29  updateNeighborListsTimer(nullptr),
31  range(NaN),
32  maxSpeed(NaN)
33 {
34 }
double range
Definition: NeighborListNeighborCache.h:52
RadioMedium * radioMedium
Definition: NeighborListNeighborCache.h:47
double maxSpeed
Definition: NeighborListNeighborCache.h:53
cMessage * updateNeighborListsTimer
Definition: NeighborListNeighborCache.h:49
#define NaN
Definition: INETMath.h:103
double refillPeriod
Definition: NeighborListNeighborCache.h:51
inet::physicallayer::NeighborListNeighborCache::~NeighborListNeighborCache ( )
148 {
149  for (auto & elem : radios)
150  delete elem;
151 
152  cancelAndDelete(updateNeighborListsTimer);
153 }
cMessage * updateNeighborListsTimer
Definition: NeighborListNeighborCache.h:49
RadioEntries radios
Definition: NeighborListNeighborCache.h:48

Member Function Documentation

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

Implements inet::physicallayer::INeighborCache.

105 {
106  RadioEntry *newEntry = new RadioEntry(radio);
107  radios.push_back(newEntry);
108  radioToEntry[radio] = newEntry;
111  if (maxSpeed != 0 && !updateNeighborListsTimer->isScheduled() && initialized())
112  scheduleAt(simTime() + refillPeriod, updateNeighborListsTimer);
113 }
const value_type & get() const
Definition: Units.h:89
RadioMedium * radioMedium
Definition: NeighborListNeighborCache.h:47
double maxSpeed
Definition: NeighborListNeighborCache.h:53
cMessage * updateNeighborListsTimer
Definition: NeighborListNeighborCache.h:49
RadioEntries radios
Definition: NeighborListNeighborCache.h:48
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
double refillPeriod
Definition: NeighborListNeighborCache.h:51
void updateNeighborLists()
Definition: NeighborListNeighborCache.cc:130
RadioEntryCache radioToEntry
Definition: NeighborListNeighborCache.h:50
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::NeighborListNeighborCache::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
78 {
79  if (!msg->isSelfMessage())
80  throw cRuntimeError("This module only handles self messages");
81 
83 
84  scheduleAt(simTime() + refillPeriod, msg);
85 }
double refillPeriod
Definition: NeighborListNeighborCache.h:51
void updateNeighborLists()
Definition: NeighborListNeighborCache.cc:130
void inet::physicallayer::NeighborListNeighborCache::initialize ( int  stage)
overrideprotectedvirtual
37 {
38  if (stage == INITSTAGE_LOCAL) {
39  radioMedium = getModuleFromPar<RadioMedium>(par("radioMediumModule"), this);
40  refillPeriod = par("refillPeriod");
41  range = par("range");
42  updateNeighborListsTimer = new cMessage("updateNeighborListsTimer");
43  }
44  else if (stage == INITSTAGE_LINK_LAYER_2) {
47  scheduleAt(simTime() + refillPeriod, updateNeighborListsTimer);
48  }
49 }
double range
Definition: NeighborListNeighborCache.h:52
const value_type & get() const
Definition: Units.h:89
RadioMedium * radioMedium
Definition: NeighborListNeighborCache.h:47
double maxSpeed
Definition: NeighborListNeighborCache.h:53
cMessage * updateNeighborListsTimer
Definition: NeighborListNeighborCache.h:49
Local initializations.
Definition: InitStages.h:35
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
double refillPeriod
Definition: NeighborListNeighborCache.h:51
Additional link-layer initializations that depend on the previous stage.
Definition: InitStages.h:64
void updateNeighborLists()
Definition: NeighborListNeighborCache.cc:130
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::NeighborListNeighborCache::numInitStages ( ) const
inlineoverrideprotectedvirtual
56 { return NUM_INIT_STAGES; }
The number of initialization stages.
Definition: InitStages.h:116
std::ostream & inet::physicallayer::NeighborListNeighborCache::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.

52 {
53  stream << "NeighborListNeighborCache";
54  if (level <= PRINT_LEVEL_TRACE)
55  stream << ", refillPeriod = " << refillPeriod
56  << ", range = " << range
57  << ", maxSpeed = " << maxSpeed;
58  return stream;
59 }
double range
Definition: NeighborListNeighborCache.h:52
double maxSpeed
Definition: NeighborListNeighborCache.h:53
double refillPeriod
Definition: NeighborListNeighborCache.h:51
void inet::physicallayer::NeighborListNeighborCache::removeRadio ( const IRadio radio)
overridevirtual

Implements inet::physicallayer::INeighborCache.

116 {
117  auto it = find(radios.begin(), radios.end(), radioToEntry[radio]);
118  if (it != radios.end()) {
120  radios.erase(it);
122  if (maxSpeed == 0 && initialized())
123  cancelEvent(updateNeighborListsTimer);
124  }
125  else {
126  throw cRuntimeError("You can't remove radio: %d because it is not in our radio vector", radio->getId());
127  }
128 }
void removeRadioFromNeighborLists(const IRadio *radio)
Definition: NeighborListNeighborCache.cc:137
const value_type & get() const
Definition: Units.h:89
RadioMedium * radioMedium
Definition: NeighborListNeighborCache.h:47
double maxSpeed
Definition: NeighborListNeighborCache.h:53
cMessage * updateNeighborListsTimer
Definition: NeighborListNeighborCache.h:49
RadioEntries radios
Definition: NeighborListNeighborCache.h:48
virtual const IMediumLimitCache * getMediumLimitCache() const override
Definition: RadioMedium.h:328
RadioEntryCache radioToEntry
Definition: NeighborListNeighborCache.h:50
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::NeighborListNeighborCache::removeRadioFromNeighborLists ( const IRadio radio)
protected

Referenced by removeRadio().

138 {
139  for (auto & elem : radios) {
140  Radios neighborVector = elem->neighborVector;
141  auto it = find(neighborVector.begin(), neighborVector.end(), radio);
142  if (it != neighborVector.end())
143  neighborVector.erase(it);
144  }
145 }
std::vector< const IRadio * > Radios
Definition: NeighborListNeighborCache.h:43
RadioEntries radios
Definition: NeighborListNeighborCache.h:48
std::vector< T >::iterator find(std::vector< T > &v, const T &a)
Definition: stlutils.h:48
void inet::physicallayer::NeighborListNeighborCache::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.

62 {
63  if (this->range < range)
64  throw cRuntimeError("The transmitter's (id: %d) range is bigger then the cache range", transmitter->getId());
65 
66  RadioEntryCache::const_iterator it = radioToEntry.find(transmitter);
67  if (it == radioToEntry.end())
68  throw cRuntimeError("Transmitter is not found");
69 
70  RadioEntry *radioEntry = it->second;
71  Radios& neighborVector = radioEntry->neighborVector;
72 
73  for (auto & elem : neighborVector)
74  radioMedium->sendToRadio(transmitter, elem, frame);
75 }
double range
Definition: NeighborListNeighborCache.h:52
std::vector< const IRadio * > Radios
Definition: NeighborListNeighborCache.h:43
virtual void sendToRadio(IRadio *trasmitter, const IRadio *receiver, const IRadioFrame *frame)
Definition: RadioMedium.cc:553
RadioMedium * radioMedium
Definition: NeighborListNeighborCache.h:47
RadioEntryCache radioToEntry
Definition: NeighborListNeighborCache.h:50
void inet::physicallayer::NeighborListNeighborCache::updateNeighborList ( RadioEntry radioEntry)
protected

Referenced by updateNeighborLists().

88 {
89  IMobility *radioMobility = radioEntry->radio->getAntenna()->getMobility();
90  Coord radioPosition = radioMobility->getCurrentPosition();
91  double radius = maxSpeed * refillPeriod + range;
92  radioEntry->neighborVector.clear();
93 
94  for (auto & elem : radios) {
95  const IRadio *otherRadio = elem->radio;
96  Coord otherEntryPosition = otherRadio->getAntenna()->getMobility()->getCurrentPosition();
97 
98  if (otherRadio->getId() != radioEntry->radio->getId() &&
99  otherEntryPosition.sqrdist(radioPosition) <= radius * radius)
100  radioEntry->neighborVector.push_back(otherRadio);
101  }
102 }
double range
Definition: NeighborListNeighborCache.h:52
double maxSpeed
Definition: NeighborListNeighborCache.h:53
RadioEntries radios
Definition: NeighborListNeighborCache.h:48
double refillPeriod
Definition: NeighborListNeighborCache.h:51
void inet::physicallayer::NeighborListNeighborCache::updateNeighborLists ( )
protected

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

131 {
132  EV_DETAIL << "Updating the neighbor lists" << endl;
133  for (auto & elem : radios)
134  updateNeighborList(elem);
135 }
void updateNeighborList(RadioEntry *radioEntry)
Definition: NeighborListNeighborCache.cc:87
RadioEntries radios
Definition: NeighborListNeighborCache.h:48

Member Data Documentation

double inet::physicallayer::NeighborListNeighborCache::maxSpeed
protected
RadioMedium* inet::physicallayer::NeighborListNeighborCache::radioMedium
protected
RadioEntries inet::physicallayer::NeighborListNeighborCache::radios
protected
RadioEntryCache inet::physicallayer::NeighborListNeighborCache::radioToEntry
protected
double inet::physicallayer::NeighborListNeighborCache::range
protected
double inet::physicallayer::NeighborListNeighborCache::refillPeriod
protected
cMessage* inet::physicallayer::NeighborListNeighborCache::updateNeighborListsTimer
protected

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