A Discrete-Event Network Simulator
API
uan-mac-rc.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Leonard Tracy <lentracy@gmail.com>
19  */
20 
21 #ifndef UAN_MAC_RC_H
22 #define UAN_MAC_RC_H
23 
24 #include "uan-mac.h"
25 #include "uan-address.h"
26 
27 #include "ns3/nstime.h"
28 #include "ns3/trace-source-accessor.h"
29 #include "ns3/traced-callback.h"
30 #include "ns3/event-id.h"
31 #include "ns3/random-variable-stream.h"
32 
33 #include <list>
34 #include <utility>
35 #include <vector>
36 
37 
38 namespace ns3 {
39 
40 class Address;
41 class UanTxMode;
42 class UanHeaderRcRts;
43 class UanHeaderRcCts;
44 class UanHeaderRcCtsGlobal;
45 class UanPhy;
46 
47 
53 {
54 public:
56  Reservation ();
66  Reservation (std::list<std::pair <Ptr<Packet>, UanAddress > > &list, uint8_t frameNo, uint32_t maxPkts = 0);
68  ~Reservation ();
74  uint32_t GetNoFrames () const;
82  uint32_t GetLength () const;
88  const std::list<std::pair <Ptr<Packet>, UanAddress > > &GetPktList (void) 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>, UanAddress > > 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 
148 
163 class UanMacRc : public UanMac
164 {
165 public:
167  enum {
173  };
175  UanMacRc ();
177  virtual ~UanMacRc ();
178 
183  static TypeId GetTypeId (void);
184 
185  // Inherited methods
186  virtual Address GetAddress (void);
187  virtual void SetAddress (UanAddress addr);
188  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber);
189  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb);
190  virtual void AttachPhy (Ptr<UanPhy> phy);
191  virtual Address GetBroadcast (void) const;
192  virtual void Clear (void);
193  int64_t AssignStreams (int64_t stream);
194 
201  typedef void (* QueueTracedCallback)
202  (Ptr<const Packet> packet, uint32_t proto);
203 
204 private:
206  enum State {
212  };
213 
216 
219  double m_retryRate;
222  uint32_t m_numRates;
223  uint32_t m_currentRate;
224  uint32_t m_maxFrames;
225  uint32_t m_queueLimit;
226  uint8_t m_frameNo;
229 
230  double m_minRetryRate;
231  double m_retryStep;
232 
233  uint32_t m_ctsSizeN;
234  uint32_t m_ctsSizeG;
235 
236  bool m_cleared;
237 
239  std::list<std::pair <Ptr<Packet>, UanAddress > > m_pktQueue;
241  std::list<Reservation> m_resList;
242 
245 
252 
262  void ReceiveOkFromPhy (Ptr<Packet> pkt, double sinr, UanTxMode mode);
264  void Associate (void);
266  void AssociateTimeout (void);
268  void SendRts (void);
270  void RtsTimeout (void);
285  void ScheduleData (const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes);
291  void ProcessAck (Ptr<Packet> ack);
298  void SendPacket (Ptr<Packet> pkt, uint32_t rate);
305  bool IsPhy1Ok (void);
307  void BlockRtsing (void);
308 
313  static uint32_t m_cntrlSends;
314 
317 
318 protected:
319  void DoDispose ();
320 
321 }; // class UanMacRc
322 
323 } // namespace ns3
324 
325 #endif /* UAN_MAC_RC_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Cycle broadcast information.
Callback template class.
Definition: callback.h:1176
void RtsTimeout(void)
Retry RTS.
Definition: uan-mac-rc.cc:737
EventId m_startAgain
(Unused).
Definition: uan-mac-rc.h:217
bool IsPhy1Ok(void)
Check that PHY is ok: not CTS or ACK not to my address.
Definition: uan-mac-rc.cc:714
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
Definition: uan-mac-rc.h:224
Associated with gateway.
Definition: uan-mac-rc.h:208
void DoDispose()
Destructor implementation.
Definition: uan-mac-rc.cc:201
void AddTimestamp(Time t)
Set the time of the latest RTS sent.
Definition: uan-mac-rc.cc:135
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint32_t proto)
TracedCallback signature for dequeue of a packet.
Definition: uan-mac-rc.h:202
Forward calls to a chain of Callback.
uint8_t m_frameNo
Frame number.
Definition: uan-mac-rc.h:138
virtual ~UanMacRc()
Dummy destructor, DoDispose.
Definition: uan-mac-rc.cc:172
uint8_t m_frameNo
Current frame number.
Definition: uan-mac-rc.h:226
Time m_learnedProp
Propagation delay to gateway.
Definition: uan-mac-rc.h:228
virtual Address GetAddress(void)
Get the MAC Address.
Definition: uan-mac-rc.cc:279
Finished scheduling packet sends.
Definition: uan-mac-rc.h:209
State
MAC state.
Definition: uan-mac-rc.h:206
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
Definition: uan-mac-rc.cc:610
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
Definition: uan-mac-rc.cc:558
RTS just sent.
Definition: uan-mac-rc.h:210
uint8_t m_retryNo
Number of retries.
Definition: uan-mac-rc.h:142
void ReceiveOkFromPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok Callback.
Definition: uan-mac-rc.cc:346
Non-gateway node MAC for reservation channel MAC protocol.
Definition: uan-mac-rc.h:163
uint32_t m_length
Total length of queued packets.
Definition: uan-mac-rc.h:136
a polymophic address class
Definition: address.h:90
virtual Address GetBroadcast(void) const
Get the broadcast address.
Definition: uan-mac-rc.cc:340
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
Definition: uan-mac-rc.cc:87
void BlockRtsing(void)
Callback to block RST.
Definition: uan-mac-rc.cc:776
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
Definition: uan-mac-rc.cc:147
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:48
tuple phy
Definition: third.py:86
Reservation()
Default constructor.
Definition: uan-mac-rc.cc:46
std::vector< Time > m_timestamp
Timestamps for each retry.
Definition: uan-mac-rc.h:140
UanAddress m_address
My addrese.s.
Definition: uan-mac-rc.h:218
uint8_t GetRetryNo() const
Get the retry number.
Definition: uan-mac-rc.cc:111
TracedCallback< Ptr< const Packet >, uint32_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
Definition: uan-mac-rc.h:251
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Set the callback to forward packets up to higher layers.
Definition: uan-mac-rc.cc:327
A class used for addressing UAN MAC's.
Definition: uan-address.h:40
virtual void Clear(void)
Clears all pointer references.
Definition: uan-mac-rc.cc:177
double m_minRetryRate
Smallest allowed RTS retry rate.
Definition: uan-mac-rc.h:230
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
double m_retryStep
Retry rate increment.
Definition: uan-mac-rc.h:231
bool IsTransmitted() const
Definition: uan-mac-rc.cc:123
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc.h:247
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition: uan-mac-rc.h:316
std::list< std::pair< Ptr< Packet >, UanAddress > > m_pktQueue
Pending packets.
Definition: uan-mac-rc.h:239
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-rc.h:221
#define list
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
Definition: uan-mac-rc.h:313
void AssociateTimeout(void)
Periodically retry association.
Definition: uan-mac-rc.cc:649
void SetFrameNo(uint8_t fn)
Set the frame number.
Definition: uan-mac-rc.cc:129
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-rc.h:236
UanMacRc()
Default constructor.
Definition: uan-mac-rc.cc:154
static TypeId GetTypeId(void)
Register this type.
Definition: uan-mac-rc.cc:208
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const std::list< std::pair< Ptr< Packet >, UanAddress > > & GetPktList(void) const
Get the list of packets.
Definition: uan-mac-rc.cc:99
EventId m_rtsEvent
The RTS event.
Definition: uan-mac-rc.h:254
State m_state
MAC state.
Definition: uan-mac-rc.h:214
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
Definition: uan-mac-rc.h:219
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: uan-mac-rc.cc:271
bool m_rtsBlocked
RTS blocked while processing ACK.
Definition: uan-mac-rc.h:215
TracedCallback< Ptr< const Packet >, uint32_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-rc.h:249
std::list< Reservation > m_resList
List of scheduled reservations.
Definition: uan-mac-rc.h:241
An identifier for simulation events.
Definition: event-id.h:53
virtual void SetAddress(UanAddress addr)
Set the address.
Definition: uan-mac-rc.cc:285
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition: uan-mac-rc.h:227
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-rc.cc:333
void SendRts(void)
Send RTS packet.
Definition: uan-mac-rc.cc:681
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
Definition: uan-mac-rc.cc:437
uint32_t GetLength() const
Get the total length of the Reservation.
Definition: uan-mac-rc.cc:93
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
Definition: uan-mac-rc.cc:526
Stores reservation info for use in scheduling data channel by reservation channel MAC...
Definition: uan-mac-rc.h:52
uint8_t GetFrameNo() const
Get the frame number.
Definition: uan-mac-rc.cc:105
uint32_t m_numRates
Number of rates per Phy layer.
Definition: uan-mac-rc.h:222
uint32_t m_queueLimit
Maximum packets to queue at MAC.
Definition: uan-mac-rc.h:225
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
Definition: uan-mac-rc.h:223
std::list< std::pair< Ptr< Packet >, UanAddress > > m_pktList
Queued packets for each address.
Definition: uan-mac-rc.h:134
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Definition: uan-mac-rc.h:233
bool m_transmitted
Has this reservation been transmitted.
Definition: uan-mac-rc.h:144
a unique identifier for an interface.
Definition: type-id.h:58
void Associate(void)
Associate with a gateway by sending the first GWPING.
Definition: uan-mac-rc.cc:623
UanAddress m_assocAddr
Next hop address.
Definition: uan-mac-rc.h:220
void IncrementRetry()
Increment the retry count.
Definition: uan-mac-rc.cc:141
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Definition: uan-mac-rc.h:234
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
The callback to forward a packet up to higher layer.
Definition: uan-mac-rc.h:244
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n'th RTS.
Definition: uan-mac-rc.cc:117
~Reservation()
Destructor.
Definition: uan-mac-rc.cc:76
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Enqueue packet to be transmitted.
Definition: uan-mac-rc.cc:291