A Discrete-Event Network Simulator
API
uan-mac-rc-gw.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_GW_H
21 #define UAN_MAC_RC_GW_H
22 
23 #include "uan-mac.h"
24 
25 #include "ns3/mac8-address.h"
26 #include "ns3/nstime.h"
27 #include "ns3/traced-callback.h"
28 
29 #include <map>
30 #include <set>
31 
32 namespace ns3
33 {
34 
35 class UanTxMode;
36 
54 class UanMacRcGw : public UanMac
55 {
56  public:
57  UanMacRcGw();
58  ~UanMacRcGw() override;
59 
64  static TypeId GetTypeId();
65 
66  // Inherited methods
67  bool Enqueue(Ptr<Packet> pkt, uint16_t protocolNumber, const Address& dest) override;
68  void SetForwardUpCb(Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb) override;
69  void AttachPhy(Ptr<UanPhy> phy) override;
70  void Clear() override;
71  int64_t AssignStreams(int64_t stream) override;
72 
85  typedef void (*CycleCallback)(Time now,
86  Time delay,
87  uint32_t numRts,
88  uint32_t totalBytes,
89  double secs,
90  uint32_t ctlRate,
91  double actualX);
92 
93  private:
95  enum State
96  {
97  IDLE,
99  CTSING
100  };
101 
103 
108  struct Request
109  {
110  uint8_t numFrames;
111  uint8_t frameNo;
112  uint8_t retryNo;
113  uint16_t length;
115  };
116 
121  struct AckData
122  {
123  uint8_t frameNo;
124  std::set<uint8_t> rxFrames;
125  uint8_t expFrames;
126  };
127 
130 
134  uint32_t m_maxRes;
135  uint32_t m_numRates;
136  uint32_t m_rtsSize;
137  uint32_t m_ctsSizeN;
138  uint32_t m_ctsSizeG;
139  uint32_t m_ackSize;
141  uint32_t m_currentRateNum;
142  uint32_t m_numNodes;
143  uint32_t m_totalRate;
145  uint32_t m_rateStep;
146  uint32_t m_frameSize;
147 
148  double m_minRetryRate;
149  double m_retryStep;
150 
152  std::map<Mac8Address, Time> m_propDelay;
153 
155  std::map<Mac8Address, AckData> m_ackData;
156 
158  std::map<Mac8Address, Request> m_requests;
160  std::set<std::pair<Time, Mac8Address>> m_sortedRes;
161 
163  bool m_cleared;
164 
167 
181 
189  void ReceivePacket(Ptr<Packet> pkt, double sinr, UanTxMode mode);
190 
192  void StartCycle();
194  void EndCycle();
201  void SendPacket(Ptr<Packet> pkt, uint32_t rate);
203  void CycleStarted();
210  void ReceiveError(Ptr<Packet> pkt, double sinr);
211 
212  // Stuff for computing exp throughput
223  double ComputeAlpha(uint32_t totalFrames,
224  uint32_t totalBytes,
225  uint32_t n,
226  uint32_t a,
227  double deltaK);
233  std::vector<double> GetExpPdk();
243  double ComputeExpS(uint32_t a, uint32_t ld, std::vector<double> exppdk);
251  double ComputeExpS(uint32_t a, uint32_t ld);
259  uint32_t CompExpMinIndex(uint32_t n, uint32_t k);
268  double ComputePiK(uint32_t a, uint32_t n, uint32_t k);
278  double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector<double> deltaK);
286  uint64_t NchooseK(uint32_t n, uint32_t k);
292  uint32_t FindOptA();
293 
294  protected:
295  void DoDispose() override;
296 
297 }; // class UanMacRcGw
298 
299 } // namespace ns3
300 
301 #endif /* UAN_MAC_RC_GW_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:44
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
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:46
Gateway side of RC-MAC.
Definition: uan-mac-rc-gw.h:55
uint32_t m_numNodes
Number of non-gateway nodes in this gateway's neighborhood.
void ReceiveError(Ptr< Packet > pkt, double sinr)
PHY receive error callback.
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send packet on PHY.
uint32_t m_maxRes
Maximum number of reservations to accept per cycle.
double ComputeAlpha(uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
Compute alpha parameter.
double m_minRetryRate
Smallest allowed RTS retry rate.
void Clear() override
Clears all pointer references.
uint16_t m_currentRetryRate
Retry rate number for current cycle.
~UanMacRcGw() override
Dummy destructor, see DoDispose.
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
UanMacRcGw()
Constructor.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
void EndCycle()
End cycle by scheduling pending ACKs.
uint32_t m_rateStep
Increments available for rate assignment in bps.
uint32_t FindOptA()
Compute the optimum maximum number of reservations to accept per cycle.
std::map< Mac8Address, AckData > m_ackData
AckData for each node.
void(* CycleCallback)(Time now, Time delay, uint32_t numRts, uint32_t totalBytes, double secs, uint32_t ctlRate, double actualX)
TracedCallback signature for.
Definition: uan-mac-rc-gw.h:85
void StartCycle()
Cycle through pending requests.
TracedCallback< Time, Time, uint32_t, uint32_t, double, uint32_t, double > m_cycleLogger
A packet was destined for and received at this MAC layer.
std::set< std::pair< Time, Mac8Address > > m_sortedRes
Queued request times.
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
Time m_maxDelta
Maximum propagation delay between gateway and non-gateway nodes .
double ComputeExpS(uint32_t a, uint32_t ld, std::vector< double > exppdk)
Throughput for a reservations with framesize ld, given expected delays exppdk.
Time m_sifs
Spacing between frames to account for timing error and processing delay.
void DoDispose() override
Destructor implementation.
static TypeId GetTypeId()
Register this type.
bool m_cleared
Flag when we've been cleared.
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
State
Gateway state.
Definition: uan-mac-rc-gw.h:96
@ CTSING
Sending CTS.
Definition: uan-mac-rc-gw.h:99
@ INCYCLE
Cycling through nodes.
Definition: uan-mac-rc-gw.h:98
@ IDLE
Initial idle state.
Definition: uan-mac-rc-gw.h:97
uint32_t m_frameSize
Size of data frames in bytes.
uint64_t NchooseK(uint32_t n, uint32_t k)
Binomial coefficient.
uint32_t m_numRates
Number of rates per Phy layer.
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void CycleStarted()
Set state to INCYCLE.
void ReceivePacket(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok callback.
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
uint32_t m_currentRateNum
Rate number corresponding to data rate of current cycle.
double ComputePiK(uint32_t a, uint32_t n, uint32_t k)
Numeric function.
std::vector< double > GetExpPdk()
Get the expected propagation delay to each node.
uint32_t m_totalRate
Total available channel rate in bps (for a single channel, without splitting reservation channel).
uint32_t m_rtsSize
Size of UanHeaderCommon and UanHeaderRcRts.
State m_state
Gateway processing state.
std::map< Mac8Address, Request > m_requests
Request for each node.
double m_retryStep
Retry rate increment.
double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector< double > deltaK)
Numeric function.
std::map< Mac8Address, Time > m_propDelay
Propagation delay to each node.
void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb) override
Set the callback to forward packets up to higher layers.
uint32_t m_ackSize
Size of UanHeaderCommon and UanHeaderRcAck.
uint32_t CompExpMinIndex(uint32_t n, uint32_t k)
Index to the k'th expected delay among n nodes.
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
uint8_t expFrames
Expected number of frames.
uint8_t frameNo
Frame number being ACK'ed.
std::set< uint8_t > rxFrames
Received frames.
Reservation request.
uint8_t retryNo
Retry number.
uint16_t length
Request header length.
uint8_t frameNo
Current frame number.
uint8_t numFrames
Number of frames.
Time rxTime
Time request received.