13#include "ns3/attribute.h"
14#include "ns3/double.h"
16#include "ns3/nstime.h"
17#include "ns3/trace-source-accessor.h"
18#include "ns3/uinteger.h"
76 "The MAC parameter CW.",
80 .AddAttribute(
"SlotTime",
81 "Time slot duration for MAC backoff.",
85 .AddTraceSource(
"Enqueue",
86 "A packet arrived at the MAC for transmission.",
88 "ns3::UanMacCw::QueueTracedCallback")
89 .AddTraceSource(
"Dequeue",
90 "A was passed down to the PHY from the MAC.",
92 "ns3::UanMacCw::QueueTracedCallback")
94 "A packet was destined for this MAC and was received.",
96 "ns3::UanMac::PacketModeTracedCallback")
109 <<
" Starting enqueue CCABUSY");
134 packet->AddHeader(header);
138 if (
m_phy->IsStateBusy())
147 <<
": Enqueuing new packet while busy: (Chose CW " << cw
149 <<
" Packet size: " << packet->GetSize());
156 <<
": Enqueuing new packet while idle (sending)");
183 m_phy->RegisterListener(
this);
192 <<
": Switching to channel busy");
204 <<
": Switching to channel idle");
216 <<
": Switching to channel idle");
228 <<
": Switching to channel busy");
240 <<
": Switching to channel idle");
273 m_rv->SetStream(stream);
287 if (
m_phy->IsStateIdle())
290 <<
": Switching to channel idle (After TX!)");
329 packet->RemoveHeader(header);
347 <<
" Saving timer (Delay = "
a polymophic address class
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
A class used for addressing MAC8 MAC's.
static Mac8Address GetBroadcast()
Get the broadcast address (255).
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
CW-MAC protocol, similar in idea to the 802.11 DCF with constant backoff window.
bool m_txOngoing
Tx is ongoing.
Time m_sendTime
Time to send next packet.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet destined for this MAC was received.
void NotifyCcaStart() override
Called when UanPhy begins sensing channel is busy.
void Clear() override
Clears all pointer references.
Ptr< Packet > m_pktTx
Next packet to send.
void SaveTimer()
Cancel SendEvent and save remaining delay.
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A packet was passed down to the PHY from the MAC.
void NotifyRxEndError() override
Called when UanPhy finishes receiving packet in error.
bool m_cleared
Flag when we've been cleared.
void EndTx()
End TX state.
void SendPacket()
Send packet on PHY.
void NotifyCcaEnd() override
Called when UanPhy stops sensing channel is busy.
virtual void SetSlotTime(Time duration)
Set the slot time duration.
virtual uint32_t GetCw()
Get the contention window size.
static TypeId GetTypeId()
Register this type.
UanMacCw()
Default constructor.
State m_state
Current state.
Ptr< UniformRandomVariable > m_rv
Provides uniform random variable for contention window.
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
void NotifyRxEndOk() override
Called when UanPhy finishes receiving packet without error.
void DoDispose() override
Destructor implementation.
virtual void SetCw(uint32_t cw)
Set the contention window size.
Time m_slotTime
Slot time duration.
~UanMacCw() override
Dummy destructor, DoDispose.
void NotifyTxStart(Time duration) override
Called when transmission starts from Phy object.
EventId m_sendEvent
Scheduled SendPacket event.
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
void NotifyRxStart() override
Called when UanPhy begins receiving packet.
void PhyRxPacketGood(Ptr< Packet > packet, double sinr, UanTxMode mode)
Receive packet from lower layer (passed to PHY as callback).
@ RUNNING
Delay timer running.
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
void NotifyTxEnd() override
Function called when Phy object finishes transmitting packet.
Time m_savedDelayS
Remaining delay until next send.
virtual Time GetSlotTime()
Get the slot time duration.
void StartTimer()
Schedule SendPacket after delay.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
uint32_t m_cw
Contention window size.
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb) override
Set the callback to forward packets up to higher layers.
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Virtual base class for all UAN MAC protocols.
uint32_t GetTxModeIndex() const
Get the Tx mode index (Modulation type).
virtual Address GetAddress()
Get the MAC Address.
Abstraction of packet modulation information.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
@ IDLE
Channel is IDLE, no packet is being transmitted.