A Discrete-Event Network Simulator
API
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 
32 namespace ns3
33 {
34 
47 class UanMacCw : public UanMac, public UanPhyListener
48 {
49  public:
51  UanMacCw();
53  ~UanMacCw() override;
58  static TypeId GetTypeId();
59 
65  virtual void SetCw(uint32_t cw);
71  virtual void SetSlotTime(Time duration);
77  virtual uint32_t GetCw();
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 
107  typedef void (*QueueTracedCallback)(Ptr<const Packet> packet, uint16_t proto);
108 
109  private:
111  enum State
112  {
116  TX
117  };
118 
129 
130  // Mac parameters
131  uint32_t m_cw;
133 
134  // State variables
142  uint16_t m_pktTxProt;
149 
151  bool m_cleared;
152 
155 
163  void PhyRxPacketGood(Ptr<Packet> packet, double sinr, UanTxMode mode);
170  void PhyRxPacketError(Ptr<Packet> packet, double sinr);
172  void SaveTimer();
174  void StartTimer();
176  void SendPacket();
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
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.
phy
Definition: third.py:89