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