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"
93 std::map<UanAddress, AckData>::iterator it =
m_ackData.begin ();
96 it->second.rxFrames.clear ();
114 .AddConstructor<UanMacRcGw> ()
115 .AddAttribute (
"MaxReservations",
116 "Maximum number of reservations to accept per cycle",
119 MakeUintegerChecker<uint32_t> ())
120 .AddAttribute (
"NumberOfRates",
121 "Number of rates per Phy layer",
124 MakeUintegerChecker<uint32_t> ())
125 .AddAttribute (
"MaxPropDelay",
126 "Maximum propagation delay between gateway and non-gateway nodes",
130 .AddAttribute (
"SIFS",
131 "Spacing between frames to account for timing error and processing delay",
135 .AddAttribute (
"NumberOfNodes",
136 "Number of non-gateway nodes in this gateway's neighborhood",
139 MakeUintegerChecker<uint32_t> ())
140 .AddAttribute (
"MinRetryRate",
141 "Smallest allowed RTS retry rate",
144 MakeDoubleChecker<double> ())
145 .AddAttribute (
"RetryStep",
146 "Retry rate increment",
149 MakeDoubleChecker<double> ())
150 .AddAttribute (
"TotalRate",
151 "Total available channel rate in bps (for a single channel, without splitting reservation channel)",
154 MakeUintegerChecker<uint32_t> ())
155 .AddAttribute (
"RateStep",
156 "Increments available for rate assignment in bps",
159 MakeUintegerChecker<uint32_t> ())
160 .AddAttribute (
"FrameSize",
161 "Size of data frames in bytes",
164 MakeUintegerChecker<uint32_t> ())
165 .AddTraceSource (
"RX",
166 "A packet was destined for and received at this MAC layer",
168 .AddTraceSource (
"Cycle",
169 "Trace cycle statistics",
192 NS_LOG_WARN (
"RCMAC Gateway transmission to acoustic nodes is not yet implemented");
295 NS_FATAL_ERROR (
"Received CTS at GW. Currently only support single GW network!");
298 NS_FATAL_ERROR (
"Received ACK at GW. Currently only support single GW network!");
320 uint32_t totalBytes = 0;
321 uint32_t totalFrames = 0;
325 std::map<UanAddress, Request>::iterator rit =
m_requests.begin ();
328 totalBytes += (*rit).second.length;
329 totalFrames += (*rit).second.numFrames;
331 pDelay = 2 *
m_sortedRes.begin ()->first.GetSeconds ();
346 double temprate = (thCtlRate - minRate) / ((
double)
m_rateStep) + 0.5;
353 NS_LOG_DEBUG (
"Found theoretical alpha: " << thAlpha <<
" Found associated rate = " << thCtlRate <<
" Giving rate number: " << temprate);
361 NS_LOG_WARN (
"Gateway found optimum RTS retry rate is below minimum");
374 double winSize = (double)(totalBytes) * 8.0 / dataRate +
m_sifs.
GetSeconds () * totalFrames + pDelay;
386 Time ctsTxTimeTotal = Seconds (
m_ctsSizeN * 8.0 * numRts / dataRate) + ctsTxTimeG;
413 std::set<std::pair<Time, UanAddress> >::iterator it =
m_sortedRes.begin ();
414 Time minPdelay = (*it).first;
420 Time pdelay = (*it).first;
426 m_ackData.insert (std::make_pair (dest, newData));
428 Time earliestArr = ctsTxTimeTotal + pdelay + pdelay +
m_sifs;
429 Time arrivalTime = std::max (earliestArr, nextEarliest);
431 nextEarliest = arrivalTime + Seconds (req.
length * 8.0 / dataRate) + Seconds (m_sifs.GetSeconds () * req.
numFrames);
435 ctsh.SetRtsTimeStamp (req.
rxTime);
438 ctsh.SetDelayToTx (arrivalTime);
476 Time nextAck = Seconds (0);
480 std::map<UanAddress, AckData>::iterator it =
m_ackData.begin ();
486 std::list<uint32_t> toNack;
487 for (uint32_t i = 0; i < data.
expFrames; i++)
491 toNack.push_back (i);
500 std::list<uint32_t>::iterator nit = toNack.begin ();
501 for (; nit != toNack.end (); nit++)
510 nextAck = nextAck + ackTime +
m_sifs;
544 m_phy->SendPacket (pkt, rate);
553 double lrae =
m_rtsSize * 8.0 * a * std::exp (1.0);
554 if (totalFrames == 0)
570 if (alpha < 0 || alpha > 1)
575 NS_ASSERT_MSG (alpha > 0 && alpha < 1,
"Error computing alpha. Alpha out of valid range!");
583 std::vector<double> pds;
584 std::map<UanAddress, Time>::iterator pdit =
m_propDelay.begin ();
588 pds.push_back (pdit->second.GetSeconds ());
595 std::sort (pds.begin (), pds.end ());
597 std::vector<double> exppdk;
599 for (uint32_t k = 1; k <= n; k++)
602 exppdk.push_back (pds[ind]);
614 double expk = n * (1 - std::exp (-((
double) a) / (
double) n));
618 double expdata = 8 * ld * expk;
625 for (uint32_t i = 1; i <= n; i++)
646 for (uint32_t i = 1; i <= n - k + 1; i++)
649 double p = (nChK > 0) ? (
NchooseK (n - i, k - 1) / nChK) : DBL_MAX;
652 return (uint32_t)(sum + 0.5);
658 double nck = (double)
NchooseK (n, k);
659 return nck * std::pow ( (std::exp ( (
double) a / (
double) n) - 1.0), (
double) k) * std::exp (-( (
double) a));
668 for (uint32_t k = 1; k <= n; k++)
673 double term = pik * num / denom;
695 for (uint32_t i = 1; i <= k; i++)
697 accum = accum * (n - k + i) / i;
700 return (uint64_t)(accum + 0.5);
std::set< std::pair< Time, UanAddress > > m_sortedRes
uint32_t RemoveHeader(Header &header)
keep track of time values and allow control of global simulation resolution
virtual void AttachPhy(Ptr< UanPhy > phy)
#define NS_LOG_FUNCTION(parameters)
uint32_t CompExpMinIndex(uint32_t n, uint32_t k)
TracedCallback< Time, Time, uint32_t, uint32_t, double, uint32_t, double > m_cycleLogger
int64_t AssignStreams(int64_t stream)
#define NS_LOG_COMPONENT_DEFINE(name)
std::map< UanAddress, Time > m_propDelay
uint32_t GetSize(void) const
uint16_t m_currentRetryRate
virtual void DoDispose(void)
bool operator<(const Room &a, const Room &b)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual Address GetBroadcast(void) const
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
#define NS_FATAL_ERROR(msg)
fatal error handling
a polymophic address class
std::vector< double > GetExpPdk(void)
void ReceiveError(Ptr< Packet > pkt, double sinr)
double GetSeconds(void) const
double ComputeExpS(uint32_t a, uint32_t ld, std::vector< double > exppdk)
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Virtual base class for all UAN MAC protocols.
virtual Address GetAddress(void)
uint64_t NchooseK(uint32_t n, uint32_t k)
hold objects of type ns3::Time
Hold an unsigned integer type.
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
Abstraction of packet modulation information.
void ReceivePacket(Ptr< Packet > pkt, double sinr, UanTxMode mode)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
virtual void SetAddress(UanAddress addr)
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
uint32_t m_currentRateNum
static UanAddress GetBroadcast(void)
uint32_t PeekHeader(Header &header) const
uint8_t GetAsInt(void) const
static TypeId GetTypeId(void)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
std::map< UanAddress, Request > m_requests
#define NS_ASSERT_MSG(condition, message)
#define NS_LOG_DEBUG(msg)
double ComputePiK(uint32_t a, uint32_t n, uint32_t k)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range. Both limits are inclusive.
std::map< UanAddress, AckData > m_ackData
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
double ComputeAlpha(uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
Hold an floating point type.
std::set< uint8_t > rxFrames
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector< double > deltaK)
void AddHeader(const Header &header)
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)