A Discrete-Event Network Simulator
API
uan-mac-rc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Leonard Tracy <lentracy@gmail.com>
18  */
19 
20 #ifndef UAN_MAC_RC_H
21 #define UAN_MAC_RC_H
22 
23 #include "uan-mac.h"
24 
25 #include "ns3/event-id.h"
26 #include "ns3/mac8-address.h"
27 #include "ns3/nstime.h"
28 #include "ns3/random-variable-stream.h"
29 #include "ns3/trace-source-accessor.h"
30 #include "ns3/traced-callback.h"
31 
32 #include <list>
33 #include <utility>
34 #include <vector>
35 
36 namespace ns3
37 {
38 
39 class Address;
40 class UanTxMode;
41 class UanHeaderRcRts;
42 class UanHeaderRcCts;
43 class UanHeaderRcCtsGlobal;
44 class UanPhy;
45 
51 {
52  public:
54  Reservation();
65  uint8_t frameNo,
66  uint32_t maxPkts = 0);
68  ~Reservation();
74  uint32_t GetNoFrames() const;
82  uint32_t GetLength() const;
88  const std::list<std::pair<Ptr<Packet>, Mac8Address>>& GetPktList() const;
94  uint8_t GetFrameNo() const;
100  uint8_t GetRetryNo() const;
107  Time GetTimestamp(uint8_t n) const;
108 
110  bool IsTransmitted() const;
116  void SetFrameNo(uint8_t fn);
122  void AddTimestamp(Time t);
124  void IncrementRetry();
130  void SetTransmitted(bool t = true);
131 
132  private:
134  std::list<std::pair<Ptr<Packet>, Mac8Address>> m_pktList;
136  uint32_t m_length;
138  uint8_t m_frameNo;
140  std::vector<Time> m_timestamp;
142  uint8_t m_retryNo;
145 
146 }; // class Reservation
147 
162 class UanMacRc : public UanMac
163 {
164  public:
166  enum
167  {
172  TYPE_ACK
173  };
174 
176  UanMacRc();
178  ~UanMacRc() override;
179 
184  static TypeId GetTypeId();
185 
186  // Inherited methods
187  bool Enqueue(Ptr<Packet> pkt, uint16_t protocolNumber, const Address& dest) override;
188  void SetForwardUpCb(Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb) override;
189  void AttachPhy(Ptr<UanPhy> phy) override;
190  void Clear() override;
191  int64_t AssignStreams(int64_t stream) override;
192 
199  typedef void (*QueueTracedCallback)(Ptr<const Packet> packet, uint32_t proto);
200 
201  private:
203  enum State
204  {
209  DATATX
210  };
211 
214 
216  double m_retryRate;
219  uint32_t m_numRates;
220  uint32_t m_currentRate;
221  uint32_t m_maxFrames;
222  uint32_t m_queueLimit;
223  uint8_t m_frameNo;
226 
227  double m_minRetryRate;
228  double m_retryStep;
229 
230  uint32_t m_ctsSizeN;
231  uint32_t m_ctsSizeG;
232 
233  bool m_cleared;
234 
236  std::list<std::pair<Ptr<Packet>, Mac8Address>> m_pktQueue;
238  std::list<Reservation> m_resList;
239 
242 
249 
259  void ReceiveOkFromPhy(Ptr<Packet> pkt, double sinr, UanTxMode mode);
261  void Associate();
263  void AssociateTimeout();
265  void SendRts();
267  void RtsTimeout();
282  void ScheduleData(const UanHeaderRcCts& ctsh,
283  const UanHeaderRcCtsGlobal& ctsg,
284  uint32_t ctsBytes);
290  void ProcessAck(Ptr<Packet> ack);
297  void SendPacket(Ptr<Packet> pkt, uint32_t rate);
304  bool IsPhy1Ok();
306  void BlockRtsing();
307 
312  static uint32_t m_cntrlSends;
313 
316 
317  protected:
318  void DoDispose() override;
319 
320 }; // class UanMacRc
321 
322 } // namespace ns3
323 
324 #endif /* UAN_MAC_RC_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
An identifier for simulation events.
Definition: event-id.h:55
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:44
Stores reservation info for use in scheduling data channel by reservation channel MAC.
Definition: uan-mac-rc.h:51
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
Definition: uan-mac-rc.cc:85
uint32_t GetLength() const
Get the total length of the Reservation.
Definition: uan-mac-rc.cc:91
~Reservation()
Destructor.
Definition: uan-mac-rc.cc:74
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktList
Queued packets for each address.
Definition: uan-mac-rc.h:134
bool m_transmitted
Has this reservation been transmitted.
Definition: uan-mac-rc.h:144
const std::list< std::pair< Ptr< Packet >, Mac8Address > > & GetPktList() const
Get the list of packets.
Definition: uan-mac-rc.cc:97
Reservation()
Default constructor.
Definition: uan-mac-rc.cc:45
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n'th RTS.
Definition: uan-mac-rc.cc:115
uint8_t GetFrameNo() const
Get the frame number.
Definition: uan-mac-rc.cc:103
void IncrementRetry()
Increment the retry count.
Definition: uan-mac-rc.cc:139
uint8_t m_frameNo
Frame number.
Definition: uan-mac-rc.h:138
void SetFrameNo(uint8_t fn)
Set the frame number.
Definition: uan-mac-rc.cc:127
bool IsTransmitted() const
Definition: uan-mac-rc.cc:121
uint8_t m_retryNo
Number of retries.
Definition: uan-mac-rc.h:142
uint8_t GetRetryNo() const
Get the retry number.
Definition: uan-mac-rc.cc:109
uint32_t m_length
Total length of queued packets.
Definition: uan-mac-rc.h:136
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
Definition: uan-mac-rc.cc:145
void AddTimestamp(Time t)
Set the time of the latest RTS sent.
Definition: uan-mac-rc.cc:133
std::vector< Time > m_timestamp
Timestamps for each retry.
Definition: uan-mac-rc.h:140
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Cycle broadcast information.
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:46
Non-gateway node MAC for reservation channel MAC protocol.
Definition: uan-mac-rc.h:163
void Clear() override
Clears all pointer references.
Definition: uan-mac-rc.cc:175
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
Definition: uan-mac-rc.cc:504
void ReceiveOkFromPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok Callback.
Definition: uan-mac-rc.cc:325
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
Definition: uan-mac-rc.cc:419
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
Definition: uan-mac-rc.h:216
@ TYPE_RTS
RTS.
Definition: uan-mac-rc.h:170
@ TYPE_DATA
Data.
Definition: uan-mac-rc.h:168
@ TYPE_ACK
ACK.
Definition: uan-mac-rc.h:172
@ TYPE_CTS
CTS.
Definition: uan-mac-rc.h:171
@ TYPE_GWPING
Gateway ping.
Definition: uan-mac-rc.h:169
void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb) override
Set the callback to forward packets up to higher layers.
Definition: uan-mac-rc.cc:312
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
Definition: uan-mac-rc.cc:593
EventId m_startAgain
(Unused).
Definition: uan-mac-rc.h:215
void BlockRtsing()
Callback to block RST.
Definition: uan-mac-rc.cc:768
TracedCallback< Ptr< const Packet >, uint32_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
Definition: uan-mac-rc.h:248
uint32_t m_queueLimit
Maximum packets to queue at MAC.
Definition: uan-mac-rc.h:222
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
Definition: uan-mac-rc.cc:318
void RtsTimeout()
Retry RTS.
Definition: uan-mac-rc.cc:727
EventId m_rtsEvent
The RTS event.
Definition: uan-mac-rc.h:251
uint8_t m_frameNo
Current frame number.
Definition: uan-mac-rc.h:223
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition: uan-mac-rc.h:315
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Definition: uan-mac-rc.cc:268
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-rc.h:218
void DoDispose() override
Destructor implementation.
Definition: uan-mac-rc.cc:198
double m_minRetryRate
Smallest allowed RTS retry rate.
Definition: uan-mac-rc.h:227
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktQueue
Pending packets.
Definition: uan-mac-rc.h:236
double m_retryStep
Retry rate increment.
Definition: uan-mac-rc.h:228
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Definition: uan-mac-rc.h:230
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
The callback to forward a packet up to higher layer.
Definition: uan-mac-rc.h:241
UanMacRc()
Default constructor.
Definition: uan-mac-rc.cc:152
void AssociateTimeout()
Periodically retry association.
Definition: uan-mac-rc.cc:635
~UanMacRc() override
Dummy destructor, DoDispose.
Definition: uan-mac-rc.cc:170
void Associate()
Associate with a gateway by sending the first GWPING.
Definition: uan-mac-rc.cc:606
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
Definition: uan-mac-rc.h:312
bool IsPhy1Ok()
Check that PHY is ok: not CTS or ACK not to my address.
Definition: uan-mac-rc.cc:704
void SendRts()
Send RTS packet.
Definition: uan-mac-rc.cc:669
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Definition: uan-mac-rc.h:231
Time m_learnedProp
Propagation delay to gateway.
Definition: uan-mac-rc.h:225
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc.h:244
State m_state
MAC state.
Definition: uan-mac-rc.h:212
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
Definition: uan-mac-rc.h:220
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
Definition: uan-mac-rc.cc:539
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
Definition: uan-mac-rc.cc:276
bool m_rtsBlocked
RTS blocked while processing ACK.
Definition: uan-mac-rc.h:213
std::list< Reservation > m_resList
List of scheduled reservations.
Definition: uan-mac-rc.h:238
TracedCallback< Ptr< const Packet >, uint32_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-rc.h:246
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition: uan-mac-rc.h:224
Mac8Address m_assocAddr
Next hop address.
Definition: uan-mac-rc.h:217
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-rc.h:233
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
Definition: uan-mac-rc.h:221
State
MAC state.
Definition: uan-mac-rc.h:204
@ DATATX
(Unused).
Definition: uan-mac-rc.h:209
@ IDLE
Finished scheduling packet sends.
Definition: uan-mac-rc.h:207
@ RTSSENT
RTS just sent.
Definition: uan-mac-rc.h:208
@ GWPSENT
Associated with gateway.
Definition: uan-mac-rc.h:206
@ UNASSOCIATED
Initial state.
Definition: uan-mac-rc.h:205
uint32_t m_numRates
Number of rates per Phy layer.
Definition: uan-mac-rc.h:219
static TypeId GetTypeId()
Register this type.
Definition: uan-mac-rc.cc:205
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint32_t proto)
TracedCallback signature for dequeue of a packet.
Definition: uan-mac-rc.h:199
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:43
Every class exported by the ns3 library is enclosed in the ns3 namespace.
phy
Definition: third.py:89
#define list