|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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"
56 : m_frameNo (frameNo),
60 uint32_t numPkts = (maxPkts) ? maxPkts :
static_cast<uint32_t
> (
list.size ());
65 for (uint32_t i = 0; i < numPkts; i++)
67 length +=
list.front ().first->GetSize () +
78 std::list<std::pair <Ptr<Packet>,
Mac8Address > >::iterator it;
89 return static_cast<uint32_t
> (
m_pktList.size ());
98 const std::list<std::pair <Ptr<Packet>,
Mac8Address > > &
157 m_state (UNASSOCIATED),
158 m_rtsBlocked (false),
163 m_ev = CreateObject<ExponentialRandomVariable> ();
190 std::list<std::pair <Ptr<Packet>,
Mac8Address > >::iterator it;
213 .SetGroupName (
"Uan")
215 .AddAttribute (
"RetryRate",
216 "Number of retry attempts per second (of RTS/GWPING).",
219 MakeDoubleChecker<double> ())
220 .AddAttribute (
"MaxFrames",
221 "Maximum number of frames to include in a single RTS.",
224 MakeUintegerChecker<uint32_t> ())
225 .AddAttribute (
"QueueLimit",
226 "Maximum packets to queue at MAC.",
229 MakeUintegerChecker<uint32_t> ())
230 .AddAttribute (
"SIFS",
231 "Spacing to give between frames (this should match gateway).",
235 .AddAttribute (
"NumberOfRates",
236 "Number of rate divisions supported by each PHY.",
239 MakeUintegerChecker<uint32_t> ())
240 .AddAttribute (
"MinRetryRate",
241 "Smallest allowed RTS retry rate.",
244 MakeDoubleChecker<double> ())
245 .AddAttribute (
"RetryStep",
246 "Retry rate increment.",
249 MakeDoubleChecker<double> ())
250 .AddAttribute (
"MaxPropDelay",
251 "Maximum possible propagation delay to gateway.",
255 .AddTraceSource (
"Enqueue",
256 "A (data) packet arrived at MAC for transmission.",
258 "ns3::UanMacRc::QueueTracedCallback")
259 .AddTraceSource (
"Dequeue",
260 "A (data) packet was passed down to PHY from MAC.",
262 "ns3::UanMacRc::QueueTracedCallback")
263 .AddTraceSource (
"RX",
264 "A packet was destined for and received at this MAC layer.",
266 "ns3::UanMac::PacketModeTracedCallback")
282 if (protocolNumber > 0)
284 NS_LOG_WARN (
"Warning: UanMacRc does not support multiple protocols. protocolNumber argument to Enqueue is being ignored");
346 " UanMacRc Receiving DATA packet from PHY");
369 if (winDelay >
Time (0))
400 " received CTS while state != RTSSENT or GWPING");
430 std::list<Reservation>::iterator it =
m_resList.begin ();
442 " received CTS packet with no corresponding reservation!");
447 " received CTS packet. Scheduling data");
448 it->SetTransmitted ();
462 const std::list<std::pair <Ptr<Packet>,
Mac8Address > > l = it->GetPktList ();
463 std::list<std::pair <Ptr<Packet>,
Mac8Address > >::const_iterator pit;
468 for (uint8_t i = 0; i < it->GetNoFrames (); i++, pit++)
483 Time eventTime = startDelay + frameDelay;
484 if (eventTime <
Time (0))
486 NS_FATAL_ERROR (
"Scheduling error resulted in very negative data transmission time! eventTime = " << eventTime.
As (
Time::S));
490 " scheduling with delay " << eventTime.
As (
Time::S) <<
492 " start delay " << startDelay.
As (
Time::S) <<
493 " arrival time " << arrTime.
As (
Time::S));
543 " transmitting " << pkt->
GetSize () <<
544 " byte packet of type " << type <<
" with rate " << rate <<
545 "(" <<
m_phy->GetMode (rate).GetDataRateBps () <<
") to " << ch.
GetDest ());
547 m_phy->SendPacket (pkt, rate);
556 std::list<Reservation>::iterator it =
m_resList.begin ();
566 NS_LOG_DEBUG (
"In " << __func__ <<
" could not find reservation corresponding to received ACK");
569 if (!it->IsTransmitted ())
575 const std::list<std::pair <Ptr<Packet>,
Mac8Address > > l = it->GetPktList ();
576 std::list<std::pair <Ptr<Packet>,
Mac8Address > >::const_iterator pit;
580 std::set<uint8_t>::iterator nit = nacks.begin ();
582 for (; nit != nacks.end (); nit++)
586 " Received NACK for " << (uint32_t) *nit);
601 " received ACK for all frames");
716 if (phyDual->IsPhy1Rx ())
752 " tried to retry RTS with empty reservation list");
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest)
Enqueue packet to be transmitted.
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
A class used for addressing MAC8 MAC's.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
void SetFrameNo(uint8_t fn)
Set the frame number.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
void ProcessAck(Ptr< Packet > ack)
Process a received ACK.
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb)
Set the callback to forward packets up to higher layers.
EventId m_startAgain
(Unused).
void ReceiveOkFromPhy(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok Callback.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void AddHeader(const Header &header)
Add header to this packet.
Ptr< ExponentialRandomVariable > m_ev
Provides exponential random variables.
void ScheduleData(const UanHeaderRcCts &ctsh, const UanHeaderRcCtsGlobal &ctsg, uint32_t ctsBytes)
Schedule Packet sends.
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetTransmitted(bool t=true)
Set the reservation transmitted state.
void SendRts(void)
Send RTS packet.
Mac8Address m_assocAddr
Next hop address.
uint8_t m_frameNo
Frame number.
Time m_sifs
Spacing between frames to account for timing error and processing delay.
uint8_t m_retryNo
Number of retries.
uint8_t GetRetryNo() const
Get the retry number.
~Reservation()
Destructor.
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
uint8_t m_frameNo
Current frame number.
static TypeId GetTypeId(void)
Register this type.
uint32_t m_currentRate
Rate number corresponding to data rate of current cycle.
const std::list< std::pair< Ptr< Packet >, Mac8Address > > & GetPktList(void) const
Get the list of packets.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
uint32_t GetNoFrames() const
Get the number of frames in this Reservation.
virtual ~UanMacRc()
Dummy destructor, DoDispose.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
uint32_t GetLength() const
Get the total length of the Reservation.
void AddTimestamp(Time t)
Set the time of the latest RTS sent.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
std::list< Reservation > m_resList
List of scheduled reservations.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
@ IDLE
Finished scheduling packet sends.
Time m_learnedProp
Propagation delay to gateway.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
UanMacRc()
Default constructor.
a polymophic address class
uint32_t m_queueLimit
Maximum packets to queue at MAC.
virtual Address GetAddress(void)
Get the MAC Address.
void IncrementRetry()
Increment the retry count.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
#define NS_UNUSED(x)
Mark a local variable as unused.
bool m_cleared
Flag when we've been cleared.
uint8_t GetFrameNo() const
Get the frame number.
bool IsPhy1Ok(void)
Check that PHY is ok: not CTS or ACK not to my address.
void RtsTimeout(void)
Retry RTS.
Simulation virtual time values and global simulation resolution.
Abstraction of packet modulation information.
Stores reservation info for use in scheduling data channel by reservation channel MAC.
UanHeaderRcRts CreateRtsHeader(const Reservation &res)
Create the RTS header from a Reservation.
void AssociateTimeout(void)
Periodically retry association.
TracedCallback< Ptr< const Packet >, uint32_t > m_enqueueLogger
A packet arrived at the MAC for transmission.
double m_minRetryRate
Smallest allowed RTS retry rate.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Time GetTimestamp(uint8_t n) const
Get the timestamp for the n'th RTS.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktList
Queued packets for each address.
EventId m_rtsEvent
The RTS event.
void Associate(void)
Associate with a gateway by sending the first GWPING.
Non-gateway node MAC for reservation channel MAC protocol.
void DoDispose()
Destructor implementation.
uint32_t m_numRates
Number of rates per Phy layer.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
@ UNASSOCIATED
Initial state.
Virtual base class for all UAN MAC protocols.
Time Seconds(double value)
Construct a Time in the indicated unit.
double m_retryStep
Retry rate increment.
@ GWPSENT
Associated with gateway.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t m_length
Total length of queued packets.
bool IsTransmitted() const
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
The callback to forward a packet up to higher layer.
virtual void Clear(void)
Clears all pointer references.
TracedCallback< Ptr< const Packet >, uint32_t > m_dequeueLogger
A was passed down to the PHY from the MAC.
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send on packet on the PHY.
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Reservation()
Default constructor.
AttributeValue implementation for Time.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
static Mac8Address GetBroadcast(void)
Get the broadcast address (255).
void BlockRtsing(void)
Callback to block RST.
static uint32_t m_cntrlSends
Global count of calls to Associate, AssociateTimeout, SendRts, and RtsTimeout.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Hold an unsigned integer type.
std::list< std::pair< Ptr< Packet >, Mac8Address > > m_pktQueue
Pending packets.
bool m_rtsBlocked
RTS blocked while processing ACK.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
double m_retryRate
Number of retry attempts per second (of RTS/GWPING.
double GetValue(double mean, double bound)
Get the next random value, as a double from the exponential distribution with the specified mean and ...
std::vector< Time > m_timestamp
Timestamps for each retry.
bool m_transmitted
Has this reservation been transmitted.
virtual void DoDispose(void)
Destructor implementation.
uint32_t m_maxFrames
Maximum number of frames to include in a single RTS.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
@ TYPE_GWPING
Gateway ping.