A Discrete-Event Network Simulator
Go to the documentation of this file.
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
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 */
20#ifndef UAN_MAC_CW_H
21#define UAN_MAC_CW_H
23#include "ns3/mac8-address.h"
24#include "ns3/nstime.h"
25#include "ns3/random-variable-stream.h"
26#include "ns3/simulator.h"
27#include "ns3/uan-mac.h"
28#include "ns3/uan-phy.h"
29#include "ns3/uan-tx-mode.h"
31namespace ns3
46class UanMacCw : public UanMac, public UanPhyListener
48 public:
50 UanMacCw();
52 ~UanMacCw() override;
57 static TypeId GetTypeId();
64 virtual void SetCw(uint32_t cw);
70 virtual void SetSlotTime(Time duration);
76 virtual uint32_t GetCw();
82 virtual Time GetSlotTime();
84 // Inherited methods from UanMac
85 bool Enqueue(Ptr<Packet> pkt, uint16_t protocolNumber, const Address& dest) override;
86 void SetForwardUpCb(Callback<void, Ptr<Packet>, uint16_t, const Mac8Address&> cb) override;
87 void AttachPhy(Ptr<UanPhy> phy) override;
88 void Clear() override;
89 int64_t AssignStreams(int64_t stream) override;
91 // Inherited methods from UanPhyListener
92 void NotifyRxStart() override;
93 void NotifyRxEndOk() override;
94 void NotifyRxEndError() override;
95 void NotifyCcaStart() override;
96 void NotifyCcaEnd() override;
97 void NotifyTxStart(Time duration) override;
98 void NotifyTxEnd() override;
106 typedef void (*QueueTracedCallback)(Ptr<const Packet> packet, uint16_t proto);
108 private:
110 enum State
111 {
115 TX
116 };
129 // Mac parameters
133 // State variables
141 uint16_t m_pktTxProt;
162 void PhyRxPacketGood(Ptr<Packet> packet, double sinr, UanTxMode mode);
169 void PhyRxPacketError(Ptr<Packet> packet, double sinr);
171 void SaveTimer();
173 void StartTimer();
175 void SendPacket();
177 void EndTx();
179 protected:
180 void DoDispose() override;
182}; // class UanMacCw
184} // namespace ns3
186#endif /* UAN_MAC_CW_H */
a polymophic address class
Definition: address.h:100
Callback template class.
Definition: callback.h:443
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:60
CW-MAC protocol, similar in idea to the 802.11 DCF with constant backoff window.
Definition: uan-mac-cw.h:47
bool m_txOngoing
Tx is ongoing.
Definition: uan-mac-cw.h:145
Time m_sendTime
Time to send next packet.
Definition: uan-mac-cw.h:135
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet destined for this MAC was received.
Definition: uan-mac-cw.h:123
void NotifyCcaStart() override
Called when UanPhy begins sensing channel is busy.
Definition: uan-mac-cw.cc:233
void Clear() override
Clears all pointer references.
Definition: uan-mac-cw.cc:54
Ptr< Packet > m_pktTx
Next packet to send.
Definition: uan-mac-cw.h:139
void SaveTimer()
Cancel SendEvent and save remaining delay.
Definition: uan-mac-cw.cc:354
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A packet was passed down to the PHY from the MAC.
Definition: uan-mac-cw.h:127
void NotifyRxEndError() override
Called when UanPhy finishes receiving packet in error.
Definition: uan-mac-cw.cc:221
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-cw.h:150
void EndTx()
End TX state.
Definition: uan-mac-cw.cc:288
void SendPacket()
Send packet on PHY.
Definition: uan-mac-cw.cc:383
void NotifyCcaEnd() override
Called when UanPhy stops sensing channel is busy.
Definition: uan-mac-cw.cc:245
virtual void SetSlotTime(Time duration)
Set the slot time duration.
Definition: uan-mac-cw.cc:318
virtual uint32_t GetCw()
Get the contention window size.
Definition: uan-mac-cw.cc:324
static TypeId GetTypeId()
Register this type.
Definition: uan-mac-cw.cc:79
Default constructor.
Definition: uan-mac-cw.cc:37
State m_state
Current state.
Definition: uan-mac-cw.h:147
Ptr< UniformRandomVariable > m_rv
Provides uniform random variable for contention window.
Definition: uan-mac-cw.h:153
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
Definition: uan-mac-cw.cc:113
void NotifyRxEndOk() override
Called when UanPhy finishes receiving packet without error.
Definition: uan-mac-cw.cc:209
void DoDispose() override
Destructor implementation.
Definition: uan-mac-cw.cc:72
virtual void SetCw(uint32_t cw)
Set the contention window size.
Definition: uan-mac-cw.cc:312
Time m_slotTime
Slot time duration.
Definition: uan-mac-cw.h:131
~UanMacCw() override
Dummy destructor, DoDispose.
Definition: uan-mac-cw.cc:49
void NotifyTxStart(Time duration) override
Called when transmission starts from Phy object.
Definition: uan-mac-cw.cc:257
EventId m_sendEvent
Scheduled SendPacket event.
Definition: uan-mac-cw.h:143
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Definition: uan-mac-cw.cc:349
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
Definition: uan-mac-cw.h:119
void NotifyRxStart() override
Called when UanPhy begins receiving packet.
Definition: uan-mac-cw.cc:197
void PhyRxPacketGood(Ptr< Packet > packet, double sinr, UanTxMode mode)
Receive packet from lower layer (passed to PHY as callback).
Definition: uan-mac-cw.cc:336
Enum defining possible Phy states.
Definition: uan-mac-cw.h:111
Idle state.
Definition: uan-mac-cw.h:112
Delay timer running.
Definition: uan-mac-cw.h:114
@ TX
Definition: uan-mac-cw.h:115
Channel busy.
Definition: uan-mac-cw.h:113
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Definition: uan-mac-cw.h:125
void NotifyTxEnd() override
Function called when Phy object finishes transmitting packet.
Definition: uan-mac-cw.cc:272
Time m_savedDelayS
Remaining delay until next send.
Definition: uan-mac-cw.h:137
virtual Time GetSlotTime()
Get the slot time duration.
Definition: uan-mac-cw.cc:330
void StartTimer()
Schedule SendPacket after delay.
Definition: uan-mac-cw.cc:366
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-cw.h:121
uint32_t m_cw
Contention window size.
Definition: uan-mac-cw.h:130
void(* QueueTracedCallback)(Ptr< const Packet > packet, uint16_t proto)
TracedCallback signature for enqueue/dequeue of a packet.
Definition: uan-mac-cw.h:106
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
Definition: uan-mac-cw.cc:188
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:182
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
Definition: uan-mac-cw.h:141
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:280
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:46
Interface for PHY event listener.
Definition: uan-phy.h:144
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:43
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Definition: third.py:82