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 // end of class Reservation
136};
137
138/**
139 * @ingroup uan
140 *
141 * Non-gateway node MAC for reservation channel MAC protocol.
142 *
143 * This MAC protocol assumes a network topology where all traffic
144 * is destined for a set of GW nodes which are connected via
145 * some out of band (RF?) means. This particular implementation
146 * assumes that there is only a single gateway.
147 *
148 * For more information on class operation email
149 * lentracy@u.washington.edu
150 * (This work is, as of yet, unpublished)
151 */
152class UanMacRc : public UanMac
153{
154 public:
155 /** Packet types. */
156 enum
157 {
158 TYPE_DATA, //!< Data.
159 TYPE_GWPING, //!< Gateway ping.
160 TYPE_RTS, //!< RTS.
161 TYPE_CTS, //!< CTS.
162 TYPE_ACK //!< ACK.
163 };
164
165 /** Default constructor */
166 UanMacRc();
167 /** Dummy destructor, DoDispose. */
168 ~UanMacRc() override;
169
170 /**
171 * Register this type.
172 * @return The TypeId.
173 */
174 static TypeId GetTypeId();
175
176 // Inherited methods
177 bool Enqueue(Ptr<Packet> pkt, uint16_t protocolNumber, const Address& dest) override;
178 void SetForwardUpCb(Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb) override;
179 void AttachPhy(Ptr<UanPhy> phy) override;
180 void Clear() override;
181 int64_t AssignStreams(int64_t stream) override;
182
183 /**
184 * TracedCallback signature for dequeue of a packet.
185 *
186 * @param [in] packet The Packet being received.
187 * @param [in] proto The protocol number.
188 */
189 typedef void (*QueueTracedCallback)(Ptr<const Packet> packet, uint32_t proto);
190
191 private:
192 /** MAC state. */
193 enum State
194 {
195 UNASSOCIATED, //!< Initial state.
196 GWPSENT, //!< Associated with gateway.
197 IDLE, //!< Finished scheduling packet sends.
198 RTSSENT, //!< RTS just sent.
199 DATATX //!< (Unused).
200 };
201
202 State m_state; //!< MAC state.
203 bool m_rtsBlocked; //!< RTS blocked while processing ACK.
204
205 EventId m_startAgain; //!< (Unused).
206 double m_retryRate; //!< Number of retry attempts per second (of RTS/GWPING.
207 Mac8Address m_assocAddr; //!< Next hop address.
208 Ptr<UanPhy> m_phy; //!< PHY layer attached to this MAC.
209 uint32_t m_numRates; //!< Number of rates per Phy layer.
210 uint32_t m_currentRate; //!< Rate number corresponding to data rate of current cycle.
211 uint32_t m_maxFrames; //!< Maximum number of frames to include in a single RTS.
212 uint32_t m_queueLimit; //!< Maximum packets to queue at MAC.
213 uint8_t m_frameNo; //!< Current frame number.
214 Time m_sifs; //!< Spacing between frames to account for timing error and processing delay.
215 Time m_learnedProp; //!< Propagation delay to gateway.
216
217 double m_minRetryRate; //!< Smallest allowed RTS retry rate.
218 double m_retryStep; //!< Retry rate increment.
219
220 uint32_t m_ctsSizeN; //!< Size of UanHeaderRcCts.
221 uint32_t m_ctsSizeG; //!< Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
222
223 bool m_cleared; //!< Flag when we've been cleared.
224
225 /** Pending packets. */
226 std::list<std::pair<Ptr<Packet>, Mac8Address>> m_pktQueue;
227 /** List of scheduled reservations. */
228 std::list<Reservation> m_resList;
229
230 /** The callback to forward a packet up to higher layer. */
232
233 /** A packet was destined for and received at this MAC layer. */
235 /** A packet arrived at the MAC for transmission. */
237 /** A was passed down to the PHY from the MAC. */
239
240 /** The RTS event. */
242 /**
243 * PHY receive ok Callback.
244 *
245 * @param pkt The received packet.
246 * @param sinr (Unused).
247 * @param mode Modulation mode.
248 */
249 void ReceiveOkFromPhy(Ptr<Packet> pkt, double sinr, UanTxMode mode);
250 /** Associate with a gateway by sending the first GWPING. */
251 void Associate();
252 /** Periodically retry association. */
253 void AssociateTimeout();
254 /** Send RTS packet. */
255 void SendRts();
256 /** Retry RTS. */
257 void RtsTimeout();
258 /**
259 * Create the RTS header from a Reservation.
260 *
261 * @param res The Reservation.
262 * @return A RTS header.
263 */
265 /**
266 * Schedule Packet sends.
267 *
268 * @param ctsh The CTS header identifying the frame number and delay.
269 * @param ctsg The CTS global header giving the transmit time stamp base.
270 * @param ctsBytes Number of bytes total in CTS packet.
271 */
272 void ScheduleData(const UanHeaderRcCts& ctsh,
273 const UanHeaderRcCtsGlobal& ctsg,
274 uint32_t ctsBytes);
275 /**
276 * Process a received ACK.
277 *
278 * @param ack The ACK packet.
279 */
280 void ProcessAck(Ptr<Packet> ack);
281 /**
282 * Send on packet on the PHY.
283 *
284 * @param pkt The packet.
285 * @param rate The transmission rate.
286 */
287 void SendPacket(Ptr<Packet> pkt, uint32_t rate);
288 /**
289 * Check that PHY is ok:
290 * not CTS or ACK
291 * not to my address
292 * @return True if PHY is ok.
293 */
294 bool IsPhy1Ok();
295 /** Callback to block RST. */
296 void BlockRtsing();
297
298 /**
299 * Global count of calls to Associate, AssociateTimeout,
300 * SendRts, and RtsTimeout.
301 */
303
304 /** Provides exponential random variables. */
306
307 protected:
308 void DoDispose() override;
309
310 // end of class UanMacRc
311};
312
313} // namespace ns3
314
315#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:49
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:153
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:206
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:205
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:238
uint32_t m_queueLimit
Maximum packets to queue at MAC.
Definition uan-mac-rc.h:212
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:241
uint8_t m_frameNo
Current frame number.
Definition uan-mac-rc.h:213
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
Definition uan-mac-rc.h:305
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:208
void DoDispose() override
Destructor implementation.
double m_minRetryRate
Smallest allowed RTS retry rate.
Definition uan-mac-rc.h:217
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktQueue
Pending packets.
Definition uan-mac-rc.h:226
double m_retryStep
Retry rate increment.
Definition uan-mac-rc.h:218
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Definition uan-mac-rc.h:220
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:231
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:302
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:221
Time m_learnedProp
Propagation delay to gateway.
Definition uan-mac-rc.h:215
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition uan-mac-rc.h:234
State m_state
MAC state.
Definition uan-mac-rc.h:202
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
Definition uan-mac-rc.h:210
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:203
@ TYPE_DATA
Data.
Definition uan-mac-rc.h:158
@ TYPE_GWPING
Gateway ping.
Definition uan-mac-rc.h:159
std::list< Reservation > m_resList
List of scheduled reservations.
Definition uan-mac-rc.h:228
TracedCallback< Ptr< const Packet >, uint32_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition uan-mac-rc.h:236
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition uan-mac-rc.h:214
Mac8Address m_assocAddr
Next hop address.
Definition uan-mac-rc.h:207
bool m_cleared
Flag when we've been cleared.
Definition uan-mac-rc.h:223
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
Definition uan-mac-rc.h:211
State
MAC state.
Definition uan-mac-rc.h:194
@ DATATX
(Unused).
Definition uan-mac-rc.h:199
@ IDLE
Finished scheduling packet sends.
Definition uan-mac-rc.h:197
@ RTSSENT
RTS just sent.
Definition uan-mac-rc.h:198
@ GWPSENT
Associated with gateway.
Definition uan-mac-rc.h:196
@ UNASSOCIATED
Initial state.
Definition uan-mac-rc.h:195
uint32_t m_numRates
Number of rates per Phy layer.
Definition uan-mac-rc.h:209
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:189
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.