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"
92 std::map<UanAddress, AckData>::iterator it =
m_ackData.begin ();
95 it->second.rxFrames.clear ();
113 .AddConstructor<UanMacRcGw> ()
114 .AddAttribute (
"MaxReservations",
115 "Maximum number of reservations to accept per cycle",
118 MakeUintegerChecker<uint32_t> ())
119 .AddAttribute (
"NumberOfRates",
120 "Number of rates per Phy layer",
123 MakeUintegerChecker<uint32_t> ())
124 .AddAttribute (
"RetryRate",
125 "Number of retry rates per second at non-gateway nodes",
128 MakeDoubleChecker<double> ())
129 .AddAttribute (
"MaxPropDelay",
130 "Maximum propagation delay between gateway and non-gateway nodes",
134 .AddAttribute (
"SIFS",
135 "Spacing between frames to account for timing error and processing delay",
139 .AddAttribute (
"NumberOfNodes",
140 "Number of non-gateway nodes in this gateway's neighborhood",
143 MakeUintegerChecker<uint32_t> ())
144 .AddAttribute (
"MinRetryRate",
145 "Smallest allowed RTS retry rate",
148 MakeDoubleChecker<double> ())
149 .AddAttribute (
"RetryStep",
150 "Retry rate increment",
153 MakeDoubleChecker<double> ())
154 .AddAttribute (
"NumberOfRetryRates",
155 "Number of retry rates",
158 MakeUintegerChecker<uint16_t> ())
159 .AddAttribute (
"TotalRate",
160 "Total available channel rate in bps (for a single channel, without splitting reservation channel)",
163 MakeUintegerChecker<uint32_t> ())
164 .AddAttribute (
"RateStep",
165 "Increments available for rate assignment in bps",
168 MakeUintegerChecker<uint32_t> ())
169 .AddAttribute (
"FrameSize",
170 "Size of data frames in bytes",
173 MakeUintegerChecker<uint32_t> ())
174 .AddTraceSource (
"RX",
175 "A packet was destined for and received at this MAC layer",
177 .AddTraceSource (
"Cycle",
178 "Trace cycle statistics",
201 NS_LOG_WARN (
"RCMAC Gateway transmission to acoustic nodes is not yet implemented");
304 NS_FATAL_ERROR (
"Received CTS at GW. Currently only support single GW network!");
307 NS_FATAL_ERROR (
"Received ACK at GW. Currently only support single GW network!");
329 uint32_t totalBytes = 0;
330 uint32_t totalFrames = 0;
334 std::map<UanAddress, Request>::iterator rit =
m_requests.begin ();
337 totalBytes += (*rit).second.length;
338 totalFrames += (*rit).second.numFrames;
340 pDelay = 2 *
m_sortedRes.begin ()->first.GetSeconds ();
355 double temprate = (thCtlRate - minRate) / ((
double)
m_rateStep) + 0.5;
362 NS_LOG_DEBUG (
"Found theoretical alpha: " << thAlpha <<
" Found associated rate = " << thCtlRate <<
" Giving rate number: " << temprate);
370 NS_LOG_WARN (
"Gateway found optimum RTS retry rate is below minimum");
383 double winSize = (double)(totalBytes) * 8.0 / dataRate +
m_sifs.
GetSeconds () * totalFrames + pDelay;
422 std::set<std::pair<Time, UanAddress> >::iterator it =
m_sortedRes.begin ();
423 Time minPdelay = (*it).first;
429 Time pdelay = (*it).first;
435 m_ackData.insert (std::make_pair (dest, newData));
437 Time earliestArr = ctsTxTimeTotal + pdelay + pdelay +
m_sifs;
438 Time arrivalTime = std::max (earliestArr, nextEarliest);
444 ctsh.SetRtsTimeStamp (req.
rxTime);
447 ctsh.SetDelayToTx (arrivalTime);
489 std::map<UanAddress, AckData>::iterator it =
m_ackData.begin ();
495 std::list<uint32_t> toNack;
496 for (uint32_t i = 0; i < data.
expFrames; i++)
500 toNack.push_back (i);
509 std::list<uint32_t>::iterator nit = toNack.begin ();
510 for (; nit != toNack.end (); nit++)
519 nextAck = nextAck + ackTime +
m_sifs;
562 double lrae =
m_rtsSize * 8.0*a*std::exp (1.0);
563 if (totalFrames == 0)
579 if (alpha < 0 || alpha > 1)
584 NS_ASSERT_MSG (alpha > 0 && alpha < 1,
"Error computing alpha. Alpha out of valid range!");
592 std::vector<double> pds;
593 std::map<UanAddress, Time>::iterator pdit =
m_propDelay.begin ();
597 pds.push_back (pdit->second.GetSeconds ());
604 std::sort (pds.begin (), pds.end ());
606 std::vector<double> exppdk;
608 for (uint32_t k = 1; k <= n; k++)
611 exppdk.push_back (pds[ind]);
623 double expk = n * (1 - std::exp (-((
double) a) / (
double) n));
627 double expdata = 8 * ld * expk;
634 for (uint32_t i = 1; i <= n; i++)
640 double s = (1.0 /
m_totalRate) * expdata / exptime;
655 for (uint32_t i = 1; i <= n - k + 1; i++)
660 return (uint32_t)(sum + 0.5);
666 double nck = (double)
NchooseK (n, k);
667 return nck * std::pow ( (std::exp ( (
double) a / (
double) n) - 1.0), (
double) k) * std::exp (-( (
double) a));
676 for (uint32_t k = 1; k <= n; k++)
681 double term = pik * num / denom;
703 for (uint32_t i = 1; i <= k; i++)
705 accum = accum * (n - k + i) / i;
708 return (uint64_t)(accum + 0.5);