29 #include "ns3/nstime.h"
30 #include "ns3/simulator.h"
31 #include "ns3/assert.h"
32 #include "ns3/double.h"
33 #include "ns3/uinteger.h"
55 : m_frameNo (frameNo),
59 uint32_t numPkts = (maxPkts) ? maxPkts :
list.size ();
64 for (uint32_t i = 0; i < numPkts; i++)
66 length +=
list.front ().first->GetSize () +
77 std::list<std::pair <Ptr<Packet>,
UanAddress > >::iterator it;
97 const std::list<std::pair <Ptr<Packet>,
UanAddress > > &
155 m_state (UNASSOCIATED),
156 m_rtsBlocked (false),
161 m_ev = CreateObject<ExponentialRandomVariable> ();
188 std::list<std::pair <Ptr<Packet>,
UanAddress > >::iterator it;
211 .AddConstructor<UanMacRc> ()
212 .AddAttribute (
"RetryRate",
213 "Number of retry attempts per second (of RTS/GWPING).",
216 MakeDoubleChecker<double> ())
217 .AddAttribute (
"MaxFrames",
218 "Maximum number of frames to include in a single RTS.",
221 MakeUintegerChecker<uint32_t> ())
222 .AddAttribute (
"QueueLimit",
223 "Maximum packets to queue at MAC.",
226 MakeUintegerChecker<uint32_t> ())
227 .AddAttribute (
"SIFS",
228 "Spacing to give between frames (this should match gateway).",
232 .AddAttribute (
"NumberOfRates",
233 "Number of rate divisions supported by each PHY.",
236 MakeUintegerChecker<uint32_t> ())
237 .AddAttribute (
"MinRetryRate",
238 "Smallest allowed RTS retry rate.",
241 MakeDoubleChecker<double> ())
242 .AddAttribute (
"RetryStep",
243 "Retry rate increment.",
246 MakeDoubleChecker<double> ())
247 .AddAttribute (
"MaxPropDelay",
248 "Maximum possible propagation delay to gateway.",
252 .AddTraceSource (
"Enqueue",
253 "A (data) packet arrived at MAC for transmission.",
255 .AddTraceSource (
"Dequeue",
256 "A (data) packet was passed down to PHY from MAC.",
258 .AddTraceSource (
"RX",
259 "A packet was destined for and received at this MAC layer.",
288 if (protocolNumber > 0)
290 NS_LOG_WARN (
"Warning: UanMacRc does not support multiple protocols. protocolNumber argument to Enqueue is being ignored");
438 std::list<Reservation>::iterator it =
m_resList.begin ();
452 it->SetTransmitted ();
464 Time frameDelay = Seconds (0);
466 const std::list<std::pair <Ptr<Packet>,
UanAddress > > l = it->GetPktList ();
467 std::list<std::pair <Ptr<Packet>,
UanAddress > >::const_iterator pit;
472 for (uint32_t i = 0; i < it->GetNoFrames (); i++, pit++)
487 Time eventTime = startDelay + frameDelay;
492 eventTime = Seconds (0);
496 NS_FATAL_ERROR (
"Scheduling error resulted in very negative data transmission time! eventTime = " << eventTime.
GetSeconds ());
499 NS_LOG_DEBUG (Simulator::Now ().GetSeconds () <<
" Node " <<
m_address <<
" scheduling with delay " << eventTime.
GetSeconds () <<
" propDelay " << m_learnedProp.GetSeconds () <<
" start delay " << startDelay.
GetSeconds () <<
" arrival time " << arrTime.
GetSeconds ());
501 frameDelay = frameDelay +
m_sifs + Seconds (pkt->
GetSize () / currentBps);
549 m_phy->SendPacket (pkt, rate);
558 std::list<Reservation>::iterator it =
m_resList.begin ();
568 NS_LOG_DEBUG (
"In " << __func__ <<
" could not find reservation corresponding to received ACK");
571 if (!it->IsTransmitted ())
577 const std::list<std::pair <Ptr<Packet>,
UanAddress > > l = it->GetPktList ();
578 std::list<std::pair <Ptr<Packet>,
UanAddress > >::const_iterator pit;
582 std::set<uint8_t>::iterator nit = nacks.begin ();
584 for (; nit != nacks.end (); nit++)
660 res.IncrementRetry ();
714 if (phyDual->IsPhy1Rx ())
756 res.IncrementRetry ();
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Simulation virtual time values and global simulation resolution.
#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.
void RtsTimeout(void)
Retry RTS.
EventId m_startAgain
(Unused).
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
bool IsPhy1Ok(void)
Check that PHY is ok: not CTS or ACK not to my address.
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
void AddTimestamp(Time t)
Set the time of the latest RTS sent.
uint8_t m_frameNo
Frame number.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual ~UanMacRc()
Dummy destructor, DoDispose.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint8_t m_frameNo
Current frame number.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Time m_learnedProp
Propagation delay to gateway.
#define NS_FATAL_ERROR(msg)
fatal error handling
bool IsRunning(void) const
This method is syntactic sugar for the ns3::Simulator::isExpired method.
virtual Address GetAddress(void)
Get the MAC Address.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
uint8_t m_retryNo
Number of retries.
void ReceiveOkFromPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok Callback.
uint32_t m_length
Total length of queued packets.
a polymophic address class
virtual Address GetBroadcast(void) const
Get the broadcast address.
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
void BlockRtsing(void)
Callback to block RST.
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
TracedCallback< Ptr< const Packet >, uint16_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
double GetSeconds(void) const
Virtual base class for all UAN MAC protocols.
Reservation()
Default constructor.
std::vector< Time > m_timestamp
Timestamps for each retry.
UanAddress m_address
My addrese.s.
uint8_t GetRetryNo() const
Get the retry number.
hold objects of type ns3::Time
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Set the callback to forward packets up to higher layers.
A class used for addressing UAN MAC's.
static UanAddress ConvertFrom(const Address &address)
Convert a generic address to a UanAddress.
virtual void Clear(void)
Clears all pointer references.
Hold an unsigned integer type.
double m_minRetryRate
Smallest allowed RTS retry rate.
Abstraction of packet modulation information.
double m_retryStep
Retry rate increment.
bool IsTransmitted() const
Finished scheduling packet sends.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
std::list< std::pair< Ptr< Packet >, UanAddress > > m_pktQueue
Pending packets.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
static UanAddress GetBroadcast(void)
Get the broadcast address (255).
void AssociateTimeout(void)
Periodically retry association.
void SetFrameNo(uint8_t fn)
Set the frame number.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
bool m_cleared
Flag when we've been cleared.
UanMacRc()
Default constructor.
static TypeId GetTypeId(void)
Register this type.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
const std::list< std::pair< Ptr< Packet >, UanAddress > > & GetPktList(void) const
Get the list of packets.
EventId m_rtsEvent
The RTS event.
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
static Time Now(void)
Return the "current simulation time".
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
bool m_rtsBlocked
RTS blocked while processing ACK.
TracedCallback< Ptr< const Packet >, uint16_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
std::list< Reservation > m_resList
List of scheduled reservations.
virtual void SetAddress(UanAddress addr)
Set the address.
Time m_sifs
Spacing between frames to account for timing error and processing delay.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
void SendRts(void)
Send RTS packet.
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
uint32_t GetLength() const
Get the total length of the Reservation.
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Stores reservation info for use in scheduling data channel by reservation channel MAC...
uint8_t GetFrameNo() const
Get the frame number.
uint32_t m_numRates
Number of rates per Phy layer.
double GetValue(double mean, double bound)
Returns a random double from an exponential distribution with the specified mean and upper bound...
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::cancel method.
uint32_t m_queueLimit
Maximum packets to queue at MAC.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
std::list< std::pair< Ptr< Packet >, UanAddress > > m_pktList
Queued packets for each address.
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
bool m_transmitted
Has this reservation been transmitted.
Hold a floating point type.
void SetAttribute(std::string name, const AttributeValue &value)
a unique identifier for an interface.
void Associate(void)
Associate with a gateway by sending the first GWPING.
TypeId SetParent(TypeId tid)
UanAddress m_assocAddr
Next hop address.
void IncrementRetry()
Increment the retry count.
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
The callback to forward a packet up to higher layer.
void AddHeader(const Header &header)
Add header to this packet.
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n'th RTS.
~Reservation()
Destructor.
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Enqueue packet to be transmitted.