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 (
"RetryRate",
126 "Number of retry rates per second at non-gateway nodes",
129 MakeDoubleChecker<double> ())
130 .AddAttribute (
"MaxPropDelay",
131 "Maximum propagation delay between gateway and non-gateway nodes",
135 .AddAttribute (
"SIFS",
136 "Spacing between frames to account for timing error and processing delay",
140 .AddAttribute (
"NumberOfNodes",
141 "Number of non-gateway nodes in this gateway's neighborhood",
144 MakeUintegerChecker<uint32_t> ())
145 .AddAttribute (
"MinRetryRate",
146 "Smallest allowed RTS retry rate",
149 MakeDoubleChecker<double> ())
150 .AddAttribute (
"RetryStep",
151 "Retry rate increment",
154 MakeDoubleChecker<double> ())
155 .AddAttribute (
"NumberOfRetryRates",
156 "Number of retry rates",
159 MakeUintegerChecker<uint16_t> ())
160 .AddAttribute (
"TotalRate",
161 "Total available channel rate in bps (for a single channel, without splitting reservation channel)",
164 MakeUintegerChecker<uint32_t> ())
165 .AddAttribute (
"RateStep",
166 "Increments available for rate assignment in bps",
169 MakeUintegerChecker<uint32_t> ())
170 .AddAttribute (
"FrameSize",
171 "Size of data frames in bytes",
174 MakeUintegerChecker<uint32_t> ())
175 .AddTraceSource (
"RX",
176 "A packet was destined for and received at this MAC layer",
178 .AddTraceSource (
"Cycle",
179 "Trace cycle statistics",
202 NS_LOG_WARN (
"RCMAC Gateway transmission to acoustic nodes is not yet implemented");
305 NS_FATAL_ERROR (
"Received CTS at GW. Currently only support single GW network!");
308 NS_FATAL_ERROR (
"Received ACK at GW. Currently only support single GW network!");
330 uint32_t totalBytes = 0;
331 uint32_t totalFrames = 0;
335 std::map<UanAddress, Request>::iterator rit =
m_requests.begin ();
338 totalBytes += (*rit).second.length;
339 totalFrames += (*rit).second.numFrames;
341 pDelay = 2 *
m_sortedRes.begin ()->first.GetSeconds ();
356 double temprate = (thCtlRate - minRate) / ((
double)
m_rateStep) + 0.5;
363 NS_LOG_DEBUG (
"Found theoretical alpha: " << thAlpha <<
" Found associated rate = " << thCtlRate <<
" Giving rate number: " << temprate);
371 NS_LOG_WARN (
"Gateway found optimum RTS retry rate is below minimum");
384 double winSize = (double)(totalBytes) * 8.0 / dataRate +
m_sifs.
GetSeconds () * totalFrames + pDelay;
396 Time ctsTxTimeTotal = Seconds (
m_ctsSizeN * 8.0 * numRts / dataRate) + ctsTxTimeG;
423 std::set<std::pair<Time, UanAddress> >::iterator it =
m_sortedRes.begin ();
424 Time minPdelay = (*it).first;
430 Time pdelay = (*it).first;
436 m_ackData.insert (std::make_pair (dest, newData));
438 Time earliestArr = ctsTxTimeTotal + pdelay + pdelay +
m_sifs;
439 Time arrivalTime = std::max (earliestArr, nextEarliest);
441 nextEarliest = arrivalTime + Seconds (req.
length * 8.0 / dataRate) + Seconds (m_sifs.GetSeconds () * req.
numFrames);
445 ctsh.SetRtsTimeStamp (req.
rxTime);
448 ctsh.SetDelayToTx (arrivalTime);
486 Time nextAck = Seconds (0);
490 std::map<UanAddress, AckData>::iterator it =
m_ackData.begin ();
496 std::list<uint32_t> toNack;
497 for (uint32_t i = 0; i < data.
expFrames; i++)
501 toNack.push_back (i);
510 std::list<uint32_t>::iterator nit = toNack.begin ();
511 for (; nit != toNack.end (); nit++)
520 nextAck = nextAck + ackTime +
m_sifs;
563 double lrae =
m_rtsSize * 8.0 * a * std::exp (1.0);
564 if (totalFrames == 0)
580 if (alpha < 0 || alpha > 1)
585 NS_ASSERT_MSG (alpha > 0 && alpha < 1,
"Error computing alpha. Alpha out of valid range!");
593 std::vector<double> pds;
594 std::map<UanAddress, Time>::iterator pdit =
m_propDelay.begin ();
598 pds.push_back (pdit->second.GetSeconds ());
605 std::sort (pds.begin (), pds.end ());
607 std::vector<double> exppdk;
609 for (uint32_t k = 1; k <= n; k++)
612 exppdk.push_back (pds[ind]);
624 double expk = n * (1 - std::exp (-((
double) a) / (
double) n));
628 double expdata = 8 * ld * expk;
635 for (uint32_t i = 1; i <= n; i++)
656 for (uint32_t i = 1; i <= n - k + 1; i++)
659 double p = (nChK > 0) ? (
NchooseK (n - i, k - 1) / nChK) : DBL_MAX;
662 return (uint32_t)(sum + 0.5);
668 double nck = (double)
NchooseK (n, k);
669 return nck * std::pow ( (std::exp ( (
double) a / (
double) n) - 1.0), (
double) k) * std::exp (-( (
double) a));
678 for (uint32_t k = 1; k <= n; k++)
683 double term = pik * num / denom;
705 for (uint32_t i = 1; i <= k; i++)
707 accum = accum * (n - k + i) / i;
710 return (uint64_t)(accum + 0.5);