EMANE  1.2.1
neighbormanager.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2010-2012 - DRS CenGen, LLC, Columbia, Maryland
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of DRS CenGen, LLC nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef EMANEMODELSIEEE802ABGNEIGHBORMANAGER_HEADER_
35 #define EMANEMODELSIEEE802ABGNEIGHBORMANAGER_HEADER_
36 
37 
38 #include "emane/types.h"
41 #include "emane/statistictable.h"
42 
44 
45 #include "wmmmanager.h"
46 #include "neighborentry.h"
47 #include "neighbor2hopentry.h"
48 #include "onehopneighborsevent.h"
49 
50 #include <map>
51 #include <list>
52 
53 namespace EMANE
54  {
55  namespace Models
56  {
57  namespace IEEE80211ABG
58  {
59  class MACLayer;
60 
68  {
69  public:
71  PlatformServiceProvider * pPlatformService,
72  MACLayer *pMgr);
73 
75 
77  std::uint8_t type,
78  float fRxPowerMilliWatts,
79  const TimePoint & timePoint,
80  const Microseconds & duration,
81  std::uint8_t u8Category);
82 
84  NEMId origin,
85  std::uint8_t type,
86  float fRxPowerMilliWatts,
87  const TimePoint & tvTime,
88  const Microseconds & duration,
89  std::uint8_t u8Category);
90 
91  void handleOneHopNeighborsEvent(const Serialization &serialization);
92 
93  void start();
94 
95  void resetStatistics();
96 
97  void setNeighborTimeoutMicroseconds(const Microseconds & timeOutMicroseconds);
98 
100 
102 
103  float getHiddenChannelActivity(NEMId src) const;
104 
106 
108 
109  float getLocalNodeTx() const;
110 
111  size_t getTotalActiveOneHopNeighbors() const;
112 
113  void setCategories(std::uint8_t u8NumCategories);
114 
116 
118 
120 
122 
124 
126 
128 
130 
132 
134 
136 
137  void registerStatistics(StatisticRegistrar & statisticRegistrar);
138 
139  private:
140  using NeighborEntryMap = std::map<NEMId, NeighborEntry>;
141 
142  using NeighborEntryInsertResult = std::pair<NeighborEntryMap::iterator, bool>;
143 
144  using Neighbor2HopEntryMap = std::map<NEMId, Neighbor2HopEntry>;
145 
146  using Neighbor2HopEntryInsertResult = std::pair<Neighbor2HopEntryMap::iterator, bool>;
147 
148  using NbrSetMap = std::map<NEMId, NbrSet>;
149 
150  using NbrUtilizationMap = std::map<NEMId, Microseconds>;
151 
152  using ProbabilityPair = std::pair<float, float>;
153 
154  using ProbabilityPairMap = std::map<NEMId, ProbabilityPair>;
155 
156  using ProbabilityPairMapMap = std::map<NEMId, ProbabilityPairMap>;
157 
158  using RxPowerMap = std::map<NEMId, float>;
159 
160  NEMId id_;
161 
162  PlatformServiceProvider * pPlatformService_;
163 
164  MACLayer *pMACLayer_;
165 
166  WMMManager wmmManager_;
167 
168  NeighborEntryMap oneHopNbrMap_;
169 
170  Neighbor2HopEntryMap twoHopNbrMap_;
171 
172  NbrSetMap cachedOneHopNbrSetMap_;
173 
174  Microseconds totalOneHopUtilizationMicroseconds_;
175 
176  Microseconds totalTwoHopUtilizationMicroseconds_;
177 
178  size_t totalOneHopNumPackets_;
179 
180  size_t totalTwoHopNumPackets_;
181 
182  size_t numTotalActiveOneHopNeighbors_;
183 
184  Microseconds averageMessageDurationMicroseconds_;
185 
186  float fAverageRxPowerPerMessageMilliWatts_;
187 
188  float fTotalRxPowerMilliWatts_;
189 
190  Microseconds averageUtilizationPerOneHopNbrMicroseconds_;
191 
192  Microseconds averageUtilizationPerTwoHopNbrMicroseconds_;
193 
194  float fEstimatedNumOneHopNeighbors_;
195 
196  float fEstimatedNumTwoHopNeighbors_;
197 
198  float fLocalNodeTx_;
199 
200  size_t sumCommonPackets_;
201 
202  size_t sumHiddenPackets_;
203 
204  float fCommonRxPowerMilliWatts_;
205 
206  float fHiddenRxPowerMilliWatts_;
207 
208  Microseconds utilizationThisNEMMicroseconds_;
209 
210  Microseconds nbrTimeOutMicroseconds_;
211 
212  TimePoint lastOneHopNbrListTxTime_;
213 
214  NbrUtilizationMap oneHopUtilizationMap_;
215 
216  NbrUtilizationMap twoHopUtilizationMap_;
217 
218  ProbabilityPairMapMap commonProbabilityMapMap_;
219 
220  ProbabilityPairMapMap hiddenProbabilityMapMap_;
221 
222  RxPowerMap commonNbrAvgRxPowerMwMap_;
223 
224  RxPowerMap hiddenNbrAvgRxPowerMwMap_;
225 
226  WMMManager::UtilizationRatioVector utilizationRatioVector_;
227 
228  Utils::RandomNumberDistribution<std::mt19937,
229  std::uniform_real_distribution<float>> RNDZeroToOne_;
230 
231  StatisticTable<NEMId> * pStatisticOneHopNbrTable_;
232 
233  StatisticTable<NEMId> * pStatisticTwoHopNbrTable_;
234 
235  TimePoint lastResetTime_;
236 
237  void sendOneHopNbrListEvent_i();
238 
239  bool flushOneHopNeighbors_i(const TimePoint & tvCurrentTime, const Microseconds & timeOutMicroseconds);
240 
241  bool flushTwoHopNeighbors_i(const TimePoint & tvCurrentTime, const Microseconds & timeOutMicroseconds);
242 
243  void resetCounters_i();
244 
245  void calculateBwUtilization_i(const Microseconds & deltaTMicroseconds);
246 
247  NeighborEntryInsertResult addOneHopNeighbor_i(NEMId src);
248 
249  Neighbor2HopEntryInsertResult addTwoHopNeighbor_i(NEMId src);
250 
251  float getA_i(const Microseconds & utilizationMicroseconds, const Microseconds & avgUtilizationMicroseconds) const;
252 
253  float getC_i(const Microseconds & utilizationMicroseconds, const Microseconds & deltaTMicroseconds) const;
254 
255  float getH_i(const Microseconds & utilizationMicroseconds, const Microseconds & deltaTMicroseconds) const;
256 
257  float getChannelActivity_i(const Microseconds & utilizationMicroseconds, const Microseconds & deltaTMicroseconds) const;
258 
259  void setCommonAndHiddenProbability_i();
260 
261  ProbabilityPairMap setProbability_i(NEMId id, const NbrUtilizationMap & map,
262  const Microseconds & utilizationMicroseconds,
263  const NbrSet & nbrSet, const char * str) const;
264 
265  float getRandomRxPowerMilliWatts_i(NEMId src, float R1,
266  const ProbabilityPairMapMap & pmap,
267  const RxPowerMap & rmap) const;
268  };
269  }
270  }
271 }
272 #endif //EMANEMODELSIEEE802ABGNEIGHBORMANAGER_HEADER_
std::string Serialization
Definition: serializable.h:42
void handleOneHopNeighborsEvent(const Serialization &serialization)
void registerStatistics(StatisticRegistrar &statisticRegistrar)
void setNeighborTimeoutMicroseconds(const Microseconds &timeOutMicroseconds)
std::vector< UtilizationRatioPair > UtilizationRatioVector
Definition: wmmmanager.h:61
Microseconds getAllUtilizationMicroseconds(NEMId src) const
The PlatformServiceProvider interface provides access to emulator services.
float getNumberOfEstimatedCommonNeighbors(NEMId src) const
void updateCtrlChannelActivity(NEMId src, NEMId origin, std::uint8_t type, float fRxPowerMilliWatts, const TimePoint &tvTime, const Microseconds &duration, std::uint8_t u8Category)
The StatisticRegistrar allows NEM layers to register statistics and statistic tables. Statistics and Statistic tables are owned by the emulator framework and a borrowed reference is returned to the registering NEM layer.
Defines the ieee 80211 abg 1 and 2 hop neighbor manager.
void setCategories(std::uint8_t u8NumCategories)
std::chrono::microseconds Microseconds
Definition: types.h:45
std::uint16_t NEMId
Definition: types.h:52
Microseconds getTotalOneHopUtilizationMicroseconds() const
NeighborManager(NEMId id, PlatformServiceProvider *pPlatformService, MACLayer *pMgr)
float getNumberOfEstimatedHiddenNeighbors(NEMId src) const
std::set< EMANE::NEMId > NbrSet
Definition: neighbortype.h:47
Microseconds getTotalTwoHopUtilizationMicroseconds() const
union EtherAddr src
Definition: netutils.h:391
Microseconds getAverageMessageDurationMicroseconds() const
Defines the WMM manager.
Definition: wmmmanager.h:56
Clock::time_point TimePoint
Definition: types.h:50
void updateDataChannelActivity(NEMId src, std::uint8_t type, float fRxPowerMilliWatts, const TimePoint &timePoint, const Microseconds &duration, std::uint8_t u8Category)
Definition: agent.h:43
A utility wrapper around a generator and a distribution.
WMMManager::UtilizationRatioVector getUtilizationRatios()