|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
28 #include "ns3/assert.h"
30 #include "ns3/trace-source-accessor.h"
31 #include "ns3/nstime.h"
32 #include "ns3/double.h"
33 #include "ns3/uinteger.h"
86 std::map<Mac8Address, AckData>::iterator it =
m_ackData.begin ();
89 it->second.rxFrames.clear ();
107 .SetGroupName (
"Uan")
109 .AddAttribute (
"MaxReservations",
110 "Maximum number of reservations to accept per cycle.",
113 MakeUintegerChecker<uint32_t> ())
114 .AddAttribute (
"NumberOfRates",
115 "Number of rates per Phy layer.",
118 MakeUintegerChecker<uint32_t> ())
119 .AddAttribute (
"MaxPropDelay",
120 "Maximum propagation delay between gateway and non-gateway nodes.",
124 .AddAttribute (
"SIFS",
125 "Spacing between frames to account for timing error and processing delay.",
129 .AddAttribute (
"NumberOfNodes",
130 "Number of non-gateway nodes in this gateway's neighborhood.",
133 MakeUintegerChecker<uint32_t> ())
134 .AddAttribute (
"MinRetryRate",
135 "Smallest allowed RTS retry rate.",
138 MakeDoubleChecker<double> ())
139 .AddAttribute (
"RetryStep",
140 "Retry rate increment.",
143 MakeDoubleChecker<double> ())
144 .AddAttribute (
"TotalRate",
145 "Total available channel rate in bps (for a single channel, without splitting reservation channel).",
148 MakeUintegerChecker<uint32_t> ())
149 .AddAttribute (
"RateStep",
150 "Increments available for rate assignment in bps.",
153 MakeUintegerChecker<uint32_t> ())
154 .AddAttribute (
"FrameSize",
155 "Size of data frames in bytes.",
158 MakeUintegerChecker<uint32_t> ())
159 .AddTraceSource (
"RX",
160 "A packet was destined for and received at this MAC layer.",
162 "ns3::UanMac::PacketModeTracedCallback")
163 .AddTraceSource (
"Cycle",
164 "Trace cycle statistics.",
166 "ns3::UanMacRcGw::CycleCallback")
178 NS_LOG_WARN (
"RCMAC Gateway transmission to acoustic nodes is not yet implemented");
277 NS_FATAL_ERROR (
"Received CTS at GW. Currently only support single GW network!");
280 NS_FATAL_ERROR (
"Received ACK at GW. Currently only support single GW network!");
290 uint32_t numRts =
static_cast<uint32_t
> (
m_sortedRes.size ());
302 uint32_t totalBytes = 0;
303 uint32_t totalFrames = 0;
307 std::map<Mac8Address, Request>::iterator rit =
m_requests.begin ();
310 totalBytes += (*rit).second.length;
311 totalFrames += (*rit).second.numFrames;
328 double temprate = (thCtlRate - minRate) / ((
double)
m_rateStep) + 0.5;
335 NS_LOG_DEBUG (
"Found theoretical alpha: " << thAlpha <<
" Found associated rate = " << thCtlRate <<
" Giving rate number: " << temprate);
343 NS_LOG_WARN (
"Gateway found optimum RTS retry rate is below minimum");
356 Time winSize =
Seconds (totalBytes * 8.0 / dataRate) +
m_sifs * totalFrames + pDelay;
365 Time cycleSeconds = winSize + ((totalFrames + 1.0) *
m_sifs) +
401 std::set<std::pair<Time, Mac8Address> >::iterator it =
m_sortedRes.begin ();
402 Time minPdelay = (*it).first;
408 Time pdelay = (*it).first;
414 m_ackData.insert (std::make_pair (dest, newData));
416 Time earliestArr = ctsTxTimeTotal + pdelay + pdelay +
m_sifs;
417 Time arrivalTime =
std::max (earliestArr, nextEarliest);
418 NS_LOG_DEBUG (
Now ().As (
Time::S) <<
" GW: Scheduling request for prop. delay " << pdelay.
As (
Time::S) <<
" for " << (*it).second <<
" Earliest possible arrival=" << earliestArr.
As (
Time::S) <<
" Next arrival time=" << nextEarliest.
As (
Time::S));
430 " GW Scheduling reception for " << (uint32_t) req.
numFrames <<
431 " frames at " << (
Simulator::Now () + arrivalTime).As (
Time::S) <<
" (delaytiltx of " << arrivalTime.
As (
Time::S) <<
") Total length is " << req.
length <<
" with txtime " << req.
length * 8 / dataRate <<
" seconds");
470 std::map<Mac8Address, AckData>::iterator it =
m_ackData.begin ();
476 std::list<uint32_t> toNack;
477 for (uint8_t i = 0; i <
data.expFrames; i++)
479 if (
data.rxFrames.find (i) ==
data.rxFrames.end ())
481 toNack.push_back (i);
490 std::list<uint32_t>::iterator nit = toNack.begin ();
491 for (; nit != toNack.end (); nit++)
500 nextAck = nextAck + ackTime +
m_sifs;
534 m_phy->SendPacket (pkt, rate);
543 double lrae =
m_rtsSize * 8.0 * a * std::exp (1.0);
544 if (totalFrames == 0)
560 if (alpha < 0 || alpha > 1)
573 std::vector<double> pds;
574 std::map<Mac8Address, Time>::iterator pdit =
m_propDelay.begin ();
578 pds.push_back (pdit->second.GetSeconds ());
585 std::sort (pds.begin (), pds.end ());
587 std::vector<double> exppdk;
589 for (uint32_t
k = 1;
k <=
n;
k++)
592 exppdk.push_back (pds[ind]);
604 double expk =
n * (1 - std::exp (-((
double) a) / (
double)
n));
608 double expdata = 8 * ld * expk;
615 for (uint32_t i = 1; i <=
n; i++)
621 double s = (1.0 /
m_totalRate) * expdata / exptime;
636 for (uint32_t i = 1; i <=
n -
k + 1; i++)
638 double nChK =
static_cast<double> (
NchooseK (
n,
k));
639 double p = (nChK > 0) ? (
static_cast<double> (
NchooseK (
n - i,
k - 1)) / nChK) : DBL_MAX;
642 return (uint32_t)(sum + 0.5);
649 return nck * std::pow ( (std::exp ( (
double) a / (
double)
n) - 1.0), (
double)
k) * std::exp (-( (
double) a));
658 for (uint32_t
k = 1;
k <=
n;
k++)
663 double term = pik * num / denom;
685 for (uint32_t i = 1; i <=
k; i++)
687 accum = accum * (
n -
k + i) / i;
690 return (uint64_t)(accum + 0.5);
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
double m_minRetryRate
Smallest allowed RTS retry rate.
A class used for addressing MAC8 MAC's.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
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.
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
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.
std::set< std::pair< Time, Mac8Address > > m_sortedRes
Queued request times.
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.
uint8_t numFrames
Number of frames.
uint32_t m_rateStep
Increments available for rate assignment in bps.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
uint32_t m_currentRateNum
Rate number corresponding to data rate of current cycle.
uint32_t CompExpMinIndex(uint32_t n, uint32_t k)
Index to the k'th expected delay among n nodes.
void ReceivePacket(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok callback.
@ IDLE
Initial idle state.
virtual ~UanMacRcGw()
Dummy destructor, see DoDispose.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
virtual void DoDispose()
Destructor implementation.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
static TypeId GetTypeId(void)
Register this type.
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< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb)
Set the callback to forward packets up to higher layers.
TracedCallback< Time, Time, uint32_t, uint32_t, double, uint32_t, double > m_cycleLogger
A packet was destined for and received at this MAC layer.
uint64_t NchooseK(uint32_t n, uint32_t k)
Binomial coefficient.
void CycleStarted(void)
Set state to INCYCLE.
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send packet on PHY.
uint32_t m_ackSize
Size of UanHeaderCommon and UanHeaderRcAck.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
uint8_t frameNo
Current frame number.
@ IDLE
Channel is IDLE, no packet is being transmitted.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
a polymophic address class
virtual Address GetAddress(void)
Get the MAC Address.
@ INCYCLE
Cycling through nodes.
Time rxTime
Time request received.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
uint32_t FindOptA(void)
Compute the optimum maximum number of reservations to accept per cycle.
#define NS_UNUSED(x)
Mark a local variable as unused.
State m_state
Gateway processing state.
Simulation virtual time values and global simulation resolution.
bool m_cleared
Flag when we've been cleared.
uint32_t m_totalRate
Total available channel rate in bps (for a single channel, without splitting reservation channel).
virtual bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest)
Enqueue packet to be transmitted.
Abstraction of packet modulation information.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
uint32_t m_numRates
Number of rates per Phy layer.
std::vector< double > GetExpPdk(void)
Get the expected propagation delay to each node.
uint32_t m_numNodes
Number of non-gateway nodes in this gateway's neighborhood.
Time m_maxDelta
Maximum propagation delay between gateway and non-gateway nodes .
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...
uint32_t m_rtsSize
Size of UanHeaderCommon and UanHeaderRcRts.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
void EndCycle(void)
End cycle by scheduling pending ACKs.
std::map< Mac8Address, Request > m_requests
Request for each node.
uint32_t m_frameSize
Size of data frames in bytes.
double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector< double > deltaK)
Numeric function.
std::map< Mac8Address, Time > m_propDelay
Propagation delay to each node.
uint16_t length
Request header length.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
double ComputeAlpha(uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
Compute alpha parameter.
Virtual base class for all UAN MAC protocols.
Time Seconds(double value)
Construct a Time in the indicated unit.
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
uint8_t expFrames
Expected number of frames.
void StartCycle(void)
Cycle through pending requests.
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).
double ComputeExpS(uint32_t a, uint32_t ld, std::vector< double > exppdk)
Throughput for a reservations with framesize ld, given expected delays exppdk.
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Hold an unsigned integer type.
double ComputePiK(uint32_t a, uint32_t n, uint32_t k)
Numeric function.
uint8_t frameNo
Frame number being ACK'ed.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
void ReceiveError(Ptr< Packet > pkt, double sinr)
PHY receive error callback.
Time m_sifs
Spacing between frames to account for timing error and processing delay.
std::map< Mac8Address, AckData > m_ackData
AckData for each node.
uint16_t m_currentRetryRate
Retry rate number for current cycle.
virtual void DoDispose(void)
Destructor implementation.
uint32_t m_maxRes
Maximum number of reservations to accept per cycle.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
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.
virtual void Clear(void)
Clears all pointer references.
double m_retryStep
Retry rate increment.
uint8_t retryNo
Retry number.