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 "ns3/mac8-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>, Mac8Address > > &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>, Mac8Address > > &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>, 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 
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 bool Enqueue (Ptr<Packet> pkt, uint16_t protocolNumber, const Address &dest);
187  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb);
188  virtual void AttachPhy (Ptr<UanPhy> phy);
189  virtual void Clear (void);
190  int64_t AssignStreams (int64_t stream);
191 
198  typedef void (* QueueTracedCallback)
199  (Ptr<const Packet> packet, uint32_t proto);
200 
201 private:
203  enum State {
209  };
210 
213 
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 (void);
263  void AssociateTimeout (void);
265  void SendRts (void);
267  void RtsTimeout (void);
282  void ScheduleData (const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes);
288  void ProcessAck (Ptr<Packet> ack);
295  void SendPacket (Ptr<Packet> pkt, uint32_t rate);
302  bool IsPhy1Ok (void);
304  void BlockRtsing (void);
305 
310  static uint32_t m_cntrlSends;
311 
314 
315 protected:
316  void DoDispose ();
317 
318 }; // class UanMacRc
319 
320 } // namespace ns3
321 
322 #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
Mac8Address m_address
My addrese.s.
Definition: uan-mac-rc.h:215
void RtsTimeout(void)
Retry RTS.
Definition: uan-mac-rc.cc:720
EventId m_startAgain
(Unused).
Definition: uan-mac-rc.h:214
bool IsPhy1Ok(void)
Check that PHY is ok: not CTS or ACK not to my address.
Definition: uan-mac-rc.cc:697
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
Definition: uan-mac-rc.h:221
void DoDispose()
Destructor implementation.
Definition: uan-mac-rc.cc:202
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:199
State
MAC state.
Definition: uan-mac-rc.h:203
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:173
uint8_t m_frameNo
Current frame number.
Definition: uan-mac-rc.h:223
Time m_learnedProp
Propagation delay to gateway.
Definition: uan-mac-rc.h:225
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
Definition: uan-mac-rc.cc:87
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
Definition: uan-mac-rc.cc:593
bool IsTransmitted() const
Definition: uan-mac-rc.cc:123
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
Definition: uan-mac-rc.cc:541
uint8_t m_retryNo
Number of retries.
Definition: uan-mac-rc.h:142
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktQueue
Pending packets.
Definition: uan-mac-rc.h:236
uint32_t GetLength() const
Get the total length of the Reservation.
Definition: uan-mac-rc.cc:93
void ReceiveOkFromPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok Callback.
Definition: uan-mac-rc.cc:329
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
uint8_t GetFrameNo() const
Get the frame number.
Definition: uan-mac-rc.cc:105
phy
Definition: third.py:86
void BlockRtsing(void)
Callback to block RST.
Definition: uan-mac-rc.cc:759
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
Definition: uan-mac-rc.cc:147
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
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:49
Reservation()
Default constructor.
Definition: uan-mac-rc.cc:46
std::vector< Time > m_timestamp
Timestamps for each retry.
Definition: uan-mac-rc.h:140
TracedCallback< Ptr< const Packet >, uint32_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
Definition: uan-mac-rc.h:248
virtual void Clear(void)
Clears all pointer references.
Definition: uan-mac-rc.cc:178
double m_minRetryRate
Smallest allowed RTS retry rate.
Definition: uan-mac-rc.h:227
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktList
Queued packets for each address.
Definition: uan-mac-rc.h:134
double m_retryStep
Retry rate increment.
Definition: uan-mac-rc.h:228
A class used for addressing MAC8 MAC&#39;s.
Definition: mac8-address.h:42
const std::list< std::pair< Ptr< Packet >, Mac8Address > > & GetPktList(void) const
Get the list of packets.
Definition: uan-mac-rc.cc:99
Finished scheduling packet sends.
Definition: uan-mac-rc.h:206
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc.h:244
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition: uan-mac-rc.h:313
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-rc.h:218
#define list
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
Definition: uan-mac-rc.h:310
void AssociateTimeout(void)
Periodically retry association.
Definition: uan-mac-rc.cc:632
void SetFrameNo(uint8_t fn)
Set the frame number.
Definition: uan-mac-rc.cc:129
bool m_cleared
Flag when we&#39;ve been cleared.
Definition: uan-mac-rc.h:233
UanMacRc()
Default constructor.
Definition: uan-mac-rc.cc:155
static TypeId GetTypeId(void)
Register this type.
Definition: uan-mac-rc.cc:209
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest)
Enqueue packet to be transmitted.
Definition: uan-mac-rc.cc:280
Associated with gateway.
Definition: uan-mac-rc.h:205
EventId m_rtsEvent
The RTS event.
Definition: uan-mac-rc.h:251
State m_state
MAC state.
Definition: uan-mac-rc.h:211
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
Definition: uan-mac-rc.h:216
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:272
bool m_rtsBlocked
RTS blocked while processing ACK.
Definition: uan-mac-rc.h:212
TracedCallback< Ptr< const Packet >, uint32_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-rc.h:246
std::list< Reservation > m_resList
List of scheduled reservations.
Definition: uan-mac-rc.h:238
An identifier for simulation events.
Definition: event-id.h:53
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition: uan-mac-rc.h:224
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address &> cb)
Set the callback to forward packets up to higher layers.
Definition: uan-mac-rc.cc:316
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-rc.cc:322
void SendRts(void)
Send RTS packet.
Definition: uan-mac-rc.cc:664
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
Definition: uan-mac-rc.cc:420
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
Definition: uan-mac-rc.cc:509
Stores reservation info for use in scheduling data channel by reservation channel MAC...
Definition: uan-mac-rc.h:52
uint8_t GetRetryNo() const
Get the retry number.
Definition: uan-mac-rc.cc:111
uint32_t m_numRates
Number of rates per Phy layer.
Definition: uan-mac-rc.h:219
uint32_t m_queueLimit
Maximum packets to queue at MAC.
Definition: uan-mac-rc.h:222
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
Definition: uan-mac-rc.h:220
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Definition: uan-mac-rc.h:230
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n&#39;th RTS.
Definition: uan-mac-rc.cc:117
bool m_transmitted
Has this reservation been transmitted.
Definition: uan-mac-rc.h:144
Mac8Address m_assocAddr
Next hop address.
Definition: uan-mac-rc.h:217
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:606
void IncrementRetry()
Increment the retry count.
Definition: uan-mac-rc.cc:141
RTS just sent.
Definition: uan-mac-rc.h:207
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Definition: uan-mac-rc.h:231
~Reservation()
Destructor.
Definition: uan-mac-rc.cc:76