A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
195 private:
197  enum State {
203  };
204 
207 
210  double m_retryRate;
213  uint32_t m_numRates;
214  uint32_t m_currentRate;
215  uint32_t m_maxFrames;
216  uint32_t m_queueLimit;
217  uint8_t m_frameNo;
220 
221  double m_minRetryRate;
222  double m_retryStep;
223 
224  uint32_t m_ctsSizeN;
225  uint32_t m_ctsSizeG;
226 
227  bool m_cleared;
228 
230  std::list<std::pair <Ptr<Packet>, UanAddress > > m_pktQueue;
232  std::list<Reservation> m_resList;
233 
236 
243 
253  void ReceiveOkFromPhy (Ptr<Packet> pkt, double sinr, UanTxMode mode);
255  void Associate (void);
257  void AssociateTimeout (void);
259  void SendRts (void);
261  void RtsTimeout (void);
276  void ScheduleData (const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes);
282  void ProcessAck (Ptr<Packet> ack);
289  void SendPacket (Ptr<Packet> pkt, uint32_t rate);
296  bool IsPhy1Ok (void);
298  void BlockRtsing (void);
299 
304  static uint32_t m_cntrlSends;
305 
308 
309 protected:
310  void DoDispose ();
311 
312 }; // class UanMacRc
313 
314 } // namespace ns3
315 
316 #endif /* UAN_MAC_RC_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
Cycle broadcast information.
Callback template class.
Definition: callback.h:924
void RtsTimeout(void)
Retry RTS.
Definition: uan-mac-rc.cc:732
EventId m_startAgain
(Unused).
Definition: uan-mac-rc.h:208
bool IsPhy1Ok(void)
Check that PHY is ok: not CTS or ACK not to my address.
Definition: uan-mac-rc.cc:709
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
Definition: uan-mac-rc.h:215
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: uan-mac-rc.cc:200
void AddTimestamp(Time t)
Set the time of the latest RTS sent.
Definition: uan-mac-rc.cc:134
State
MAC state.
Definition: uan-mac-rc.h:197
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
uint8_t m_frameNo
Frame number.
Definition: uan-mac-rc.h:138
virtual ~UanMacRc()
Dummy destructor, DoDispose.
Definition: uan-mac-rc.cc:171
uint8_t m_frameNo
Current frame number.
Definition: uan-mac-rc.h:217
Time m_learnedProp
Propagation delay to gateway.
Definition: uan-mac-rc.h:219
virtual Address GetAddress(void)
Get the MAC Address.
Definition: uan-mac-rc.cc:274
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
Definition: uan-mac-rc.cc:605
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
Definition: uan-mac-rc.cc:553
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:341
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:86
virtual Address GetBroadcast(void) const
Get the broadcast address.
Definition: uan-mac-rc.cc:335
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
Definition: uan-mac-rc.cc:86
void BlockRtsing(void)
Callback to block RST.
Definition: uan-mac-rc.cc:771
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
Definition: uan-mac-rc.cc:146
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
Definition: uan-mac-rc.h:242
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:47
Reservation()
Default constructor.
Definition: uan-mac-rc.cc:45
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:209
uint8_t GetRetryNo() const
Get the retry number.
Definition: uan-mac-rc.cc:110
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:322
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:176
double m_minRetryRate
Smallest allowed RTS retry rate.
Definition: uan-mac-rc.h:221
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
double m_retryStep
Retry rate increment.
Definition: uan-mac-rc.h:222
bool IsTransmitted() const
Definition: uan-mac-rc.cc:122
Finished scheduling packet sends.
Definition: uan-mac-rc.h:200
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc.h:238
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition: uan-mac-rc.h:307
std::list< std::pair< Ptr< Packet >, UanAddress > > m_pktQueue
Pending packets.
Definition: uan-mac-rc.h:230
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-rc.h:212
#define list
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
Definition: uan-mac-rc.h:304
void AssociateTimeout(void)
Periodically retry association.
Definition: uan-mac-rc.cc:644
void SetFrameNo(uint8_t fn)
Set the frame number.
Definition: uan-mac-rc.cc:128
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-rc.h:227
UanMacRc()
Default constructor.
Definition: uan-mac-rc.cc:153
static TypeId GetTypeId(void)
Register this type.
Definition: uan-mac-rc.cc:207
const std::list< std::pair< Ptr< Packet >, UanAddress > > & GetPktList(void) const
Get the list of packets.
Definition: uan-mac-rc.cc:98
Associated with gateway.
Definition: uan-mac-rc.h:199
EventId m_rtsEvent
The RTS event.
Definition: uan-mac-rc.h:245
State m_state
MAC state.
Definition: uan-mac-rc.h:205
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
Definition: uan-mac-rc.h:210
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:266
bool m_rtsBlocked
RTS blocked while processing ACK.
Definition: uan-mac-rc.h:206
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-rc.h:240
std::list< Reservation > m_resList
List of scheduled reservations.
Definition: uan-mac-rc.h:232
an identifier for simulation events.
Definition: event-id.h:46
virtual void SetAddress(UanAddress addr)
Set the address.
Definition: uan-mac-rc.cc:280
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition: uan-mac-rc.h:218
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-rc.cc:328
void SendRts(void)
Send RTS packet.
Definition: uan-mac-rc.cc:676
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
Definition: uan-mac-rc.cc:432
uint32_t GetLength() const
Get the total length of the Reservation.
Definition: uan-mac-rc.cc:92
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
Definition: uan-mac-rc.cc:521
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:104
uint32_t m_numRates
Number of rates per Phy layer.
Definition: uan-mac-rc.h:213
uint32_t m_queueLimit
Maximum packets to queue at MAC.
Definition: uan-mac-rc.h:216
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
Definition: uan-mac-rc.h:214
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:224
bool m_transmitted
Has this reservation been transmitted.
Definition: uan-mac-rc.h:144
a unique identifier for an interface.
Definition: type-id.h:49
void Associate(void)
Associate with a gateway by sending the first GWPING.
Definition: uan-mac-rc.cc:618
UanAddress m_assocAddr
Next hop address.
Definition: uan-mac-rc.h:211
void IncrementRetry()
Increment the retry count.
Definition: uan-mac-rc.cc:140
RTS just sent.
Definition: uan-mac-rc.h:201
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Definition: uan-mac-rc.h:225
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
The callback to forward a packet up to higher layer.
Definition: uan-mac-rc.h:235
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n'th RTS.
Definition: uan-mac-rc.cc:116
~Reservation()
Destructor.
Definition: uan-mac-rc.cc:75
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Enqueue packet to be transmitted.
Definition: uan-mac-rc.cc:286