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"
44 m_rv = CreateObject<UniformRandomVariable> ();
84 "The MAC parameter CW.",
87 MakeUintegerChecker<uint32_t> ())
88 .AddAttribute (
"SlotTime",
89 "Time slot duration for MAC backoff.",
93 .AddTraceSource (
"Enqueue",
94 "A packet arrived at the MAC for transmission.",
96 "ns3::UanMacCw::QueueTracedCallback")
97 .AddTraceSource (
"Dequeue",
98 "A was passed down to the PHY from the MAC.",
100 "ns3::UanMacCw::QueueTracedCallback")
101 .AddTraceSource (
"RX",
102 "A packet was destined for this MAC and was received.",
104 "ns3::UanMac::PacketModeTracedCallback")
139 NS_ASSERT (
m_phy->GetTransducer ()->GetArrivalList ().size () >= 1 ||
m_phy->IsStateTx ());
143 NS_ASSERT (
m_phy->GetTransducer ()->GetArrivalList ().size () == 0 && !
m_phy->IsStateTx ());
158 if (
m_phy->IsStateBusy ())
166 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 ());
167 NS_ASSERT (
m_phy->GetTransducer ()->GetArrivalList ().size () >= 1 ||
m_phy->IsStateTx ());
173 NS_ASSERT (
m_phy->GetTransducer ()->GetArrivalList ().size () == 0 && !
m_phy->IsStateTx ());
175 m_phy->SendPacket (packet,protocolNumber);
202 m_phy->RegisterListener (
this);
311 if (
m_phy->IsStateIdle ())
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
CW-MAC protocol, similar in idea to the 802.11 DCF with constant backoff window.
Simulation virtual time values and global simulation resolution.
virtual Address GetAddress()
Get the MAC Address.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
State m_state
Current state.
void SendPacket(void)
Send packet on PHY.
uint16_t m_pktTxProt
Next packet protocol number (usage varies by MAC).
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
static TypeId GetTypeId(void)
Register this type.
Channel is IDLE, no packet is being transmitted.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
virtual void SetSlotTime(Time duration)
Set the slot time duration.
virtual void DoDispose(void)
Destructor implementation.
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
bool m_cleared
Flag when we've been cleared.
#define NS_FATAL_ERROR(msg)
Fatal error handling.
virtual void Clear(void)
Clears all pointer references.
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...
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
virtual Address GetBroadcast(void) const
Get the broadcast address.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Time m_savedDelayS
Remaining delay until next send.
virtual void NotifyRxEndError(void)
Called when UanPhy finishes receiving packet in error.
a polymophic address class
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual void SetAddress(UanAddress addr)
Set the address.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Enqueue packet to be transmitted.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Virtual base class for all UAN MAC protocols.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet destined for this MAC was received.
AttributeValue implementation for Time.
A class used for addressing UAN MAC's.
static UanAddress ConvertFrom(const Address &address)
Convert a generic address to a UanAddress.
Hold an unsigned integer type.
virtual void SetCw(uint32_t cw)
Set the contention window size.
virtual void NotifyRxStart(void)
Called when UanPhy begins receiving packet.
void EndTx(void)
End TX state.
Abstraction of packet modulation information.
UanMacCw()
Default constructor.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Ptr< UniformRandomVariable > m_rv
Provides uniform random variable for contention window.
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
Forwarding up callback.
virtual void NotifyRxEndOk(void)
Called when UanPhy finishes receiving packet without error.
void SaveTimer(void)
Cancel SendEvent and save remaining delay.
static UanAddress GetBroadcast(void)
Get the broadcast address (255).
virtual ~UanMacCw()
Dummy destructor, DoDispose.
virtual void NotifyCcaStart(void)
Called when UanPhy begins sensing channel is busy.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual Time GetSlotTime(void)
Get the slot time duration.
static Time Now(void)
Return the current simulation virtual time.
virtual void NotifyTxStart(Time duration)
Called when transmission starts from Phy object.
virtual void DoDispose()
Destructor implementation.
EventId m_sendEvent
Scheduled SendPacket event.
EventId m_txEndEvent
Scheduled EndTx event.
virtual uint32_t GetCw(void)
Get the contention window size.
Time m_sendTime
Time to send next packet.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Time m_slotTime
Slot time duration.
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Set the callback to forward packets up to higher layers.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
void PhyRxPacketGood(Ptr< Packet > packet, double sinr, UanTxMode mode)
Receive packet from lower layer (passed to PHY as callback).
Ptr< Packet > m_pktTx
Next packet to send.
UanAddress m_address
The MAC address.
A base class which provides memory management and object aggregation.
void StartTimer(void)
Schedule SendPacket after delay.
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A packet was passed down to the PHY from the MAC.
void PhyRxPacketError(Ptr< Packet > packet, double sinr)
Packet received at lower layer in error.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
a unique identifier for an interface.
uint32_t m_cw
Contention window size.
virtual void NotifyCcaEnd(void)
Called when UanPhy stops sensing channel is busy.
TypeId SetParent(TypeId tid)
void AddHeader(const Header &header)
Add header to this packet.