A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
uan-mac-rc.h
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:
58  Reservation ();
65  Reservation (std::list<std::pair <Ptr<Packet>, UanAddress > > &list, uint8_t frameNo, uint32_t maxPkts = 0);
66  ~Reservation ();
70  uint32_t GetNoFrames () const;
74  uint32_t GetLength () const;
78  const std::list<std::pair <Ptr<Packet>, UanAddress > > &GetPktList (void) const;
82  uint8_t GetFrameNo () const;
86  uint8_t GetRetryNo () const;
91  Time GetTimestamp (uint8_t n) const;
95  bool IsTransmitted () const;
99  void SetFrameNo (uint8_t fn);
103  void AddTimestamp (Time t);
107  void IncrementRetry ();
112  void SetTransmitted (bool t = true);
113 private:
114  std::list<std::pair <Ptr<Packet>, UanAddress > > m_pktList;
115  uint32_t m_length;
116  uint8_t m_frameNo;
117  std::vector<Time> m_timestamp;
118  uint8_t m_retryNo;
119  bool m_transmitted;
120 
121 };
122 
123 
137 class UanMacRc : public UanMac
138 {
139 public:
140  enum {
141  TYPE_DATA, TYPE_GWPING, TYPE_RTS, TYPE_CTS, TYPE_ACK
142  };
143  UanMacRc ();
144  virtual ~UanMacRc ();
145 
146  static TypeId GetTypeId (void);
147 
148  // Inherited virtual functions
149  virtual Address GetAddress (void);
150  virtual void SetAddress (UanAddress addr);
151  virtual bool Enqueue (Ptr<Packet> pkt, const Address &dest, uint16_t protocolNumber);
152  virtual void SetForwardUpCb (Callback<void, Ptr<Packet>, const UanAddress&> cb);
153  virtual void AttachPhy (Ptr<UanPhy> phy);
154  virtual Address GetBroadcast (void) const;
155  virtual void Clear (void);
156 
165  int64_t AssignStreams (int64_t stream);
166 
167 private:
168  enum State {
169  UNASSOCIATED, GWPSENT, IDLE, RTSSENT, DATATX
170  };
171 
172  State m_state;
173  bool m_rtsBlocked;
174 
175  EventId m_startAgain;
176  UanAddress m_address;
177  double m_retryRate;
178  UanAddress m_assocAddr;
179  Ptr<UanPhy> m_phy;
180  uint32_t m_numRates;
181  uint32_t m_currentRate;
182  uint32_t m_maxFrames;
183  uint32_t m_queueLimit;
184  uint8_t m_frameNo;
185  Time m_sifs;
186  Time m_learnedProp;
187 
188  uint16_t m_numRetryRates;
189  double m_minRetryRate;
190  double m_retryStep;
191 
192  uint32_t m_ctsSizeN;
193  uint32_t m_ctsSizeG;
194 
195  bool m_cleared;
196 
197  std::list<std::pair <Ptr<Packet>, UanAddress > > m_pktQueue;
198  std::list<Reservation> m_resList;
199 
200  Callback<void, Ptr<Packet>, const UanAddress& > m_forwardUpCb;
201 
203  TracedCallback<Ptr<const Packet>, uint16_t > m_enqueueLogger;
204  TracedCallback<Ptr<const Packet>, uint16_t > m_dequeueLogger;
205 
206  EventId m_rtsEvent;
207  void ReceiveOkFromPhy (Ptr<Packet>, double sinr, UanTxMode mode);
208 
209  void Associate (void);
210  void AssociateTimeout (void);
211  void SendRts (void);
212  void RtsTimeout (void);
213  UanHeaderRcRts CreateRtsHeader (const Reservation &res);
214  void ScheduleData (const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes);
215  void ProcessAck (Ptr<Packet> ack);
216  void SendPacket (Ptr<Packet> pkt, uint32_t rate);
217  bool IsPhy1Ok (void);
218  void BlockRtsing (void);
219 
220  static uint32_t m_cntrlSends;
221 
224 
225 protected:
226  void DoDispose ();
227 };
228 
229 }
230 
231 #endif /* UAN_MAC_RC_H */
keep track of time unit.
Definition: nstime.h:149
Cycle broadcast information for.
Callback template class.
Definition: callback.h:369
void DoDispose()
Definition: uan-mac-rc.cc:200
void AddTimestamp(Time t)
Definition: uan-mac-rc.cc:134
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
virtual Address GetAddress(void)
Definition: uan-mac-rc.cc:279
Non-gateway node MAC for reservation channel MAC protocol.
Definition: uan-mac-rc.h:137
a polymophic address class
Definition: address.h:86
virtual Address GetBroadcast(void) const
Definition: uan-mac-rc.cc:340
uint32_t GetNoFrames() const
Definition: uan-mac-rc.cc:86
void SetTransmitted(bool t=true)
Sets reservation transmitted state.
Definition: uan-mac-rc.cc:146
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:47
Reservation()
Create empty object with default values.
Definition: uan-mac-rc.cc:45
uint8_t GetRetryNo() const
Definition: uan-mac-rc.cc:110
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Definition: uan-mac-rc.cc:327
virtual void Clear(void)
Definition: uan-mac-rc.cc:176
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:36
bool IsTransmitted() const
Definition: uan-mac-rc.cc:122
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition: uan-mac-rc.h:223
void SetFrameNo(uint8_t fn)
Definition: uan-mac-rc.cc:128
const std::list< std::pair< Ptr< Packet >, UanAddress > > & GetPktList(void) const
Definition: uan-mac-rc.cc:98
int64_t AssignStreams(int64_t stream)
Definition: uan-mac-rc.cc:271
an identifier for simulation events.
Definition: event-id.h:46
virtual void SetAddress(UanAddress addr)
Definition: uan-mac-rc.cc:285
virtual void AttachPhy(Ptr< UanPhy > phy)
Definition: uan-mac-rc.cc:333
uint32_t GetLength() const
Definition: uan-mac-rc.cc:92
Stores reservation info for use in scheduling data channel by reservation channel MAC...
Definition: uan-mac-rc.h:52
uint8_t GetFrameNo() const
Definition: uan-mac-rc.cc:104
a unique identifier for an interface.
Definition: type-id.h:44
void IncrementRetry()
Increments retry count by 1.
Definition: uan-mac-rc.cc:140
Time GetTimestamp(uint8_t n) const
Definition: uan-mac-rc.cc:116
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Definition: uan-mac-rc.cc:291