EMANE  1.2.1
neighborentry.cc
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 
35 #include "neighborentry.h"
36 
38  lastActivityTime_{},
39  fEstimatedNumCommonNeighbors_{},
40  fHiddenChannelActivity_{},
41  fAverageHiddenRxPowerMilliWatts_{},
42  fAverageCommonRxPowerMilliWatts_{}
43 {
44  prevUtilizationTypeMap_.insert(std::make_pair(MSG_TYPE_BROADCAST_DATA, NeighborEntry::Utilization()));
45  prevUtilizationTypeMap_.insert(std::make_pair(MSG_TYPE_UNICAST_DATA, NeighborEntry::Utilization()));
46  prevUtilizationTypeMap_.insert(std::make_pair(MSG_TYPE_UNICAST_RTS_CTS_DATA, NeighborEntry::Utilization()));
47  prevUtilizationTypeMap_.insert(std::make_pair(MSG_TYPE_UNICAST_CTS_CTRL, NeighborEntry::Utilization()));
48 
49  currUtilizationTypeMap_.insert(std::make_pair(MSG_TYPE_BROADCAST_DATA, NeighborEntry::Utilization()));
50  currUtilizationTypeMap_.insert(std::make_pair(MSG_TYPE_UNICAST_DATA, NeighborEntry::Utilization()));
51  currUtilizationTypeMap_.insert(std::make_pair(MSG_TYPE_UNICAST_RTS_CTS_DATA, NeighborEntry::Utilization()));
52  currUtilizationTypeMap_.insert(std::make_pair(MSG_TYPE_UNICAST_CTS_CTRL, NeighborEntry::Utilization()));
53 }
54 
55 
56 
59 {
60  return lastActivityTime_;
61 }
62 
63 
64 
67 {
68  EMANE::Microseconds result{};
69 
70  // all utilization types
71  for(auto & iter : prevUtilizationTypeMap_)
72  {
73  // check mask
74  if(iter.first & msgTypeMask)
75  {
76  result += iter.second.totalUtilizationMicroseconds_;
77  }
78  }
79 
80  return result;
81 }
82 
83 
84 
85 float
87 {
88  return fHiddenChannelActivity_;
89 }
90 
91 
92 
93 void
95 {
96  fHiddenChannelActivity_ = fActivity;
97 }
98 
99 
100 
101 size_t
103 {
104  size_t result = 0;
105 
106  // all utilization types
107  for(auto & iter : prevUtilizationTypeMap_)
108  {
109  // check mask
110  if(iter.first & msgTypeMask)
111  {
112  result += iter.second.totalNumPackets_;
113  }
114  }
115 
116  return result;
117 }
118 
119 
120 
121 float
123 {
124  return fEstimatedNumCommonNeighbors_;
125 }
126 
127 
128 
129 
130 void
132 {
133  fEstimatedNumCommonNeighbors_ = num;
134 }
135 
136 
137 
138 float
140 {
141  return fAverageHiddenRxPowerMilliWatts_;
142 }
143 
144 
145 
146 void
148 {
149  fAverageHiddenRxPowerMilliWatts_ = fAverageHiddenRxPowerMilliWatts;
150 }
151 
152 
153 float
155 {
156  return fAverageCommonRxPowerMilliWatts_;
157 }
158 
159 
160 void
162 {
163  fAverageCommonRxPowerMilliWatts_ = dAverageCommonRxPowerMilliWatts;
164 }
165 
166 
167 float
169 {
170  float result{};
171 
172  for(auto & iter : prevUtilizationTypeMap_)
173  {
174  // check mask
175  if(iter.first & msgTypeMask)
176  {
177  result += iter.second.fTotalRxPowerMilliWatts_;
178  }
179  }
180 
181  return result;
182 }
183 
184 
185 
186 void
188 {
189  prevUtilizationTypeMap_ = currUtilizationTypeMap_;
190 
191  // all utilization types
192  for(auto & iter : currUtilizationTypeMap_)
193  {
194  // reset entry
195  iter.second.reset();
196  }
197 }
198 
199 
200 void
202  std::uint8_t type,
203  const EMANE::TimePoint & activityTime,
204  float fRxPowerMilliWatts,
205  size_t numPackets)
206 {
207  currUtilizationTypeMap_[type].update(numPackets, bandWidthMicroseconds, fRxPowerMilliWatts);
208 
209  lastActivityTime_ = activityTime;
210 }
211 
212 
213 
214 void
216 {
217  oneHopNbrSet_ = nbrs;
218 }
219 
220 
221 
222 void
224 {
225  hiddenNbrSet_ = nbrs;
226 }
227 
228 
229 
230 void
232 {
233  commonNbrSet_ = nbrs;
234 }
235 
236 
237 
240 {
241  return oneHopNbrSet_;
242 }
243 
244 
247 {
248  return commonNbrSet_;
249 }
250 
251 
254 {
255  return hiddenNbrSet_;
256 }
257 
258 
259 bool
261 {
262  return oneHopNbrSet_.find(id) != oneHopNbrSet_.end();
263 }
264 
265 
266 bool
268 {
269  return commonNbrSet_.find(id) != commonNbrSet_.end();
270 }
271 
272 
273 bool
275 {
276  return hiddenNbrSet_.find(id) != hiddenNbrSet_.end();
277 }
void setAverageCommonRxPowerMilliWatts(float dAverageCommonRxPowerMilliWatts)
const std::uint8_t MSG_TYPE_UNICAST_CTS_CTRL
Definition: msgtypes.h:48
size_t getNumberOfPackets(std::uint8_t msgTypeMask) const
bool isOneHopNbr(EMANE::NEMId id) const
bool isCommonNbr(EMANE::NEMId id) const
EMANE::TimePoint getLastActivityTime() const
void setAverageHiddenRxPowerMilliWatts(float dAverageHiddenRxPowerMilliWatts)
void setHiddenChannelActivity(float fActivity)
Microseconds getUtilizationMicroseconds(std::uint8_t msgTypeMask) const
void setOneHopNeighbors(const NbrSet &nbrs)
float getRxPowerMilliWatts(std::uint8_t msgTypeMask) const
void updateChannelActivity(const Microseconds &utilizationMicroseconds, std::uint8_t type, const TimePoint &activityTime, float fRxPowerMilliWatts, size_t numPackets=1)
const std::uint8_t MSG_TYPE_BROADCAST_DATA
Definition: msgtypes.h:45
std::chrono::microseconds Microseconds
Definition: types.h:45
std::uint16_t NEMId
Definition: types.h:52
void setHiddenNeighbors(const NbrSet &nbrs)
void setCommonNeighbors(const NbrSet &nbrs)
std::set< EMANE::NEMId > NbrSet
Definition: neighbortype.h:47
const std::uint8_t MSG_TYPE_UNICAST_DATA
Definition: msgtypes.h:46
bool isHiddenNbr(EMANE::NEMId id) const
Clock::time_point TimePoint
Definition: types.h:50
const std::uint8_t MSG_TYPE_UNICAST_RTS_CTS_DATA
Definition: msgtypes.h:47