A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-mac-cw.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_CW_H
21#define UAN_MAC_CW_H
22
23#include "uan-mac.h"
24#include "uan-phy.h"
25#include "uan-tx-mode.h"
26
27#include "ns3/mac8-address.h"
28#include "ns3/nstime.h"
29#include "ns3/random-variable-stream.h"
30#include "ns3/simulator.h"
31
32namespace ns3
33{
34
35/**
36 * \ingroup uan
37 *
38 * CW-MAC protocol, similar in idea to the 802.11 DCF with
39 * constant backoff window
40 *
41 * For more information on this MAC protocol, see:
42 * Parrish, N.; Tracy, L.; Roy, S.; Arabshahi, P.; Fox, W.,
43 * "System Design Considerations for Undersea Networks: Link and
44 * Multiple Access Protocols," Selected Areas in Communications,
45 * IEEE Journal on , vol.26, no.9, pp.1720-1730, December 2008
46 */
47class UanMacCw : public UanMac, public UanPhyListener
48{
49 public:
50 /** Default constructor */
51 UanMacCw();
52 /** Dummy destructor, DoDispose. */
53 ~UanMacCw() override;
54 /**
55 * Register this type.
56 * \return The TypeId.
57 */
58 static TypeId GetTypeId();
59
60 /**
61 * Set the contention window size.
62 *
63 * \param cw Contention window size.
64 */
65 virtual void SetCw(uint32_t cw);
66 /**
67 * Set the slot time duration.
68 *
69 * \param duration Slot time duration.
70 */
71 virtual void SetSlotTime(Time duration);
72 /**
73 * Get the contention window size.
74 *
75 * \return Contention window size.
76 */
77 virtual uint32_t GetCw();
78 /**
79 * Get the slot time duration.
80 *
81 * \return Slot time duration.
82 */
83 virtual Time GetSlotTime();
84
85 // Inherited methods from UanMac
86 bool Enqueue(Ptr<Packet> pkt, uint16_t protocolNumber, const Address& dest) override;
87 void SetForwardUpCb(Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb) override;
88 void AttachPhy(Ptr<UanPhy> phy) override;
89 void Clear() override;
90 int64_t AssignStreams(int64_t stream) override;
91
92 // Inherited methods from UanPhyListener
93 void NotifyRxStart() override;
94 void NotifyRxEndOk() override;
95 void NotifyRxEndError() override;
96 void NotifyCcaStart() override;
97 void NotifyCcaEnd() override;
98 void NotifyTxStart(Time duration) override;
99 void NotifyTxEnd() override;
100
101 /**
102 * TracedCallback signature for enqueue/dequeue of a packet.
103 *
104 * \param [in] packet The Packet being received.
105 * \param [in] proto The protocol number.
106 */
107 typedef void (*QueueTracedCallback)(Ptr<const Packet> packet, uint16_t proto);
108
109 private:
110 /** Enum defining possible Phy states. */
111 enum State
112 {
113 IDLE, //!< Idle state.
114 CCABUSY, //!< Channel busy.
115 RUNNING, //!< Delay timer running.
116 TX //!< Transmitting.
117 };
118
119 /** Forwarding up callback. */
121 /** PHY layer attached to this MAC. */
123 /** A packet destined for this MAC was received. */
125 /** A packet arrived at the MAC for transmission. */
127 /** A packet was passed down to the PHY from the MAC. */
129
130 // Mac parameters
131 uint32_t m_cw; //!< Contention window size.
132 Time m_slotTime; //!< Slot time duration.
133
134 // State variables
135 /** Time to send next packet. */
137 /** Remaining delay until next send. */
139 /** Next packet to send. */
141 /** Next packet protocol number (usage varies by MAC). */
142 uint16_t m_pktTxProt;
143 /** Scheduled SendPacket event. */
145 /** Tx is ongoing */
147 /** Current state. */
149
150 /** Flag when we've been cleared */
152
153 /** Provides uniform random variable for contention window. */
155
156 /**
157 * Receive packet from lower layer (passed to PHY as callback).
158 *
159 * \param packet Packet being received.
160 * \param sinr SINR of received packet.
161 * \param mode Mode of received packet.
162 */
163 void PhyRxPacketGood(Ptr<Packet> packet, double sinr, UanTxMode mode);
164 /**
165 * Packet received at lower layer in error.
166 *
167 * \param packet Packet received in error.
168 * \param sinr SINR of received packet.
169 */
170 void PhyRxPacketError(Ptr<Packet> packet, double sinr);
171 /** Cancel SendEvent and save remaining delay. */
172 void SaveTimer();
173 /** Schedule SendPacket after delay. */
174 void StartTimer();
175 /** Send packet on PHY. */
176 void SendPacket();
177 /** End TX state. */
178 void EndTx();
179
180 protected:
181 void DoDispose() override;
182
183}; // class UanMacCw
184
185} // namespace ns3
186
187#endif /* UAN_MAC_CW_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
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
CW-MAC protocol, similar in idea to the 802.11 DCF with constant backoff window.
Definition: uan-mac-cw.h:48
bool m_txOngoing
Tx is ongoing.
Definition: uan-mac-cw.h:146
Time m_sendTime
Time to send next packet.
Definition: uan-mac-cw.h:136
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet destined for this MAC was received.
Definition: uan-mac-cw.h:124
void NotifyCcaStart() override
Called when UanPhy begins sensing channel is busy.
Definition: uan-mac-cw.cc:234
void Clear() override
Clears all pointer references.
Definition: uan-mac-cw.cc:55
Ptr< Packet > m_pktTx
Next packet to send.
Definition: uan-mac-cw.h:140
void SaveTimer()
Cancel SendEvent and save remaining delay.
Definition: uan-mac-cw.cc:355
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A packet was passed down to the PHY from the MAC.
Definition: uan-mac-cw.h:128
void NotifyRxEndError() override
Called when UanPhy finishes receiving packet in error.
Definition: uan-mac-cw.cc:222
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-cw.h:151
void EndTx()
End TX state.
Definition: uan-mac-cw.cc:289
void SendPacket()
Send packet on PHY.
Definition: uan-mac-cw.cc:384
void NotifyCcaEnd() override
Called when UanPhy stops sensing channel is busy.
Definition: uan-mac-cw.cc:246
virtual void SetSlotTime(Time duration)
Set the slot time duration.
Definition: uan-mac-cw.cc:319
virtual uint32_t GetCw()
Get the contention window size.
Definition: uan-mac-cw.cc:325
static TypeId GetTypeId()
Register this type.
Definition: uan-mac-cw.cc:80
UanMacCw()
Default constructor.
Definition: uan-mac-cw.cc:38
State m_state
Current state.
Definition: uan-mac-cw.h:148
Ptr< UniformRandomVariable > m_rv
Provides uniform random variable for contention window.
Definition: uan-mac-cw.h:154
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
Definition: uan-mac-cw.cc:114
void NotifyRxEndOk() override
Called when UanPhy finishes receiving packet without error.
Definition: uan-mac-cw.cc:210
void DoDispose() override
Destructor implementation.
Definition: uan-mac-cw.cc:73
virtual void SetCw(uint32_t cw)
Set the contention window size.
Definition: uan-mac-cw.cc:313
Time m_slotTime
Slot time duration.
Definition: uan-mac-cw.h:132
~UanMacCw() override
Dummy destructor, DoDispose.
Definition: uan-mac-cw.cc:50
void NotifyTxStart(Time duration) override
Called when transmission starts from Phy object.
Definition: uan-mac-cw.cc:258
EventId m_sendEvent
Scheduled SendPacket event.
Definition: uan-mac-cw.h:144
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Definition: uan-mac-cw.cc:350
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
Definition: uan-mac-cw.h:120
void NotifyRxStart() override
Called when UanPhy begins receiving packet.
Definition: uan-mac-cw.cc:198
void PhyRxPacketGood(Ptr< Packet > packet, double sinr, UanTxMode mode)
Receive packet from lower layer (passed to PHY as callback).
Definition: uan-mac-cw.cc:337
State
Enum defining possible Phy states.
Definition: uan-mac-cw.h:112
@ IDLE
Idle state.
Definition: uan-mac-cw.h:113
@ RUNNING
Delay timer running.
Definition: uan-mac-cw.h:115
@ TX
Transmitting.
Definition: uan-mac-cw.h:116
@ CCABUSY
Channel busy.
Definition: uan-mac-cw.h:114
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-cw.h:126
void NotifyTxEnd() override
Function called when Phy object finishes transmitting packet.
Definition: uan-mac-cw.cc:273
Time m_savedDelayS
Remaining delay until next send.
Definition: uan-mac-cw.h:138
virtual Time GetSlotTime()
Get the slot time duration.
Definition: uan-mac-cw.cc:331
void StartTimer()
Schedule SendPacket after delay.
Definition: uan-mac-cw.cc:367
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-cw.h:122
uint32_t m_cw
Contention window size.
Definition: uan-mac-cw.h:131
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint16_t proto)
TracedCallback signature for enqueue/dequeue of a packet.
Definition: uan-mac-cw.h:107
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
Definition: uan-mac-cw.cc:189
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-cw.cc:183
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
Definition: uan-mac-cw.h:142
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-cw.cc:281
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:46
Interface for PHY event listener.
Definition: uan-phy.h:145
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:43
Every class exported by the ns3 library is enclosed in the ns3 namespace.