A Discrete-Event Network Simulator
API
uan-mac-rc-gw.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Leonard Tracy <lentracy@gmail.com>
19  */
20 
21 #include "uan-mac-rc-gw.h"
22 #include "uan-mac-rc.h"
23 #include "uan-header-common.h"
24 #include "uan-header-rc.h"
25 #include "uan-phy.h"
26 #include "uan-tx-mode.h"
27 
28 #include "ns3/assert.h"
29 #include "ns3/log.h"
30 #include "ns3/trace-source-accessor.h"
31 #include "ns3/nstime.h"
32 #include "ns3/double.h"
33 #include "ns3/uinteger.h"
34 
35 #include <cfloat>
36 #include <utility>
37 #include <set>
38 #include <map>
39 #include <vector>
40 #include <algorithm>
41 
42 namespace ns3 {
43 
44 NS_LOG_COMPONENT_DEFINE ("UanMacRcGw");
45 
46 NS_OBJECT_ENSURE_REGISTERED (UanMacRcGw);
47 
49  : UanMac (),
50  m_state (IDLE),
51  m_currentRateNum (0),
52  m_cleared (false)
53 {
54  UanHeaderCommon ch;
55  UanHeaderRcRts rts;
56  UanHeaderRcCts cts;
57  UanHeaderRcAck ack;
59 
64 
65  NS_LOG_DEBUG ("Gateway initialized");
66 }
67 
69 {
70 }
71 
72 void
74 {
75  if (m_cleared)
76  {
77  return;
78  }
79  m_cleared = true;
80  if (m_phy)
81  {
82  m_phy->Clear ();
83  m_phy = 0;
84  }
85  m_propDelay.clear ();
86  std::map<Mac8Address, AckData>::iterator it = m_ackData.begin ();
87  for (; it != m_ackData.end (); it++)
88  {
89  it->second.rxFrames.clear ();
90  }
91  m_ackData.clear ();
92  m_requests.clear ();
93  m_sortedRes.clear ();
94 }
95 
96 void
98 {
99  Clear ();
101 }
102 TypeId
104 {
105  static TypeId tid = TypeId ("ns3::UanMacRcGw")
106  .SetParent<UanMac> ()
107  .SetGroupName ("Uan")
108  .AddConstructor<UanMacRcGw> ()
109  .AddAttribute ("MaxReservations",
110  "Maximum number of reservations to accept per cycle.",
111  UintegerValue (10),
113  MakeUintegerChecker<uint32_t> ())
114  .AddAttribute ("NumberOfRates",
115  "Number of rates per Phy layer.",
116  UintegerValue (1023),
118  MakeUintegerChecker<uint32_t> ())
119  .AddAttribute ("MaxPropDelay",
120  "Maximum propagation delay between gateway and non-gateway nodes.",
121  TimeValue (Seconds (2)),
123  MakeTimeChecker ())
124  .AddAttribute ("SIFS",
125  "Spacing between frames to account for timing error and processing delay.",
126  TimeValue (Seconds (0.2)),
128  MakeTimeChecker ())
129  .AddAttribute ("NumberOfNodes",
130  "Number of non-gateway nodes in this gateway's neighborhood.",
131  UintegerValue (10),
133  MakeUintegerChecker<uint32_t> ())
134  .AddAttribute ("MinRetryRate",
135  "Smallest allowed RTS retry rate.",
136  DoubleValue (0.01),
138  MakeDoubleChecker<double> ())
139  .AddAttribute ("RetryStep",
140  "Retry rate increment.",
141  DoubleValue (0.01),
143  MakeDoubleChecker<double> ())
144  .AddAttribute ("TotalRate",
145  "Total available channel rate in bps (for a single channel, without splitting reservation channel).",
146  UintegerValue (4096),
148  MakeUintegerChecker<uint32_t> ())
149  .AddAttribute ("RateStep",
150  "Increments available for rate assignment in bps.",
151  UintegerValue (4),
153  MakeUintegerChecker<uint32_t> ())
154  .AddAttribute ("FrameSize",
155  "Size of data frames in bytes.",
156  UintegerValue (1000),
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")
167 
168  ;
169 
170  return tid;
171 }
172 
173 bool
174 UanMacRcGw::Enqueue (Ptr<Packet> packet, uint16_t protocolNumber, const Address &dest)
175 {
176  NS_UNUSED (dest);
177  NS_UNUSED (protocolNumber);
178  NS_LOG_WARN ("RCMAC Gateway transmission to acoustic nodes is not yet implemented");
179  return false;
180 }
181 
182 void
184 {
185  m_forwardUpCb = cb;
186 }
187 
188 void
190 {
191  m_phy = phy;
192  phy->SetReceiveOkCallback (MakeCallback (&UanMacRcGw::ReceivePacket, this));
193  phy->SetReceiveErrorCallback (MakeCallback (&UanMacRcGw::ReceiveError, this));
194 }
195 
196 void
198 {
199  NS_UNUSED (sinr);
200 }
201 
202 void
204 {
205  NS_UNUSED (sinr);
206  UanHeaderCommon ch;
207  pkt->PeekHeader (ch);
208 
210  {
211  m_rxLogger (pkt, mode);
212  }
213  else
214  {
215  return;
216  }
217 
218  pkt->RemoveHeader (ch);
219 
220  switch (ch.GetType ())
221  {
222  case UanMacRc::TYPE_DATA:
223  {
224  UanHeaderRcData dh;
225  pkt->RemoveHeader (dh);
226  m_propDelay[ch.GetSrc ()] = dh.GetPropDelay ();
227  if (m_ackData.find (ch.GetSrc ()) == m_ackData.end ())
228  {
229  NS_LOG_DEBUG (Now ().As (Time::S) << " GATEWAY Received unexpected data packet");
230  }
231  else
232  {
233  NS_LOG_DEBUG (Now ().As (Time::S) << " GW Received data packet from " << ch.GetSrc () << " length = " << pkt->GetSize ());
234  m_ackData[ch.GetSrc ()].rxFrames.insert (dh.GetFrameNo ());
235  }
236  m_forwardUpCb (pkt, ch.GetProtocolNumber (), ch.GetSrc ());
237  }
238  break;
240  case UanMacRc::TYPE_RTS:
241  if (m_state == CTSING)
242  {
243  return;
244  }
245 
246  {
247  UanHeaderRcRts rh;
248  pkt->RemoveHeader (rh);
249 
250  if (m_requests.find (ch.GetSrc ()) == m_requests.end ())
251  {
252  Request req;
253  req.numFrames = rh.GetNoFrames ();
254  req.rxTime = Simulator::Now ();
255  req.frameNo = rh.GetFrameNo ();
256  req.retryNo = rh.GetRetryNo ();
257  req.length = rh.GetLength ();
258  NS_LOG_DEBUG (Now ().As (Time::S) << " GW storing reservation from " << ch.GetSrc () << " with length " << req.length);
259  m_requests.insert (std::make_pair (ch.GetSrc (), req));
260  std::map<Mac8Address, Time>::iterator it = m_propDelay.find (ch.GetSrc ());
261  if (it == m_propDelay.end ())
262  {
263  m_sortedRes.insert (std::make_pair (m_maxDelta, ch.GetSrc ()));
264  }
265  else
266  {
267  m_sortedRes.insert (std::make_pair ( (*it).second, ch.GetSrc ()));
268  }
269  }
270  }
271  if (m_state == IDLE)
272  {
273  StartCycle ();
274  }
275  break;
276  case UanMacRc::TYPE_CTS:
277  NS_FATAL_ERROR ("Received CTS at GW. Currently only support single GW network!");
278  break;
279  case UanMacRc::TYPE_ACK:
280  NS_FATAL_ERROR ("Received ACK at GW. Currently only support single GW network!");
281  break;
282  default:
283  NS_FATAL_ERROR ("Received unknown packet at GW!");
284  }
285 }
286 
287 void
289 {
290  uint32_t numRts = static_cast<uint32_t> (m_sortedRes.size ());
291 
292  if (numRts)
293  {
294  NS_LOG_DEBUG (Now ().As (Time::S) << " Simulator starting non-empty cycle");
295  }
296  else
297  {
298  NS_LOG_DEBUG (Now ().As (Time::S) << " Simulator starting EMPTY cycle");
299  }
300 
301  // Calculate dataRate
302  uint32_t totalBytes = 0;
303  uint32_t totalFrames = 0;
304  Time pDelay = Seconds (0);
305  if (numRts > 0)
306  {
307  std::map<Mac8Address, Request>::iterator rit = m_requests.begin ();
308  for (; rit != m_requests.end (); rit++)
309  {
310  totalBytes += (*rit).second.length;
311  totalFrames += (*rit).second.numFrames;
312  }
313  pDelay = 2 * m_sortedRes.begin ()->first;
314  }
315 
316 
317  double minRate = m_phy->GetMode (m_numRates).GetDataRateBps ();
318 
319  uint32_t optA = m_maxRes;
320  if (m_maxRes == 0)
321  {
322  optA = FindOptA ();
323  }
324  double thAlpha = ComputeAlpha (totalFrames, totalBytes, m_numNodes, optA, (pDelay / 2.0).GetSeconds ());
325 
326  double thCtlRate = m_totalRate * thAlpha;
327 
328  double temprate = (thCtlRate - minRate) / ((double) m_rateStep) + 0.5;
329  m_currentRateNum = (uint32_t) temprate;
331  {
333  }
334 
335  NS_LOG_DEBUG ("Found theoretical alpha: " << thAlpha << " Found associated rate = " << thCtlRate << " Giving rate number: " << temprate);
336  double thX = thAlpha * m_totalRate / (2.0 * m_numNodes * m_rtsSize * 8.0);
337 
338  double dataRate = m_phy->GetMode (m_currentRateNum).GetDataRateBps ();
339 
340 
341  if (thX < m_minRetryRate)
342  {
343  NS_LOG_WARN ("Gateway found optimum RTS retry rate is below minimum");
344  m_currentRetryRate = 0;
345  }
346  else
347  {
348  m_currentRetryRate = (uint16_t)((thX - m_minRetryRate) / m_retryStep + 0.5);
349  }
350 
351  double actualX = m_currentRetryRate * m_retryStep + m_minRetryRate;
352 
353  uint32_t ctlRate = m_phy->GetMode (m_currentRateNum + m_numRates).GetDataRateBps ();
354 
355 
356  Time winSize = Seconds (totalBytes * 8.0 / dataRate) + m_sifs * totalFrames + pDelay;
357  if (numRts == 0)
358  {
359  winSize = Seconds ((optA * std::exp (1.0) + 0.5) * 2.0 * 8.0 * m_rtsSize / (thAlpha * m_totalRate)) + (2 * m_maxDelta);
360  }
361  Time effWinSize = winSize - Seconds (m_rtsSize * 8.0 / ctlRate) - (2 * m_maxDelta);
362 
363  // Before fast CTS/ACK(below)
364  Time ctsTxTimeG = Seconds (m_ctsSizeG * 8.0 / dataRate);
365  Time cycleSeconds = winSize + ((totalFrames + 1.0) * m_sifs) +
366  ctsTxTimeG + Seconds ((m_ctsSizeN + m_ackSize) * 8.0 / dataRate);
367 
368 
369  Time ctsTxTimeTotal = Seconds (m_ctsSizeN * 8.0 * numRts / dataRate) + ctsTxTimeG;
370  if (numRts == 0)
371  {
373  ctsg.SetWindowTime (effWinSize);
374  ctsg.SetRateNum (static_cast<uint16_t> (m_currentRateNum));
376  ctsg.SetTxTimeStamp (Simulator::Now ());
377 
378  UanHeaderCommon ch;
382  ch.SetProtocolNumber (0);
383 
384  Ptr<Packet> p = Create<Packet> ();
385  p->AddHeader (ctsg);
386  p->AddHeader (ch);
388 
389 
390  Simulator::Schedule (cycleSeconds, &UanMacRcGw::StartCycle, this);
391  m_state = INCYCLE;
392  m_cycleLogger (Simulator::Now (), Seconds (0), numRts, totalBytes, effWinSize.GetSeconds (), ctlRate, actualX);
393  return;
394  }
395 
396  Time nextEarliest = ctsTxTimeTotal + m_sifs;
397 
398  m_state = CTSING;
399  Simulator::Schedule (nextEarliest, &UanMacRcGw::CycleStarted, this);
400 
401  std::set<std::pair<Time, Mac8Address> >::iterator it = m_sortedRes.begin ();
402  Time minPdelay = (*it).first;
403  Ptr<Packet> cts = Create<Packet> ();
404 
405  for (; it != m_sortedRes.end (); it++)
406  {
407  Request req = m_requests[(*it).second];
408  Time pdelay = (*it).first;
409 
410  AckData newData;
411  newData.expFrames = req.numFrames;
412  newData.frameNo = req.frameNo;
413  Mac8Address dest = (*it).second;
414  m_ackData.insert (std::make_pair (dest, newData));
415 
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));
419  nextEarliest = arrivalTime + Seconds (req.length * 8.0 / dataRate) + m_sifs * req.numFrames;
420 
421  UanHeaderRcCts ctsh;
422  ctsh.SetAddress (dest);
423  ctsh.SetRtsTimeStamp (req.rxTime);
424  ctsh.SetFrameNo (req.frameNo);
425  ctsh.SetRetryNo (req.retryNo);
426  ctsh.SetDelayToTx (arrivalTime);
427  cts->AddHeader (ctsh);
428 
429  NS_LOG_DEBUG (Now ().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");
432  }
433 
435  ctsg.SetRateNum (static_cast<uint16_t> (m_currentRateNum));
437  ctsg.SetWindowTime (effWinSize);
438  ctsg.SetTxTimeStamp (Simulator::Now ());
439  UanHeaderCommon ch;
443  cts->AddHeader (ctsg);
444  cts->AddHeader (ch);
446 
447  m_requests.clear ();
448  m_sortedRes.clear ();
449  Simulator::Schedule (nextEarliest, &UanMacRcGw::EndCycle, this);
450 
451 
452  m_cycleLogger (Simulator::Now (), minPdelay, numRts, totalBytes, cycleSeconds.GetSeconds (), ctlRate, actualX);
453 }
454 
455 void
457 {
458  m_state = INCYCLE;
459 }
460 void
462 {
463 
464  NS_LOG_DEBUG (Now ().As (Time::S) << " GW Ending cycle");
465 
466  Time nextAck = Seconds (0);
467 
468  Time ackTime = Seconds (m_ackSize * 8.0 / m_phy->GetMode (m_currentRateNum).GetDataRateBps ());
469 
470  std::map<Mac8Address, AckData>::iterator it = m_ackData.begin ();
471  for (; it != m_ackData.end (); it++)
472  {
473  Mac8Address dest = (*it).first;
474  AckData &data = (*it).second;
475 
476  std::list<uint32_t> toNack;
477  for (uint8_t i = 0; i < data.expFrames; i++)
478  {
479  if (data.rxFrames.find (i) == data.rxFrames.end ())
480  {
481  toNack.push_back (i);
482  }
483  }
484  UanHeaderCommon ch;
485  ch.SetDest (dest);
488  UanHeaderRcAck ah;
489  ah.SetFrameNo (data.frameNo);
490  std::list<uint32_t>::iterator nit = toNack.begin ();
491  for (; nit != toNack.end (); nit++)
492  {
493  ah.AddNackedFrame (static_cast<uint8_t> (*nit));
494  }
495 
496  Ptr<Packet> ack = Create<Packet> ();
497  ack->AddHeader (ah);
498  ack->AddHeader (ch);
500  nextAck = nextAck + ackTime + m_sifs;
501  }
502  m_ackData.clear ();
504 
505 }
506 void
508 {
509  UanHeaderCommon ch;
510  pkt->PeekHeader (ch);
511  std::string type;
512  switch (ch.GetType ())
513  {
514  case UanMacRc::TYPE_DATA:
515  type = "DATA";
516  break;
517  case UanMacRc::TYPE_RTS:
518  type = "RTS";
519  break;
520  case UanMacRc::TYPE_CTS:
521  type = "CTS";
522  break;
523  case UanMacRc::TYPE_ACK:
524  type = "ACK";
525  break;
527  type = "GWPING";
528  break;
529  default:
530  type = "UNKNOWN";
531  break;
532  }
533  NS_LOG_DEBUG (Now ().As (Time::S) << " GW sending " << type << " packet with size " << pkt->GetSize () << " to " << ch.GetDest () << " at rate " << rate);
534  m_phy->SendPacket (pkt, rate);
535 }
536 
537 
538 double
539 UanMacRcGw::ComputeAlpha (uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
540 {
541  NS_UNUSED (n);
542  double alpha;
543  double lrae = m_rtsSize * 8.0 * a * std::exp (1.0);
544  if (totalFrames == 0)
545  {
546 
547  alpha = (2.0 * lrae + 8.0 * m_rtsSize - std::sqrt (m_ctsSizeG * 8.0 * 8.0 * m_rtsSize + 2 * 8.0 * m_ctsSizeG * 8.0 * m_rtsSize * a * std::exp (1.0)) ) /
548  (2 * lrae + 8.0 * m_rtsSize - 8.0 * m_ctsSizeG);
549  }
550  else
551  {
552  double w = totalBytes * 8.0 + totalFrames*m_sifs.GetSeconds () * m_totalRate;
553  double v = m_rtsSize * 8.0 + 2 * lrae;
554  double u = (2 * m_maxDelta.GetSeconds () - 2 * deltaK) * m_totalRate;
555 
556  double gamma = (w - u + v) / (2 * (u - totalFrames * m_sifs.GetSeconds () * m_totalRate));
557 
558  alpha = -gamma + std::sqrt (gamma * gamma + v / (u - totalFrames * m_sifs.GetSeconds () * m_totalRate));
559 
560  if (alpha < 0 || alpha > 1)
561  {
562  alpha = -gamma - std::sqrt (gamma * gamma + v / (u - totalFrames * m_sifs.GetSeconds () * m_totalRate));
563  }
564  }
565  NS_ASSERT_MSG (alpha > 0 && alpha < 1, "Error computing alpha. Alpha out of valid range!");
566  return alpha;
567 }
568 
569 std::vector<double>
571 {
572  uint32_t n = m_numNodes;
573  std::vector<double> pds;
574  std::map<Mac8Address, Time>::iterator pdit = m_propDelay.begin ();
575 
576  for (; pdit != m_propDelay.end (); pdit++)
577  {
578  pds.push_back (pdit->second.GetSeconds ());
579  }
580  while (pds.size () < m_numNodes)
581  {
582  pds.push_back (m_maxDelta.GetSeconds ());
583  }
584 
585  std::sort (pds.begin (), pds.end ());
586  // Find expected min. prop. delay for k nodes
587  std::vector<double> exppdk;
588  exppdk.push_back (m_maxDelta.GetSeconds ());
589  for (uint32_t k = 1; k <= n; k++)
590  {
591  uint32_t ind = CompExpMinIndex (n,k) - 1;
592  exppdk.push_back (pds[ind]);
593  }
594  return exppdk;
595 }
596 
597 double
598 UanMacRcGw::ComputeExpS (uint32_t a, uint32_t ld, std::vector<double> exppdk)
599 {
600  UanHeaderCommon ch;
601  uint32_t lh = ch.GetSerializedSize ();
602 
603  uint32_t n = m_numNodes;
604  double expk = n * (1 - std::exp (-((double) a) / (double) n));
605  NS_LOG_DEBUG ("expk = " << expk);
606 
607  // Compute expected data per cycle
608  double expdata = 8 * ld * expk;
609 
610  // Compute expected time per cycle
611  double alpha0 = ComputeAlpha (0,0,n,a,exppdk[0]);
612  double c0 = 8.0 * m_ctsSizeG / ( m_totalRate * (1 - alpha0)) + 2 * m_maxDelta.GetSeconds () + (a * std::exp (1.0) + 0.5) * 2 * m_rtsSize * 8.0 / (alpha0 * m_totalRate);
613  double exptime = ComputePiK (a,n,0) * c0;
614  double expp = 0;
615  for (uint32_t i = 1; i <= n; i++)
616  {
617  expp += ComputePiK (a,n,i) * exppdk[i - 1];
618  }
619 
620  exptime += ComputeExpBOverA (n,a,ld + lh,exppdk) + expk * 2 * m_sifs.GetSeconds () + m_sifs.GetSeconds () + 2 * expp;
621  double s = (1.0 / m_totalRate) * expdata / exptime;
622 
623  return s;
624 }
625 
626 double
627 UanMacRcGw::ComputeExpS (uint32_t a, uint32_t ld)
628 {
629  return ComputeExpS (a, ld, GetExpPdk ());
630 }
631 
632 uint32_t
633 UanMacRcGw::CompExpMinIndex (uint32_t n, uint32_t k)
634 {
635  double sum = 0;
636  for (uint32_t i = 1; i <= n - k + 1; i++)
637  {
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;
640  sum += p * i;
641  }
642  return (uint32_t)(sum + 0.5);
643 }
644 
645 double
646 UanMacRcGw::ComputePiK (uint32_t a, uint32_t n, uint32_t k)
647 {
648  double nck = (double) NchooseK (n, k);
649  return nck * std::pow ( (std::exp ( (double) a / (double) n) - 1.0), (double) k) * std::exp (-( (double) a));
650 }
651 
652 double
653 UanMacRcGw::ComputeExpBOverA (uint32_t n, uint32_t a, uint32_t ldlh, std::vector<double> deltaK)
654 {
655 
656  double sum = 0;
657  uint32_t lt = 8 * (m_ctsSizeN + ldlh + m_ackSize);
658  for (uint32_t k = 1; k <= n; k++)
659  {
660  double num = 8.0 * m_ctsSizeG + k * lt;
661  double denom = (1.0 - ComputeAlpha (k, k * ldlh, n, a, deltaK[k])) * m_totalRate;
662  double pik = ComputePiK (a, n, k);
663  double term = pik * num / denom;
664 
665  sum += term;
666  }
667 
668  return sum;
669 }
670 
671 uint64_t
672 UanMacRcGw::NchooseK (uint32_t n, uint32_t k)
673 {
674  if (k > n)
675  {
676  return 0;
677  }
678 
679  if (k > n / 2)
680  {
681  k = n - k;
682  }
683 
684  double accum = 1;
685  for (uint32_t i = 1; i <= k; i++)
686  {
687  accum = accum * (n - k + i) / i;
688  }
689 
690  return (uint64_t)(accum + 0.5);
691 
692 }
693 
694 uint32_t
696 {
697  double tput = 0;
698  uint32_t a = 1;
699  while (1)
700  {
701 
702  double newtput = ComputeExpS (a, m_frameSize);
703  if (newtput < tput)
704  {
705  a--;
706  break;
707  }
708  else
709  {
710  tput = newtput;
711  a++;
712  }
713  }
714  NS_LOG_DEBUG (Now ().As (Time::S) << " GW: Found optimum a = " << a);
715  return a;
716 }
717 
718 int64_t
720 {
721  NS_LOG_FUNCTION (this << stream);
722  return 0;
723 }
724 
725 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::UanMacRc::TYPE_DATA
@ TYPE_DATA
Data.
Definition: uan-mac-rc.h:168
ns3::UanMacRcGw::AttachPhy
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
Definition: uan-mac-rc-gw.cc:189
ns3::UanMacRcGw::m_rxLogger
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc-gw.h:162
ns3::UanMacRc::TYPE_RTS
@ TYPE_RTS
RTS.
Definition: uan-mac-rc.h:170
ns3::UanMacRcGw::m_minRetryRate
double m_minRetryRate
Smallest allowed RTS retry rate.
Definition: uan-mac-rc-gw.h:144
ns3::UanMacRcGw::Request
Reservation request.
Definition: uan-mac-rc-gw.h:107
ns3::UanHeaderRcCts::SetFrameNo
void SetFrameNo(uint8_t frameNo)
Set the RTS frame number being cleared.
Definition: uan-header-rc.cc:446
ns3::Mac8Address
A class used for addressing MAC8 MAC's.
Definition: mac8-address.h:43
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::UanHeaderRcRts::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition: uan-header-rc.cc:229
ns3::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533
ns3::Packet::PeekHeader
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:290
ns3::UanMacRcGw::m_ctsSizeG
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Definition: uan-mac-rc-gw.h:135
ns3::UanHeaderCommon::SetDest
void SetDest(Mac8Address dest)
Set the destination address.
Definition: uan-header-common.cc:67
ns3::Packet::GetSize
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
ns3::Packet::AddHeader
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
ns3::Callback
Callback template class.
Definition: callback.h:1279
ns3::UanMacRcGw::m_sortedRes
std::set< std::pair< Time, Mac8Address > > m_sortedRes
Queued request times.
Definition: uan-mac-rc-gw.h:156
ns3::Mac8Address::ConvertFrom
static Mac8Address ConvertFrom(const Address &address)
Convert a generic address to a Mac8Address.
Definition: mac8-address.cc:54
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uan-mac-rc-gw.h
ns3::UanMacRcGw::AckData
Packet ACK data.
Definition: uan-mac-rc-gw.h:120
ns3::UanMacRcGw::Request::numFrames
uint8_t numFrames
Number of frames.
Definition: uan-mac-rc-gw.h:108
ns3::UanHeaderRcCts::SetAddress
void SetAddress(Mac8Address addr)
Set the destination address, for scheduling info.
Definition: uan-header-rc.cc:471
ns3::UanMacRcGw::m_rateStep
uint32_t m_rateStep
Increments available for rate assignment in bps.
Definition: uan-mac-rc-gw.h:141
NS_LOG_WARN
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
ns3::UanHeaderRcRts::GetLength
uint16_t GetLength(void) const
Get the total number of bytes in the reservation, including headers.
Definition: uan-header-rc.cc:205
ns3::UanMacRcGw::m_currentRateNum
uint32_t m_currentRateNum
Rate number corresponding to data rate of current cycle.
Definition: uan-mac-rc-gw.h:138
ns3::UanMacRcGw::CompExpMinIndex
uint32_t CompExpMinIndex(uint32_t n, uint32_t k)
Index to the k'th expected delay among n nodes.
Definition: uan-mac-rc-gw.cc:633
ns3::UanHeaderRcRts::GetRetryNo
uint8_t GetRetryNo(void) const
Get the retry number of this RTS packet.
Definition: uan-header-rc.cc:217
ns3::UanHeaderRcData::GetPropDelay
Time GetPropDelay(void) const
Get the propagation delay found in handshaking.
Definition: uan-header-rc.cc:84
ns3::UanMacRcGw::ReceivePacket
void ReceivePacket(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY receive ok callback.
Definition: uan-mac-rc-gw.cc:203
ns3::UanMacRcGw::IDLE
@ IDLE
Initial idle state.
Definition: uan-mac-rc-gw.h:96
ns3::UanMacRcGw::~UanMacRcGw
virtual ~UanMacRcGw()
Dummy destructor, see DoDispose.
Definition: uan-mac-rc-gw.cc:68
ns3::UanHeaderCommon::GetDest
Mac8Address GetDest(void) const
Get the destination address.
Definition: uan-header-common.cc:99
ns3::UanHeaderRcCtsGlobal::SetRateNum
void SetRateNum(uint16_t rate)
Set the rate number corresponding to data rate of current cycle.
Definition: uan-header-rc.cc:315
ns3::Time::As
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:429
ns3::UanMacRcGw::DoDispose
virtual void DoDispose()
Destructor implementation.
Definition: uan-mac-rc-gw.cc:97
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
ns3::UanMacRcGw::AssignStreams
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: uan-mac-rc-gw.cc:719
ns3::UanHeaderCommon::GetProtocolNumber
uint16_t GetProtocolNumber(void) const
Get the packet type value.
Definition: uan-header-common.cc:115
ns3::UanMacRcGw::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: uan-mac-rc-gw.cc:103
ns3::UanHeaderCommon
Common packet header fields.
Definition: uan-header-common.h:65
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::UanMacRcGw::SetForwardUpCb
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > cb)
Set the callback to forward packets up to higher layers.
Definition: uan-mac-rc-gw.cc:183
ns3::UanMacRcGw::m_cycleLogger
TracedCallback< Time, Time, uint32_t, uint32_t, double, uint32_t, double > m_cycleLogger
A packet was destined for and received at this MAC layer.
Definition: uan-mac-rc-gw.h:176
uan-header-rc.h
ns3::UanMacRcGw::NchooseK
uint64_t NchooseK(uint32_t n, uint32_t k)
Binomial coefficient.
Definition: uan-mac-rc-gw.cc:672
ns3::UanMacRcGw::CycleStarted
void CycleStarted(void)
Set state to INCYCLE.
Definition: uan-mac-rc-gw.cc:456
ns3::UanHeaderCommon::GetSrc
Mac8Address GetSrc(void) const
Get the source address.
Definition: uan-header-common.cc:104
ns3::UanMacRcGw::SendPacket
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send packet on PHY.
Definition: uan-mac-rc-gw.cc:507
ns3::Ptr< Packet >
ns3::UanMacRcGw::m_ackSize
uint32_t m_ackSize
Size of UanHeaderCommon and UanHeaderRcAck.
Definition: uan-mac-rc-gw.h:136
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::UanHeaderRcRts::GetFrameNo
uint8_t GetFrameNo(void) const
Get the frame number.
Definition: uan-header-rc.cc:223
ns3::UanHeaderRcData::GetFrameNo
uint8_t GetFrameNo(void) const
Get the frame number of the reservation being transmitted.
Definition: uan-header-rc.cc:78
ns3::UanMacRcGw::Request::frameNo
uint8_t frameNo
Current frame number.
Definition: uan-mac-rc-gw.h:109
ns3::IDLE
@ IDLE
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:75
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
uan-phy.h
ns3::UanMacRcGw::m_phy
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
Definition: uan-mac-rc-gw.h:128
bianchi11ax.k
int k
Definition: bianchi11ax.py:129
max
#define max(a, b)
Definition: 80211b.c:43
uan-tx-mode.h
ns3::Address
a polymophic address class
Definition: address.h:91
sample-rng-plot.alpha
alpha
Definition: sample-rng-plot.py:37
data
uint8_t data[writeSize]
Definition: socket-bound-tcp-static-routing.cc:53
ns3::UanMac::GetAddress
virtual Address GetAddress(void)
Get the MAC Address.
Definition: uan-mac.cc:55
ns3::UanMacRcGw
Gateway side of RC-MAC.
Definition: uan-mac-rc-gw.h:58
ns3::UanMacRcGw::INCYCLE
@ INCYCLE
Cycling through nodes.
Definition: uan-mac-rc-gw.h:97
ns3::UanMacRcGw::Request::rxTime
Time rxTime
Time request received.
Definition: uan-mac-rc-gw.h:112
ns3::UanMacRc::TYPE_CTS
@ TYPE_CTS
CTS.
Definition: uan-mac-rc.h:171
ns3::Packet::RemoveHeader
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
ns3::UanMacRcGw::FindOptA
uint32_t FindOptA(void)
Compute the optimum maximum number of reservations to accept per cycle.
Definition: uan-mac-rc-gw.cc:695
NS_UNUSED
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
uan-mac-rc.h
ns3::UanHeaderRcAck::SetFrameNo
void SetFrameNo(uint8_t frameNo)
Set the frame number of the reservation being acknowledged.
Definition: uan-header-rc.cc:577
ns3::UanMacRcGw::m_state
State m_state
Gateway processing state.
Definition: uan-mac-rc-gw.h:100
ns3::UanHeaderRcCts::SetDelayToTx
void SetDelayToTx(Time delay)
Set the time delay from CTS transmission to first data frame arrival.
Definition: uan-header-rc.cc:459
ns3::UanHeaderCommon::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition: uan-header-common.cc:129
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::UanMacRcGw::m_cleared
bool m_cleared
Flag when we've been cleared.
Definition: uan-mac-rc-gw.h:159
ns3::UanMacRcGw::m_totalRate
uint32_t m_totalRate
Total available channel rate in bps (for a single channel, without splitting reservation channel).
Definition: uan-mac-rc-gw.h:140
ns3::UanMacRcGw::Enqueue
virtual bool Enqueue(Ptr< Packet > pkt, uint16_t protocolNumber, const Address &dest)
Enqueue packet to be transmitted.
Definition: uan-mac-rc-gw.cc:174
ns3::UanHeaderRcRts::GetNoFrames
uint8_t GetNoFrames(void) const
Get the number of data frames in the reservation.
Definition: uan-header-rc.cc:199
ns3::UanTxMode
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:42
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
ns3::UanMacRcGw::m_numRates
uint32_t m_numRates
Number of rates per Phy layer.
Definition: uan-mac-rc-gw.h:132
ns3::UanMacRcGw::GetExpPdk
std::vector< double > GetExpPdk(void)
Get the expected propagation delay to each node.
Definition: uan-mac-rc-gw.cc:570
ns3::UanHeaderRcCtsGlobal::SetRetryRate
void SetRetryRate(uint16_t rate)
Set the retry rate number for the current cycle.
Definition: uan-header-rc.cc:321
ns3::UanHeaderRcCts::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition: uan-header-rc.cc:506
ns3::UanMacRcGw::m_numNodes
uint32_t m_numNodes
Number of non-gateway nodes in this gateway's neighborhood.
Definition: uan-mac-rc-gw.h:139
ns3::UanHeaderRcAck::AddNackedFrame
void AddNackedFrame(uint8_t frame)
NACK a frame.
Definition: uan-header-rc.cc:583
ns3::UanMacRcGw::m_maxDelta
Time m_maxDelta
Maximum propagation delay between gateway and non-gateway nodes .
Definition: uan-mac-rc-gw.h:129
ns3::UanHeaderCommon::SetSrc
void SetSrc(Mac8Address src)
Set the source address.
Definition: uan-header-common.cc:72
ns3::UanHeaderRcData
Extra data header information.
Definition: uan-header-rc.h:42
ns3::UanHeaderRcAck
Header used for ACK packets by protocol UanMacRc.
Definition: uan-header-rc.h:459
ns3::UanHeaderRcCtsGlobal
Cycle broadcast information.
Definition: uan-header-rc.h:239
ns3::MakeCallback
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...
Definition: callback.h:1642
ns3::UanHeaderRcCts::SetRetryNo
void SetRetryNo(uint8_t no)
Set the retry number of the RTS frame being cleared.
Definition: uan-header-rc.cc:465
ns3::UanMacRcGw::m_rtsSize
uint32_t m_rtsSize
Size of UanHeaderCommon and UanHeaderRcRts.
Definition: uan-mac-rc-gw.h:133
ns3::MakeDoubleAccessor
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:42
ns3::UanMacRcGw::EndCycle
void EndCycle(void)
End cycle by scheduling pending ACKs.
Definition: uan-mac-rc-gw.cc:461
ns3::UanMacRcGw::m_requests
std::map< Mac8Address, Request > m_requests
Request for each node.
Definition: uan-mac-rc-gw.h:154
ns3::UanHeaderRcAck::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition: uan-header-rc.cc:607
ns3::UanMacRcGw::m_frameSize
uint32_t m_frameSize
Size of data frames in bytes.
Definition: uan-mac-rc-gw.h:142
ns3::UanMacRcGw::ComputeExpBOverA
double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector< double > deltaK)
Numeric function.
Definition: uan-mac-rc-gw.cc:653
ns3::UanMacRcGw::m_propDelay
std::map< Mac8Address, Time > m_propDelay
Propagation delay to each node.
Definition: uan-mac-rc-gw.h:148
ns3::UanMacRcGw::CTSING
@ CTSING
Sending CTS.
Definition: uan-mac-rc-gw.h:98
ns3::UanHeaderRcCts::SetRtsTimeStamp
void SetRtsTimeStamp(Time timeStamp)
Set the timestamp for RTS reception.
Definition: uan-header-rc.cc:452
ns3::UanMacRcGw::Request::length
uint16_t length
Request header length.
Definition: uan-mac-rc-gw.h:111
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::UanHeaderCommon::SetType
void SetType(uint8_t type)
Set the header type.
Definition: uan-header-common.cc:78
ns3::UanHeaderRcCtsGlobal::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition: uan-header-rc.cc:362
ns3::UanMacRcGw::ComputeAlpha
double ComputeAlpha(uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
Compute alpha parameter.
Definition: uan-mac-rc-gw.cc:539
ns3::UanMac
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:50
ns3::UanMacRcGw::UanMacRcGw
UanMacRcGw()
Constructor.
Definition: uan-mac-rc-gw.cc:48
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Time::S
@ S
second
Definition: nstime.h:115
ns3::UanMacRcGw::m_forwardUpCb
Callback< void, Ptr< Packet >, uint16_t, const Mac8Address & > m_forwardUpCb
Forwarding up callback.
Definition: uan-mac-rc-gw.h:126
ns3::UanMacRcGw::AckData::expFrames
uint8_t expFrames
Expected number of frames.
Definition: uan-mac-rc-gw.h:123
ns3::UanMacRcGw::StartCycle
void StartCycle(void)
Cycle through pending requests.
Definition: uan-mac-rc-gw.cc:288
uan-header-common.h
ns3::UanHeaderCommon::GetType
uint8_t GetType(void) const
Get the header type value.
Definition: uan-header-common.cc:109
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::Mac8Address::GetBroadcast
static Mac8Address GetBroadcast(void)
Get the broadcast address (255).
Definition: mac8-address.cc:87
ns3::UanMacRcGw::ComputeExpS
double ComputeExpS(uint32_t a, uint32_t ld, std::vector< double > exppdk)
Throughput for a reservations with framesize ld, given expected delays exppdk.
Definition: uan-mac-rc-gw.cc:598
ns3::UanHeaderRcRts
RTS header.
Definition: uan-header-rc.h:118
ns3::UanMacRcGw::m_ctsSizeN
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
Definition: uan-mac-rc-gw.h:134
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::UanMacRc::TYPE_ACK
@ TYPE_ACK
ACK.
Definition: uan-mac-rc.h:172
ns3::UanMacRcGw::ComputePiK
double ComputePiK(uint32_t a, uint32_t n, uint32_t k)
Numeric function.
Definition: uan-mac-rc-gw.cc:646
ns3::UanMacRcGw::AckData::frameNo
uint8_t frameNo
Frame number being ACK'ed.
Definition: uan-mac-rc-gw.h:121
ns3::UanHeaderCommon::SetProtocolNumber
void SetProtocolNumber(uint16_t protocolNumber)
Set the packet type.
Definition: uan-header-common.cc:84
ns3::MakeUintegerAccessor
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
ns3::UanMacRcGw::ReceiveError
void ReceiveError(Ptr< Packet > pkt, double sinr)
PHY receive error callback.
Definition: uan-mac-rc-gw.cc:197
ns3::UanMacRcGw::m_sifs
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Definition: uan-mac-rc-gw.h:130
ns3::UanHeaderRcCts
CTS header.
Definition: uan-header-rc.h:343
ns3::UanMacRcGw::m_ackData
std::map< Mac8Address, AckData > m_ackData
AckData for each node.
Definition: uan-mac-rc-gw.h:151
ns3::UanHeaderRcCtsGlobal::SetWindowTime
void SetWindowTime(Time t)
Set the window time (time duration following blocking time to allow RTS transmissions).
Definition: uan-header-rc.cc:327
ns3::UanMacRcGw::m_currentRetryRate
uint16_t m_currentRetryRate
Retry rate number for current cycle.
Definition: uan-mac-rc-gw.h:137
ns3::Object::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
ns3::UanMacRcGw::m_maxRes
uint32_t m_maxRes
Maximum number of reservations to accept per cycle.
Definition: uan-mac-rc-gw.h:131
ns3::Time::GetSeconds
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37
ns3::UanHeaderRcCtsGlobal::SetTxTimeStamp
void SetTxTimeStamp(Time timeStamp)
Set the CTS timestamp.
Definition: uan-header-rc.cc:333
third.phy
phy
Definition: third.py:93
ns3::MakeTimeAccessor
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: nstime.h:1354
ns3::UanMacRc::TYPE_GWPING
@ TYPE_GWPING
Gateway ping.
Definition: uan-mac-rc.h:169
ns3::UanMacRcGw::Clear
virtual void Clear(void)
Clears all pointer references.
Definition: uan-mac-rc-gw.cc:73
ns3::UanMacRcGw::m_retryStep
double m_retryStep
Retry rate increment.
Definition: uan-mac-rc-gw.h:145
ns3::UanMacRcGw::Request::retryNo
uint8_t retryNo
Retry number.
Definition: uan-mac-rc-gw.h:110