EMANE  1.0.1
models/mac/ieee80211abg/maclayer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2016 - Adjacent Link LLC, Bridgewater, New Jersey
3  * Copyright (c) 2008-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 EMANEMODELSIEEE802ABGMACLAYER_HEADER_
35 #define EMANEMODELSIEEE802ABGMACLAYER_HEADER_
36 
37 #include "emane/maclayerimpl.h"
38 #include "emane/mactypes.h"
40 #include "emane/transmitter.h"
41 #include "emane/frequencysegment.h"
44 
47 
48 #include "macheaderparams.h"
49 #include "downstreamqueue.h"
50 #include "transmissiontxstate.h"
51 #include "macstatistics.h"
52 
53 #include "macconfig.h"
54 #include "modetimingparameters.h"
55 #include "pcrmanager.h"
56 #include "neighbormanager.h"
57 #include "collisiontable.h"
58 
59 #include <memory>
60 
61 #include <map>
62 #include <vector>
63 
64 namespace EMANE
65 {
66  namespace Models
67  {
68  namespace IEEE80211ABG
69  {
76  {
77  std::uint16_t seq_; // sequence number
78  TimePoint tp_; // validity time
79 
86  SequenceEntry(std::uint16_t seq, const TimePoint & tp) :
87  seq_(seq),
88  tp_(tp)
89  { }
90  };
91 
92  using SequenceVector = std::vector<SequenceEntry>;
93 
94  using DuplicateMap = std::map<NEMId, SequenceVector>;
95 
96  class TransmissionTxState;
97 
105  {
106  public:
107  MACLayer(NEMId id,
108  PlatformServiceProvider *pPlatformServiceProvider,
109  RadioServiceProvider * pRadioServiceProvider);
110 
111  ~MACLayer();
112 
113  /*
114  * Component Interface
115  */
116  void initialize(Registrar & registrar) override;
117 
118  void configure(const ConfigurationUpdate & update) override;
119 
120  void start() override;
121 
122  void postStart() override;
123 
124  void stop() override;
125 
126  void destroy() throw() override;
127 
128  void processUpstreamControl(const ControlMessages & msgs) override;
129 
130 
131  void processUpstreamPacket(const CommonMACHeader & hdr,
132  UpstreamPacket & pkt,
133  const ControlMessages & msgs) override;
134 
135  void processDownstreamControl(const ControlMessages & msgs) override;
136 
137 
138  void processDownstreamPacket(DownstreamPacket & pkt,
139  const ControlMessages & msgs) override;
140 
141 
142  void processEvent(const EventId &, const Serialization &);
143 
144  void processConfiguration(const ConfigurationUpdate & update) override;
145 
151  enum COLLISION_TYPE { COLLISION_TYPE_NONE = 0x00,
152  COLLISION_TYPE_CLOBBER_RX_DURING_TX = 0x01,
153  COLLISION_TYPE_NOISE_COMMON_RX = 0x02,
154  COLLISION_TYPE_CLOBBER_RX_HIDDEN_BUSY = 0x04,
155  COLLISION_TYPE_NOISE_HIDDEN_RX = 0x08 };
156 
157 
165  NEMId getId()const;
166 
167 
175  void sendDownstreamBroadcastData(DownstreamQueueEntry &);
176 
177 
185  void sendDownstreamUnicastData(DownstreamQueueEntry &entry);
186 
187 
196  void sendDownstreamUnicastCts(DownstreamQueueEntry & entry,
197  NEMId origin);
198 
207  void sendDownstreamMessage(DownstreamQueueEntry & entry,
208  MACHeaderParams & macHeaderParams);
209 
220  bool isDuplicate(NEMId src, std::uint16_t seq);
221 
222 
230  bool addToken();
231 
232 
240  bool removeToken();
241 
242 
250  void setDelayTime(IEEE80211ABG::DownstreamQueueEntry &entry);
251 
252 
266  COLLISION_TYPE checkForRxCollision(NEMId src, std::uint8_t u8Category, std::uint8_t retries);
267 
268 
274  MACStatistics & getStatistics();
275 
276 
282  ModeTimingParameters & getModeTiming();
283 
284 
285  private:
286  static const RegistrationId registrationId_ {EMANE::REGISTERED_EMANE_MAC_IEEE_802_11_ABG};
287 
288  NEMId id_;
289 
290  MACConfig macConfig_;
291 
292  MACStatistics macStatistics_;
293 
294  DownstreamQueue downstreamQueue_;
295 
296  TransmissionTxState *pTxState_;
297 
298  PCRManager pcrManager_;
299 
300  NeighborManager neighborManager_;
301 
302  NeighborMetricManager neighborMetricManager_;
303 
304  QueueMetricManager queueMetricManager_;
305 
306  FlowControlManager flowControlManager_;
307 
308  CollisionTable collisionTable_;
309 
310  std::uint64_t u64SequenceNumber_;
311 
312  std::uint16_t u16EntrySequenceNumber_;
313 
314  DuplicateMap duplicateMap_;
315 
316  ModeTimingParameters modeTiming_;
317 
318  TimerEventId channelUsageTimedEventId_;
319 
320  TimerEventId radioMetricTimedEventId_;
321 
322  TimerEventId downstreamQueueTimedEventId_;
323 
324  bool bHasPendingDownstreamQueueEntry_;
325 
326  DownstreamQueueEntry pendingDownstreamQueueEntry_;
327 
328  std::unique_ptr<std::function<bool()>> pChannelUsageCallback_;
329 
330  std::unique_ptr<std::function<bool()>> pRadioMetricCallback_;
331 
332  Utils::RandomNumberDistribution<std::mt19937,
333  std::uniform_real_distribution<float>> RNDZeroToOne_;
334 
335  std::vector<std::unique_ptr<Utils::CommonLayerStatistics>> commonLayerStatistics_;
336 
337  TimePoint currentEndOfTransmissionTime_;
338 
339  bool handleDownstreamQueueEntry(std::uint64_t u64SequenceNumber);
340 
341  void setEntrySequenceNumber(DownstreamQueueEntry &entry);
342 
343  void handleUpstreamPacket(UpstreamPacket & pkt,
344  double dRxPowerdBm,
345  double dNoiseFloordBm,
346  std::uint64_t u64SequenceNumber,
347  const TimePoint & rBeginTime,
348  std::uint8_t u8Category);
349 
350 
351  std::pair<bool, std::uint16_t> checkUpstremReception(UpstreamPacket &pkt,
352  const TimePoint & currentTime,
353  std::uint64_t u64SequenceNumber,
354  double dRxPowerdBm,
355  double dNoiseFloordBm,
356  const MACHeaderParams & macHeaderParams,
357  int tryNum,
358  std::uint8_t u8Category);
359 
360  void changeDownstreamState(TransmissionTxState *);
361 
362  bool checkPOR(float fSINR, size_t packetSize, std::uint16_t u16DataRateIndex);
363 
364  std::uint8_t dscpToCategory(std::uint8_t dscp) const;
365 
366  inline bool isBroadcast(NEMId nemId)
367  {
368  return nemId == NEM_BROADCAST_MAC_ADDRESS;
369  }
370 
371 
372  friend class TransmissionTxState;
373  };
374  }
375  }
376 }
377 
378 #endif //EMANEMODELSIEEE802ABGMACLAYER_HEADER_
std::string Serialization
Definition: serializable.h:42
A Packet class that allows upstream processing to strip layer headers as the packet travels up the st...
The Registrar interface provides access to all of the emulator registrars.
Definition: registrar.h:50
class used to define the mac layer configuration items
Definition: macconfig.h:152
provides access to the pcr curves
class used to define timing parameters
Flow Control Manager (token producer) side.
std::map< NEMId, SequenceVector > DuplicateMap
std::list< const ControlMessage * > ControlMessages
class used to define the mac downstream packet queue
std::vector< SequenceEntry > SequenceVector
structure defines the mac downstream packet queue entry
constexpr NEMId NEM_BROADCAST_MAC_ADDRESS
Definition: types.h:69
const RegistrationId REGISTERED_EMANE_MAC_IEEE_802_11_ABG
Definition: mactypes.h:60
Manager Queue metrics.
std::uint16_t EventId
Definition: types.h:53
The PlatformServiceProvider interface provides access to emulator services.
base class used to define the transitions for the mac tx states
Specialized packet the allows downstream processing to add layer specific headers as the packet trave...
std::uint16_t RegistrationId
Definition: types.h:59
Defines the ieee 80211 abg 1 and 2 hop neighbor manager.
class used to define the mac layer statistic items
Definition: macstatistics.h:57
std::uint16_t NEMId
Definition: types.h:52
SequenceEntry(std::uint16_t seq, const TimePoint &tp)
The RadioServiceProvider interface provides access to radio (RF) model specific services.
structure used to define parameters to detect duplicate frames
std::vector< ConfigurationNameAnyValues > ConfigurationUpdate
union EtherAddr src
Definition: netutils.h:391
std::size_t TimerEventId
Definition: types.h:54
Clock::time_point TimePoint
Definition: types.h:50
Definition: agent.h:43
A utility wrapper around a generator and a distribution.
Defines a collision table based on contention window and number of neighbors.
Manages neighbor metrics and sends neighbor metric control message upstream.
Interface used to create a MAC layer plugin implementation.
Definition: maclayerimpl.h:48