A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-mac-rc.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_H
21#define UAN_MAC_RC_H
22
23#include "uan-mac.h"
24
25#include "ns3/event-id.h"
26#include "ns3/mac8-address.h"
27#include "ns3/nstime.h"
28#include "ns3/random-variable-stream.h"
29#include "ns3/trace-source-accessor.h"
30#include "ns3/traced-callback.h"
31
32#include <list>
33#include <utility>
34#include <vector>
35
36namespace ns3
37{
38
39class Address;
40class UanTxMode;
41class UanHeaderRcRts;
42class UanHeaderRcCts;
43class UanHeaderRcCtsGlobal;
44class UanPhy;
45
46/**
47 * Stores reservation info for use in scheduling data channel
48 * by reservation channel MAC.
49 */
51{
52 public:
53 /** Default constructor. */
55 /**
56 * Create Reservation object with given packet list,
57 * frame number and max packets.
58 *
59 * \param list List of packets for assigned to reservation.
60 * \param frameNo Frame number of reservation transmission.
61 * \param maxPkts Maximum number of packets to assign to reservation
62 * from packet list (0 = no maximum).
63 */
64 Reservation(std::list<std::pair<Ptr<Packet>, Mac8Address>>& list,
65 uint8_t frameNo,
66 uint32_t maxPkts = 0);
67 /** Destructor */
69 /**
70 * Get the number of frames in this Reservation.
71 *
72 * \return Number of frames.
73 */
74 uint32_t GetNoFrames() const;
75 /**
76 * Get the total length of the Reservation.
77 *
78 * This is the sum of packets with headers.
79 *
80 * \return Total length, in bytes.
81 */
82 uint32_t GetLength() const;
83 /**
84 * Get the list of packets.
85 *
86 * \return The list of packets.
87 */
88 const std::list<std::pair<Ptr<Packet>, Mac8Address>>& GetPktList() const;
89 /**
90 * Get the frame number.
91 *
92 * \return The frame number.
93 */
94 uint8_t GetFrameNo() const;
95 /**
96 * Get the retry number.
97 *
98 * \return The retry number.
99 */
100 uint8_t GetRetryNo() const;
101 /**
102 * Get the timestamp for the n'th RTS.
103 *
104 * \param n Which retry number.
105 * \return N'th timestamp.
106 */
107 Time GetTimestamp(uint8_t n) const;
108
109 /** \return True if reservation packets have been transmitted. */
110 bool IsTransmitted() const;
111 /**
112 * Set the frame number.
113 *
114 * \param fn The frame number.
115 */
116 void SetFrameNo(uint8_t fn);
117 /**
118 * Set the time of the latest RTS sent.
119 *
120 * \param t RTS timestamp.
121 */
122 void AddTimestamp(Time t);
123 /** Increment the retry count. */
124 void IncrementRetry();
125 /**
126 * Set the reservation transmitted state.
127 *
128 * \param t True if reservation has been transmitted.
129 */
130 void SetTransmitted(bool t = true);
131
132 private:
133 /** Queued packets for each address. */
134 std::list<std::pair<Ptr<Packet>, Mac8Address>> m_pktList;
135 /** Total length of queued packets. */
137 /** Frame number. */
138 uint8_t m_frameNo;
139 /** Timestamps for each retry. */
140 std::vector<Time> m_timestamp;
141 /** Number of retries. */
142 uint8_t m_retryNo;
143 /** Has this reservation been transmitted. */
145
146}; // class Reservation
147
148/**
149 * \ingroup uan
150 *
151 * Non-gateway node MAC for reservation channel MAC protocol.
152 *
153 * This MAC protocol assumes a network topology where all traffic
154 * is destined for a set of GW nodes which are connected via
155 * some out of band (RF?) means. This particular implementation
156 * assumes that there is only a single gateway.
157 *
158 * For more information on class operation email
159 * lentracy@u.washington.edu
160 * (This work is, as of yet, unpublished)
161 */
162class UanMacRc : public UanMac
163{
164 public:
165 /** Packet types. */
166 enum
167 {
168 TYPE_DATA, //!< Data.
169 TYPE_GWPING, //!< Gateway ping.
170 TYPE_RTS, //!< RTS.
171 TYPE_CTS, //!< CTS.
172 TYPE_ACK //!< ACK.
173 };
174
175 /** Default constructor */
176 UanMacRc();
177 /** Dummy destructor, DoDispose. */
178 ~UanMacRc() override;
179
180 /**
181 * Register this type.
182 * \return The TypeId.
183 */
184 static TypeId GetTypeId();
185
186 // Inherited methods
187 bool Enqueue(Ptr<Packet> pkt, uint16_t protocolNumber, const Address& dest) override;
188 void SetForwardUpCb(Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb) override;
189 void AttachPhy(Ptr<UanPhy> phy) override;
190 void Clear() override;
191 int64_t AssignStreams(int64_t stream) override;
192
193 /**
194 * TracedCallback signature for dequeue of a packet.
195 *
196 * \param [in] packet The Packet being received.
197 * \param [in] proto The protocol number.
198 */
199 typedef void (*QueueTracedCallback)(Ptr<const Packet> packet, uint32_t proto);
200
201 private:
202 /** MAC state. */
203 enum State
204 {
205 UNASSOCIATED, //!< Initial state.
206 GWPSENT, //!< Associated with gateway.
207 IDLE, //!< Finished scheduling packet sends.
208 RTSSENT, //!< RTS just sent.
209 DATATX //!< (Unused).
210 };
211
212 State m_state; //!< MAC state.
213 bool m_rtsBlocked; //!< RTS blocked while processing ACK.
214
215 EventId m_startAgain; //!< (Unused).
216 double m_retryRate; //!< Number of retry attempts per second (of RTS/GWPING.
217 Mac8Address m_assocAddr; //!< Next hop address.
218 Ptr<UanPhy> m_phy; //!< PHY layer attached to this MAC.
219 uint32_t m_numRates; //!< Number of rates per Phy layer.
220 uint32_t m_currentRate; //!< Rate number corresponding to data rate of current cycle.
221 uint32_t m_maxFrames; //!< Maximum number of frames to include in a single RTS.
222 uint32_t m_queueLimit; //!< Maximum packets to queue at MAC.
223 uint8_t m_frameNo; //!< Current frame number.
224 Time m_sifs; //!< Spacing between frames to account for timing error and processing delay.
225 Time m_learnedProp; //!< Propagation delay to gateway.
226
227 double m_minRetryRate; //!< Smallest allowed RTS retry rate.
228 double m_retryStep; //!< Retry rate increment.
229
230 uint32_t m_ctsSizeN; //!< Size of UanHeaderRcCts.
231 uint32_t m_ctsSizeG; //!< Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
232
233 bool m_cleared; //!< Flag when we've been cleared.
234
235 /** Pending packets. */
236 std::list<std::pair<Ptr<Packet>, Mac8Address>> m_pktQueue;
237 /** List of scheduled reservations. */
238 std::list<Reservation> m_resList;
239
240 /** The callback to forward a packet up to higher layer. */
242
243 /** A packet was destined for and received at this MAC layer. */
245 /** A packet arrived at the MAC for transmission. */
247 /** A was passed down to the PHY from the MAC. */
249
250 /** The RTS event. */
252 /**
253 * PHY receive ok Callback.
254 *
255 * \param pkt The received packet.
256 * \param sinr (Unused).
257 * \param mode Modulation mode.
258 */
259 void ReceiveOkFromPhy(Ptr<Packet> pkt, double sinr, UanTxMode mode);
260 /** Associate with a gateway by sending the first GWPING. */
261 void Associate();
262 /** Periodically retry association. */
263 void AssociateTimeout();
264 /** Send RTS packet. */
265 void SendRts();
266 /** Retry RTS. */
267 void RtsTimeout();
268 /**
269 * Create the RTS header from a Reservation.
270 *
271 * \param res The Reservation.
272 * \return A RTS header.
273 */
275 /**
276 * Schedule Packet sends.
277 *
278 * \param ctsh The CTS header identifying the frame number and delay.
279 * \param ctsg The CTS global header giving the transmit time stamp base.
280 * \param ctsBytes Number of bytes total in CTS packet.
281 */
282 void ScheduleData(const UanHeaderRcCts& ctsh,
283 const UanHeaderRcCtsGlobal& ctsg,
284 uint32_t ctsBytes);
285 /**
286 * Process a received ACK.
287 *
288 * \param ack The ACK packet.
289 */
290 void ProcessAck(Ptr<Packet> ack);
291 /**
292 * Send on packet on the PHY.
293 *
294 * \param pkt The packet.
295 * \param rate The transmission rate.
296 */
297 void SendPacket(Ptr<Packet> pkt, uint32_t rate);
298 /**
299 * Check that PHY is ok:
300 * not CTS or ACK
301 * not to my address
302 * \return True if PHY is ok.
303 */
304 bool IsPhy1Ok();
305 /** Callback to block RST. */
306 void BlockRtsing();
307
308 /**
309 * Global count of calls to Associate, AssociateTimeout,
310 * SendRts, and RtsTimeout.
311 */
313
314 /** Provides exponential random variables. */
316
317 protected:
318 void DoDispose() override;
319
320}; // class UanMacRc
321
322} // namespace ns3
323
324#endif /* UAN_MAC_RC_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
An identifier for simulation events.
Definition: event-id.h:55
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
Stores reservation info for use in scheduling data channel by reservation channel MAC.
Definition: uan-mac-rc.h:51
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
Definition: uan-mac-rc.cc:85
uint32_t GetLength() const
Get the total length of the Reservation.
Definition: uan-mac-rc.cc:91
~Reservation()
Destructor.
Definition: uan-mac-rc.cc:74
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktList
Queued packets for each address.
Definition: uan-mac-rc.h:134
bool m_transmitted
Has this reservation been transmitted.
Definition: uan-mac-rc.h:144
const std::list< std::pair< Ptr< Packet >, Mac8Address > > & GetPktList() const
Get the list of packets.
Definition: uan-mac-rc.cc:97
Reservation()
Default constructor.
Definition: uan-mac-rc.cc:45
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n'th RTS.
Definition: uan-mac-rc.cc:115
uint8_t GetFrameNo() const
Get the frame number.
Definition: uan-mac-rc.cc:103
void IncrementRetry()
Increment the retry count.
Definition: uan-mac-rc.cc:139
uint8_t m_frameNo
Frame number.
Definition: uan-mac-rc.h:138
void SetFrameNo(uint8_t fn)
Set the frame number.
Definition: uan-mac-rc.cc:127
bool IsTransmitted() const
Definition: uan-mac-rc.cc:121
uint8_t m_retryNo
Number of retries.
Definition: uan-mac-rc.h:142
uint8_t GetRetryNo() const
Get the retry number.
Definition: uan-mac-rc.cc:109
uint32_t m_length
Total length of queued packets.
Definition: uan-mac-rc.h:136
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
Definition: uan-mac-rc.cc:145
void AddTimestamp(Time t)
Set the time of the latest RTS sent.
Definition: uan-mac-rc.cc:133
std::vector< Time > m_timestamp
Timestamps for each retry.
Definition: uan-mac-rc.h:140
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
Cycle broadcast information.
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:46
Non-gateway node MAC for reservation channel MAC protocol.
Definition: uan-mac-rc.h:163
void Clear() override
Clears all pointer references.
Definition: uan-mac-rc.cc:175
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
Definition: uan-mac-rc.cc:504
void ReceiveOkFromPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok Callback.
Definition: uan-mac-rc.cc:325
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
Definition: uan-mac-rc.cc:419
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
Definition: uan-mac-rc.h:216
void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb) override
Set the callback to forward packets up to higher layers.
Definition: uan-mac-rc.cc:312
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
Definition: uan-mac-rc.cc:593
EventId m_startAgain
(Unused).
Definition: uan-mac-rc.h:215
void BlockRtsing()
Callback to block RST.
Definition: uan-mac-rc.cc:768
TracedCallback< Ptr< const Packet >, uint32_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
Definition: uan-mac-rc.h:248
uint32_t m_queueLimit
Maximum packets to queue at MAC.
Definition: uan-mac-rc.h:222
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
Definition: uan-mac-rc.cc:318
void RtsTimeout()
Retry RTS.
Definition: uan-mac-rc.cc:727
EventId m_rtsEvent
The RTS event.
Definition: uan-mac-rc.h:251
uint8_t m_frameNo
Current frame number.
Definition: uan-mac-rc.h:223
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition: uan-mac-rc.h:315
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Definition: uan-mac-rc.cc:268
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-rc.h:218
void DoDispose() override
Destructor implementation.
Definition: uan-mac-rc.cc:198
double m_minRetryRate
Smallest allowed RTS retry rate.
Definition: uan-mac-rc.h:227
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktQueue
Pending packets.
Definition: uan-mac-rc.h:236
double m_retryStep
Retry rate increment.
Definition: uan-mac-rc.h:228
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Definition: uan-mac-rc.h:230
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
The callback to forward a packet up to higher layer.
Definition: uan-mac-rc.h:241
UanMacRc()
Default constructor.
Definition: uan-mac-rc.cc:152
void AssociateTimeout()
Periodically retry association.
Definition: uan-mac-rc.cc:635
~UanMacRc() override
Dummy destructor, DoDispose.
Definition: uan-mac-rc.cc:170
void Associate()
Associate with a gateway by sending the first GWPING.
Definition: uan-mac-rc.cc:606
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
Definition: uan-mac-rc.h:312
bool IsPhy1Ok()
Check that PHY is ok: not CTS or ACK not to my address.
Definition: uan-mac-rc.cc:704
void SendRts()
Send RTS packet.
Definition: uan-mac-rc.cc:669
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Definition: uan-mac-rc.h:231
Time m_learnedProp
Propagation delay to gateway.
Definition: uan-mac-rc.h:225
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc.h:244
State m_state
MAC state.
Definition: uan-mac-rc.h:212
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
Definition: uan-mac-rc.h:220
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
Definition: uan-mac-rc.cc:539
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
Definition: uan-mac-rc.cc:276
bool m_rtsBlocked
RTS blocked while processing ACK.
Definition: uan-mac-rc.h:213
@ TYPE_RTS
RTS.
Definition: uan-mac-rc.h:170
@ TYPE_DATA
Data.
Definition: uan-mac-rc.h:168
@ TYPE_ACK
ACK.
Definition: uan-mac-rc.h:172
@ TYPE_CTS
CTS.
Definition: uan-mac-rc.h:171
@ TYPE_GWPING
Gateway ping.
Definition: uan-mac-rc.h:169
std::list< Reservation > m_resList
List of scheduled reservations.
Definition: uan-mac-rc.h:238
TracedCallback< Ptr< const Packet >, uint32_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-rc.h:246
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition: uan-mac-rc.h:224
Mac8Address m_assocAddr
Next hop address.
Definition: uan-mac-rc.h:217
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-rc.h:233
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
Definition: uan-mac-rc.h:221
State
MAC state.
Definition: uan-mac-rc.h:204
@ DATATX
(Unused).
Definition: uan-mac-rc.h:209
@ IDLE
Finished scheduling packet sends.
Definition: uan-mac-rc.h:207
@ RTSSENT
RTS just sent.
Definition: uan-mac-rc.h:208
@ GWPSENT
Associated with gateway.
Definition: uan-mac-rc.h:206
@ UNASSOCIATED
Initial state.
Definition: uan-mac-rc.h:205
uint32_t m_numRates
Number of rates per Phy layer.
Definition: uan-mac-rc.h:219
static TypeId GetTypeId()
Register this type.
Definition: uan-mac-rc.cc:205
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint32_t proto)
TracedCallback signature for dequeue of a packet.
Definition: uan-mac-rc.h:199
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:43
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define list