21 #include "uan-mac-cw.h"
22 #include "ns3/attribute.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/double.h"
25 #include "ns3/nstime.h"
26 #include "ns3/uan-header-common.h"
27 #include "ns3/trace-source-accessor.h"
34 NS_OBJECT_ENSURE_REGISTERED (UanMacCw);
44 m_rv = CreateObject<UniformRandomVariable> ();
47 UanMacCw::~UanMacCw ()
77 UanMacCw::GetTypeId (
void)
81 .AddConstructor<UanMacCw> ()
83 "The MAC parameter CW",
85 MakeUintegerAccessor (&UanMacCw::m_cw),
86 MakeUintegerChecker<uint32_t> ())
87 .AddAttribute (
"SlotTime",
88 "Time slot duration for MAC backoff",
90 MakeTimeAccessor (&UanMacCw::m_slotTime),
92 .AddTraceSource (
"Enqueue",
93 "A packet arrived at the MAC for transmission",
95 .AddTraceSource (
"Dequeue",
96 "A was passed down to the PHY from the MAC",
98 .AddTraceSource (
"RX",
99 "A packet was destined for this MAC and was received",
109 return this->m_address;
135 NS_ASSERT (m_phy->GetTransducer ()->GetArrivalList ().size () >= 1 || m_phy->IsStateTx ());
139 NS_ASSERT (m_phy->GetTransducer ()->GetArrivalList ().size () == 0 && !m_phy->IsStateTx ());
148 header.
SetSrc (m_address);
152 m_enqueueLogger (packet, protocolNumber);
154 if (m_phy->IsStateBusy ())
157 m_pktTxProt = protocolNumber;
162 NS_LOG_DEBUG (
"Time " <<
Simulator::Now ().GetSeconds () <<
": Addr " <<
GetAddress () <<
": Enqueuing new packet while busy: (Chose CW " << cw <<
", Sending at " << m_sendTime.GetSeconds () <<
" Packet size: " << packet->
GetSize ());
163 NS_ASSERT (m_phy->GetTransducer ()->GetArrivalList ().size () >= 1 || m_phy->IsStateTx ());
169 NS_ASSERT (m_phy->GetTransducer ()->GetArrivalList ().size () == 0 && !m_phy->IsStateTx ());
171 m_phy->SendPacket (packet,protocolNumber);
196 m_phy->SetReceiveOkCallback (
MakeCallback (&UanMacCw::PhyRxPacketGood,
this));
197 m_phy->SetReceiveErrorCallback (
MakeCallback (&UanMacCw::PhyRxPacketError,
this));
198 m_phy->RegisterListener (
this);
211 if (m_state == RUNNING)
223 if (m_state == CCABUSY && !m_phy->IsStateCcaBusy ())
235 if (m_state == CCABUSY && !m_phy->IsStateCcaBusy ())
247 if (m_state == RUNNING)
259 if (m_state == CCABUSY)
279 if (m_state == RUNNING)
298 UanMacCw::EndTx (
void)
300 NS_ASSERT (m_state == TX || m_state == CCABUSY);
305 else if (m_state == CCABUSY)
307 if (m_phy->IsStateIdle ())
327 m_slotTime = duration;
347 m_forwardUpCb (packet, header.
GetSrc ());
351 UanMacCw::PhyRxPacketError (Ptr<Packet> packet,
double sinr)
356 UanMacCw::SaveTimer (
void)
367 UanMacCw::StartTimer (
void)
383 UanMacCw::SendPacket (
void)
388 m_phy->SendPacket (m_pktTx,m_pktTxProt);
uint32_t RemoveHeader(Header &header)
virtual Address GetAddress()
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
virtual void SetSlotTime(Time duration)
virtual void DoDispose(void)
virtual void AttachPhy(Ptr< UanPhy > phy)
static void Cancel(const EventId &id)
bool IsRunning(void) const
virtual Address GetBroadcast(void) const
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual void NotifyRxEndError(void)
Function called by UanPhy object to notify of packet received in error.
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
virtual void SetAddress(UanAddress addr)
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
double GetSeconds(void) const
hold objects of type ns3::Time
static UanAddress ConvertFrom(const Address &address)
Hold an unsigned integer type.
virtual void SetCw(uint32_t cw)
virtual void NotifyRxStart(void)
Function called by UanPhy object to notify of packet reception.
Abstraction of packet modulation information.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Ptr< UniformRandomVariable > m_rv
Provides uniform random variables.
virtual void NotifyRxEndOk(void)
Function called by UanPhy object to notify of packet received successfully.
static UanAddress GetBroadcast(void)
virtual void NotifyCcaStart(void)
Function called by UanPhy object to notify of channel sensed busy.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual Time GetSlotTime(void)
virtual void NotifyTxStart(Time duration)
Function called by UanPhy object to notify of outgoing transmission start.
virtual uint32_t GetCw(void)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
#define NS_LOG_DEBUG(msg)
int64_t AssignStreams(int64_t stream)
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
a base class which provides memory management and object aggregation
a unique identifier for an interface.
virtual void NotifyCcaEnd(void)
Function called by UanPhy object to notify of channel no longer sensed busy.
TypeId SetParent(TypeId tid)
void AddHeader(const Header &header)