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