A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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
32namespace ns3
33{
34
35class UanTxMode;
36
37/**
38 * \ingroup uan
39 *
40 * Gateway side of RC-MAC.
41 *
42 * This MAC protocol assumes a network topology where all traffic
43 * is destined for a set of GW nodes which are connected via
44 * some out of band (RF?) means. UanMacRcGw is the protocol
45 * which runs on the gateway nodes.
46 *
47 * This particular implementation
48 * assumes that there is only a single gateway.
49 *
50 * For more information on class operation email
51 * lentracy@u.washington.edu
52 * (This work is, as of yet, unpublished)
53 */
54class UanMacRcGw : public UanMac
55{
56 public:
57 UanMacRcGw(); //!< Constructor
58 ~UanMacRcGw() override; //!< Dummy destructor, see DoDispose.
59
60 /**
61 * Register this type.
62 * \return The type ID.
63 */
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
73 /**
74 * TracedCallback signature for
75 *
76 * \param [in] now, The current simulation time.
77 * \param [in] delay Minimum path delay of first RTS.
78 * \param [in] numRts Number of pending RTS.
79 * \param [in] totalBytes Length of RTS header.
80 * \param [in] secs Effective window size for RcCtsGlobal message, or
81 * time to next cycle, both in seconds.
82 * \param [in] ctlRate CTL rate in Bps.
83 * \param [in] actualX Current retry rate.
84 */
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:
94 /** Gateway state. */
95 enum State
96 {
97 IDLE, //!< Initial idle state.
98 INCYCLE, //!< Cycling through nodes.
99 CTSING //!< Sending CTS.
100 };
101
102 State m_state; //!< Gateway processing state.
103
104 /**
105 * \ingroup uan
106 * Reservation request.
107 */
108 struct Request
109 {
110 uint8_t numFrames; //!< Number of frames.
111 uint8_t frameNo; //!< Current frame number.
112 uint8_t retryNo; //!< Retry number.
113 uint16_t length; //!< Request header length.
114 Time rxTime; //!< Time request received.
115 };
116
117 /**
118 * \ingroup uan
119 * Packet ACK data.
120 */
121 struct AckData
122 {
123 uint8_t frameNo; //!< Frame number being ACK'ed.
124 std::set<uint8_t> rxFrames; //!< Received frames.
125 uint8_t expFrames; //!< Expected number of frames.
126 };
127
128 /** Forwarding up callback. */
130
131 Ptr<UanPhy> m_phy; //!< PHY layer attached to this MAC.
132 Time m_maxDelta; //!< Maximum propagation delay between gateway and non-gateway nodes .
133 Time m_sifs; //!< Spacing between frames to account for timing error and processing delay.
134 uint32_t m_maxRes; //!< Maximum number of reservations to accept per cycle.
135 uint32_t m_numRates; //!< Number of rates per Phy layer.
136 uint32_t m_rtsSize; //!< Size of UanHeaderCommon and UanHeaderRcRts.
137 uint32_t m_ctsSizeN; //!< Size of UanHeaderRcCts.
138 uint32_t m_ctsSizeG; //!< Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
139 uint32_t m_ackSize; //!< Size of UanHeaderCommon and UanHeaderRcAck.
140 uint16_t m_currentRetryRate; //!< Retry rate number for current cycle.
141 uint32_t m_currentRateNum; //!< Rate number corresponding to data rate of current cycle.
142 uint32_t m_numNodes; //!< Number of non-gateway nodes in this gateway's neighborhood.
143 uint32_t m_totalRate; //!< Total available channel rate in bps (for a single channel, without
144 //!< splitting reservation channel).
145 uint32_t m_rateStep; //!< Increments available for rate assignment in bps.
146 uint32_t m_frameSize; //!< Size of data frames in bytes.
147
148 double m_minRetryRate; //!< Smallest allowed RTS retry rate.
149 double m_retryStep; //!< Retry rate increment.
150
151 /** Propagation delay to each node. */
152 std::map<Mac8Address, Time> m_propDelay;
153
154 /** AckData for each node. */
155 std::map<Mac8Address, AckData> m_ackData;
156
157 /** Request for each node. */
158 std::map<Mac8Address, Request> m_requests;
159 /** Queued request times. */
160 std::set<std::pair<Time, Mac8Address>> m_sortedRes;
161
162 /** Flag when we've been cleared. */
164
165 /** A packet was destined for and received at this MAC layer. */
167
168 /**
169 * A packet was destined for and received at this MAC layer.
170 *
171 * \pname{Start time}
172 * \pname{min propagation delay}
173 * \pname{reservations}
174 * \pname{frames}
175 * \pname{bytes}
176 * \pname{window size}
177 * \pname{CTS rate}
178 * \pname{retry rate}
179 */
181
182 /**
183 * PHY receive ok callback.
184 *
185 * \param pkt The Packet to receive
186 * \param sinr The SINR on the channel
187 * \param mode The transmission mode
188 */
189 void ReceivePacket(Ptr<Packet> pkt, double sinr, UanTxMode mode);
190
191 /** Cycle through pending requests. */
192 void StartCycle();
193 /** End cycle by scheduling pending ACKs. */
194 void EndCycle();
195 /**
196 * Send packet on PHY.
197 *
198 * \param pkt The Packet.
199 * \param rate The UanTxMode number, m_currentRateNum.
200 */
201 void SendPacket(Ptr<Packet> pkt, uint32_t rate);
202 /** Set state to INCYCLE. */
203 void CycleStarted();
204 /**
205 * PHY receive error callback.
206 *
207 * \param pkt The failed packet.
208 * \param sinr The SINR value on the channel.
209 */
210 void ReceiveError(Ptr<Packet> pkt, double sinr);
211
212 // Stuff for computing exp throughput
213 /**
214 * Compute alpha parameter.
215 *
216 * \param totalFrames Total number of frames in m_requests.
217 * \param totalBytes Total number of bytes in m_requests.
218 * \param n Number of nodes.
219 * \param a m_maxRes, or optimal A value.
220 * \param deltaK Propagation delay.
221 * \return Alpha parameter.
222 */
223 double ComputeAlpha(uint32_t totalFrames,
224 uint32_t totalBytes,
225 uint32_t n,
226 uint32_t a,
227 double deltaK);
228 /**
229 * Get the expected propagation delay to each node.
230 *
231 * \return Vector of expected propagation delays.
232 */
233 std::vector<double> GetExpPdk();
234 /**
235 * Throughput for \pname{a} reservations with framesize \pname{ld},
236 * given expected delays exppdk.
237 *
238 * \param a Number of reservations.
239 * \param ld Frame size.
240 * \param exppdk Expected delays, given by GetExpPdk.
241 * \return Expected throughput.
242 */
243 double ComputeExpS(uint32_t a, uint32_t ld, std::vector<double> exppdk);
244 /**
245 * Throughput for \pname{a} reservations with framesize \pname{ld}.
246 *
247 * \param a Number of reservations.
248 * \param ld Frame size.
249 * \return Expected throughput.
250 */
251 double ComputeExpS(uint32_t a, uint32_t ld);
252 /**
253 * Index to the k'th expected delay among n nodes.
254 *
255 * \param n Number of nodes.
256 * \param k Target index.
257 * \return The expected index.
258 */
260 /**
261 * Numeric function.
262 *
263 * \param a Number of reservations.
264 * \param n number of nodes.
265 * \param k K'th node.
266 * \return Value.
267 */
268 double ComputePiK(uint32_t a, uint32_t n, uint32_t k);
269 /**
270 * Numeric function.
271 *
272 * \param n Number of nodes.
273 * \param a Number of reservations.
274 * \param ldlh Sum of common header length and frame size.
275 * \param deltaK Result of GetExpPdk
276 * \return value.
277 */
278 double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector<double> deltaK);
279 /**
280 * Binomial coefficient.
281 *
282 * \param n Pool size.
283 * \param k Selection size.
284 * \return Binomial coefficient n choose k.
285 */
286 uint64_t NchooseK(uint32_t n, uint32_t k);
287 /**
288 * Compute the optimum maximum number of reservations to accept per cycle.
289 *
290 * \return Optimum number.
291 */
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
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
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.
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.