28#include "ns3/assert.h"
29#include "ns3/double.h"
31#include "ns3/nstime.h"
32#include "ns3/simulator.h"
33#include "ns3/uinteger.h"
65 for (
uint32_t i = 0; i < numPkts; i++)
76 std::list<std::pair<Ptr<Packet>,
Mac8Address>>::iterator it;
97const std::list<std::pair<Ptr<Packet>,
Mac8Address>>&
155 m_state(UNASSOCIATED),
161 m_ev = CreateObject<ExponentialRandomVariable>();
188 std::list<std::pair<Ptr<Packet>,
Mac8Address>>::iterator it;
214 .AddAttribute(
"RetryRate",
215 "Number of retry attempts per second (of RTS/GWPING).",
218 MakeDoubleChecker<double>())
219 .AddAttribute(
"MaxFrames",
220 "Maximum number of frames to include in a single RTS.",
223 MakeUintegerChecker<uint32_t>())
224 .AddAttribute(
"QueueLimit",
225 "Maximum packets to queue at MAC.",
228 MakeUintegerChecker<uint32_t>())
229 .AddAttribute(
"SIFS",
230 "Spacing to give between frames (this should match gateway).",
234 .AddAttribute(
"NumberOfRates",
235 "Number of rate divisions supported by each PHY.",
238 MakeUintegerChecker<uint32_t>())
239 .AddAttribute(
"MinRetryRate",
240 "Smallest allowed RTS retry rate.",
243 MakeDoubleChecker<double>())
244 .AddAttribute(
"RetryStep",
245 "Retry rate increment.",
248 MakeDoubleChecker<double>())
249 .AddAttribute(
"MaxPropDelay",
250 "Maximum possible propagation delay to gateway.",
254 .AddTraceSource(
"Enqueue",
255 "A (data) packet arrived at MAC for transmission.",
257 "ns3::UanMacRc::QueueTracedCallback")
258 .AddTraceSource(
"Dequeue",
259 "A (data) packet was passed down to PHY from MAC.",
261 "ns3::UanMacRc::QueueTracedCallback")
262 .AddTraceSource(
"RX",
263 "A packet was destined for and received at this MAC layer.",
265 "ns3::UanMac::PacketModeTracedCallback");
280 if (protocolNumber > 0)
282 NS_LOG_WARN(
"Warning: UanMacRc does not support multiple protocols. protocolNumber "
283 "argument to Enqueue is being ignored");
330 pkt->RemoveHeader(ch);
344 <<
" UanMacRc Receiving DATA packet from PHY");
346 pkt->RemoveHeader(dh);
358 pkt->RemoveHeader(ctsg);
366 if (winDelay >
Time(0))
374 <<
" Received window period < 0");
379 while (pkt->GetSize() > 0)
381 pkt->RemoveHeader(ctsh);
397 <<
" received CTS while state != RTSSENT or GWPING");
427 std::list<Reservation>::iterator it =
m_resList.begin();
439 <<
" received CTS packet with no corresponding reservation!");
443 <<
" received CTS packet. Scheduling data");
444 it->SetTransmitted();
457 const std::list<std::pair<Ptr<Packet>,
Mac8Address>> l = it->GetPktList();
458 std::list<std::pair<Ptr<Packet>,
Mac8Address>>::const_iterator pit;
461 for (uint8_t i = 0; i < it->GetNoFrames(); i++, pit++)
476 Time eventTime = startDelay + frameDelay;
477 if (eventTime <
Time(0))
480 "Scheduling error resulted in very negative data transmission time! eventTime = "
485 <<
" scheduling with delay " << eventTime.
As(
Time::S) <<
" propDelay "
487 <<
" arrival time " << arrTime.
As(
Time::S));
489 frameDelay = frameDelay +
m_sifs +
Seconds(pkt->GetSize() / currentBps);
535 << pkt->GetSize() <<
" byte packet of type " << type <<
" with rate " << rate
536 <<
"(" <<
m_phy->GetMode(rate).GetDataRateBps() <<
") to " << ch.
GetDest());
538 m_phy->SendPacket(pkt, rate);
545 ack->RemoveHeader(ah);
547 std::list<Reservation>::iterator it =
m_resList.begin();
558 <<
" could not find reservation corresponding to received ACK");
561 if (!it->IsTransmitted())
567 const std::list<std::pair<Ptr<Packet>,
Mac8Address>> l = it->GetPktList();
568 std::list<std::pair<Ptr<Packet>,
Mac8Address>>::const_iterator pit;
572 std::set<uint8_t>::iterator nit = nacks.begin();
574 for (; nit != nacks.end(); nit++)
577 <<
" Received NACK for " << (
uint32_t)*nit);
591 <<
" received ACK for all frames");
601 rh.
SetLength(
static_cast<uint16_t
>(res.GetLength()));
602 rh.
SetNoFrames(
static_cast<uint8_t
>(res.GetNoFrames()));
655 res.IncrementRetry();
713 if (phyDual->IsPhy1Rx())
747 <<
" tried to retry RTS with empty reservation list");
755 res.IncrementRetry();
a polymophic address class
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
double GetValue(double mean, double bound)
Get the next random value drawn from the distribution.
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.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Stores reservation info for use in scheduling data channel by reservation channel MAC.
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
uint32_t GetLength() const
Get the total length of the Reservation.
~Reservation()
Destructor.
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktList
Queued packets for each address.
bool m_transmitted
Has this reservation been transmitted.
const std::list< std::pair< Ptr< Packet >, Mac8Address > > & GetPktList() const
Get the list of packets.
Reservation()
Default constructor.
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n'th RTS.
uint8_t GetFrameNo() const
Get the frame number.
void IncrementRetry()
Increment the retry count.
uint8_t m_frameNo
Frame number.
void SetFrameNo(uint8_t fn)
Set the frame number.
bool IsTransmitted() const
uint8_t m_retryNo
Number of retries.
uint8_t GetRetryNo() const
Get the retry number.
uint32_t m_length
Total length of queued packets.
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
void AddTimestamp(Time t)
Set the time of the latest RTS sent.
std::vector< Time > m_timestamp
Timestamps for each retry.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
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.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Virtual base class for all UAN MAC protocols.
virtual Address GetAddress()
Get the MAC Address.
Non-gateway node MAC for reservation channel MAC protocol.
void Clear() override
Clears all pointer references.
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
void ReceiveOkFromPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok Callback.
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb) override
Set the callback to forward packets up to higher layers.
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
EventId m_startAgain
(Unused).
void BlockRtsing()
Callback to block RST.
TracedCallback< Ptr< const Packet >, uint32_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
uint32_t m_queueLimit
Maximum packets to queue at MAC.
void AttachPhy(Ptr< UanPhy > phy) override
Attach PHY layer to this MAC.
void RtsTimeout()
Retry RTS.
EventId m_rtsEvent
The RTS event.
uint8_t m_frameNo
Current frame number.
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
void DoDispose() override
Destructor implementation.
double m_minRetryRate
Smallest allowed RTS retry rate.
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktQueue
Pending packets.
double m_retryStep
Retry rate increment.
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
The callback to forward a packet up to higher layer.
UanMacRc()
Default constructor.
void AssociateTimeout()
Periodically retry association.
~UanMacRc() override
Dummy destructor, DoDispose.
void Associate()
Associate with a gateway by sending the first GWPING.
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
bool IsPhy1Ok()
Check that PHY is ok: not CTS or ACK not to my address.
void SendRts()
Send RTS packet.
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Time m_learnedProp
Propagation delay to gateway.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest) override
Enqueue packet to be transmitted.
bool m_rtsBlocked
RTS blocked while processing ACK.
@ TYPE_GWPING
Gateway ping.
std::list< Reservation > m_resList
List of scheduled reservations.
TracedCallback< Ptr< const Packet >, uint32_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Mac8Address m_assocAddr
Next hop address.
bool m_cleared
Flag when we've been cleared.
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
@ IDLE
Finished scheduling packet sends.
@ GWPSENT
Associated with gateway.
@ UNASSOCIATED
Initial state.
uint32_t m_numRates
Number of rates per Phy layer.
static TypeId GetTypeId()
Register this type.
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,...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#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 ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#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.
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.
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...