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<UanAddress, 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  .AddConstructor<UanMacRcGw> ()
108  .AddAttribute ("MaxReservations",
109  "Maximum number of reservations to accept per cycle.",
110  UintegerValue (10),
112  MakeUintegerChecker<uint32_t> ())
113  .AddAttribute ("NumberOfRates",
114  "Number of rates per Phy layer.",
115  UintegerValue (1023),
117  MakeUintegerChecker<uint32_t> ())
118  .AddAttribute ("MaxPropDelay",
119  "Maximum propagation delay between gateway and non-gateway nodes.",
120  TimeValue (Seconds (2)),
122  MakeTimeChecker ())
123  .AddAttribute ("SIFS",
124  "Spacing between frames to account for timing error and processing delay.",
125  TimeValue (Seconds (0.2)),
127  MakeTimeChecker ())
128  .AddAttribute ("NumberOfNodes",
129  "Number of non-gateway nodes in this gateway's neighborhood.",
130  UintegerValue (10),
132  MakeUintegerChecker<uint32_t> ())
133  .AddAttribute ("MinRetryRate",
134  "Smallest allowed RTS retry rate.",
135  DoubleValue (0.01),
137  MakeDoubleChecker<double> ())
138  .AddAttribute ("RetryStep",
139  "Retry rate increment.",
140  DoubleValue (0.01),
142  MakeDoubleChecker<double> ())
143  .AddAttribute ("TotalRate",
144  "Total available channel rate in bps (for a single channel, without splitting reservation channel).",
145  UintegerValue (4096),
147  MakeUintegerChecker<uint32_t> ())
148  .AddAttribute ("RateStep",
149  "Increments available for rate assignment in bps.",
150  UintegerValue (4),
152  MakeUintegerChecker<uint32_t> ())
153  .AddAttribute ("FrameSize",
154  "Size of data frames in bytes.",
155  UintegerValue (1000),
157  MakeUintegerChecker<uint32_t> ())
158  .AddTraceSource ("RX",
159  "A packet was destined for and received at this MAC layer.",
161  "ns3::UanMac::PacketModeTracedCallback")
162  .AddTraceSource ("Cycle",
163  "Trace cycle statistics.",
165  "ns3::UanMacRcGw::CycleCallback")
166 
167  ;
168 
169  return tid;
170 }
171 
172 Address
174 {
175  return m_address;
176 }
177 
178 void
180 {
181  m_address = addr;
182 }
183 
184 bool
185 UanMacRcGw::Enqueue (Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber)
186 {
187  NS_LOG_WARN ("RCMAC Gateway transmission to acoustic nodes is not yet implemented");
188  return false;
189 }
190 
191 void
193 {
194  m_forwardUpCb = cb;
195 }
196 
197 void
199 {
200  m_phy = phy;
201  phy->SetReceiveOkCallback (MakeCallback (&UanMacRcGw::ReceivePacket, this));
202  phy->SetReceiveErrorCallback (MakeCallback (&UanMacRcGw::ReceiveError, this));
203 }
204 
205 void
207 {
208 }
209 
210 Address
212 {
213  return UanAddress::GetBroadcast ();
214 }
215 
216 void
218 {
219  UanHeaderCommon ch;
220  pkt->PeekHeader (ch);
221 
222  if (ch.GetDest () == m_address || ch.GetDest () == UanAddress::GetBroadcast ())
223  {
224  m_rxLogger (pkt, mode);
225  }
226  else
227  {
228  return;
229  }
230 
231  pkt->RemoveHeader (ch);
232 
233  switch (ch.GetType ())
234  {
235  case UanMacRc::TYPE_DATA:
236  {
237  UanHeaderRcData dh;
238  pkt->RemoveHeader (dh);
239  m_propDelay[ch.GetSrc ()] = dh.GetPropDelay ();
240  if (m_ackData.find (ch.GetSrc ()) == m_ackData.end ())
241  {
242  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GATEWAY Received unexpected data packet");
243  }
244  else
245  {
246  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Received data packet from " << ch.GetSrc () << " length = " << pkt->GetSize ());
247  m_ackData[ch.GetSrc ()].rxFrames.insert (dh.GetFrameNo ());
248  }
249  m_forwardUpCb (pkt, ch.GetSrc ());
250  }
251  break;
253  case UanMacRc::TYPE_RTS:
254  if (m_state == CTSING)
255  {
256  return;
257  }
258 
259  {
260  UanHeaderRcRts rh;
261  pkt->RemoveHeader (rh);
262 
263  if (m_requests.find (ch.GetSrc ()) == m_requests.end ())
264  {
265  Request req;
266  req.numFrames = rh.GetNoFrames ();
267  req.rxTime = Simulator::Now ();
268  req.frameNo = rh.GetFrameNo ();
269  req.retryNo = rh.GetRetryNo ();
270  req.length = rh.GetLength ();
271  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW storing reservation from " << ch.GetSrc () << " with length " << req.length);
272  m_requests.insert (std::make_pair (ch.GetSrc (), req));
273  std::map<UanAddress, Time>::iterator it = m_propDelay.find (ch.GetSrc ());
274  if (it == m_propDelay.end ())
275  {
276  m_sortedRes.insert (std::make_pair (m_maxDelta, ch.GetSrc ()));
277  }
278  else
279  {
280  m_sortedRes.insert (std::make_pair ( (*it).second, ch.GetSrc ()));
281  }
282  }
283  }
284  if (m_state == IDLE)
285  {
286  StartCycle ();
287  }
288  break;
289  case UanMacRc::TYPE_CTS:
290  NS_FATAL_ERROR ("Received CTS at GW. Currently only support single GW network!");
291  break;
292  case UanMacRc::TYPE_ACK:
293  NS_FATAL_ERROR ("Received ACK at GW. Currently only support single GW network!");
294  break;
295  default:
296  NS_FATAL_ERROR ("Received unknown packet at GW!");
297  }
298 }
299 
300 void
302 {
303  uint32_t numRts = m_sortedRes.size ();
304 
305  if (numRts)
306  {
307  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Simulator starting non-empty cycle");
308  }
309  else
310  {
311  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Simulator starting EMPTY cycle");
312  }
313 
314  // Calculate dataRate
315  uint32_t totalBytes = 0;
316  uint32_t totalFrames = 0;
317  double pDelay = 0;
318  if (numRts > 0)
319  {
320  std::map<UanAddress, Request>::iterator rit = m_requests.begin ();
321  for (; rit != m_requests.end (); rit++)
322  {
323  totalBytes += (*rit).second.length;
324  totalFrames += (*rit).second.numFrames;
325  }
326  pDelay = 2 * m_sortedRes.begin ()->first.GetSeconds ();
327  }
328 
329 
330  double minRate = m_phy->GetMode (m_numRates).GetDataRateBps ();
331 
332  uint32_t optA = m_maxRes;
333  if (m_maxRes == 0)
334  {
335  optA = FindOptA ();
336  }
337  double thAlpha = ComputeAlpha (totalFrames, totalBytes, m_numNodes, optA, pDelay / 2.0);
338 
339  double thCtlRate = m_totalRate * thAlpha;
340 
341  double temprate = (thCtlRate - minRate) / ((double) m_rateStep) + 0.5;
342  m_currentRateNum = (uint32_t) temprate;
344  {
346  }
347 
348  NS_LOG_DEBUG ("Found theoretical alpha: " << thAlpha << " Found associated rate = " << thCtlRate << " Giving rate number: " << temprate);
349  double thX = thAlpha * m_totalRate / (2.0 * m_numNodes * m_rtsSize * 8.0);
350 
351  double dataRate = m_phy->GetMode (m_currentRateNum).GetDataRateBps ();
352 
353 
354  if (thX < m_minRetryRate)
355  {
356  NS_LOG_WARN ("Gateway found optimum RTS retry rate is below minimum");
357  m_currentRetryRate = 0;
358  }
359  else
360  {
361  m_currentRetryRate = (uint16_t)((thX - m_minRetryRate) / m_retryStep + 0.5);
362  }
363 
364  double actualX = m_currentRetryRate * m_retryStep + m_minRetryRate;
365 
366  uint32_t ctlRate = m_phy->GetMode (m_currentRateNum + m_numRates).GetDataRateBps ();
367 
368 
369  double winSize = (double)(totalBytes) * 8.0 / dataRate + m_sifs.GetSeconds () * totalFrames + pDelay;
370  if (numRts == 0)
371  {
372  winSize = (optA * std::exp (1.0) + 0.5) * 2.0 * 8.0 * m_rtsSize / (thAlpha * m_totalRate) + 2 * m_maxDelta.GetSeconds ();
373  }
374  double effWinSize = winSize - m_rtsSize * 8 / ctlRate - 2 * m_maxDelta.GetSeconds ();
375 
376 
377  // Before fast CTS/ACK(below)
378  double cycleSeconds = winSize + (totalFrames + 1.0) * m_sifs.GetSeconds () + m_ctsSizeG * 8.0 / dataRate + (m_ctsSizeN + m_ackSize) * 8.0 * numRts / dataRate;
379 
380  Time ctsTxTimeG = Seconds (m_ctsSizeG * 8.0 / dataRate);
381  Time ctsTxTimeTotal = Seconds (m_ctsSizeN * 8.0 * numRts / dataRate) + ctsTxTimeG;
382  if (numRts == 0)
383  {
385  ctsg.SetWindowTime (Seconds (effWinSize));
388  ctsg.SetTxTimeStamp (Simulator::Now ());
389 
391  Ptr<Packet> p = Create<Packet> ();
392  p->AddHeader (ctsg);
393  p->AddHeader (ch);
395 
396 
397  Simulator::Schedule (Seconds (cycleSeconds), &UanMacRcGw::StartCycle, this);
398  m_state = INCYCLE;
399  m_cycleLogger (Simulator::Now (), Seconds (0), numRts, totalBytes, effWinSize, ctlRate, actualX);
400  return;
401  }
402 
403  Time nextEarliest = ctsTxTimeTotal + m_sifs;
404 
405  m_state = CTSING;
406  Simulator::Schedule (nextEarliest, &UanMacRcGw::CycleStarted, this);
407 
408  std::set<std::pair<Time, UanAddress> >::iterator it = m_sortedRes.begin ();
409  Time minPdelay = (*it).first;
410  Ptr<Packet> cts = Create<Packet> ();
411 
412  for (; it != m_sortedRes.end (); it++)
413  {
414  Request req = m_requests[(*it).second];
415  Time pdelay = (*it).first;
416 
417  AckData newData;
418  newData.expFrames = req.numFrames;
419  newData.frameNo = req.frameNo;
420  UanAddress dest = (*it).second;
421  m_ackData.insert (std::make_pair (dest, newData));
422 
423  Time earliestArr = ctsTxTimeTotal + pdelay + pdelay + m_sifs;
424  Time arrivalTime = std::max (earliestArr, nextEarliest);
425  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW: Scheduling request for prop. delay " << pdelay.GetSeconds () << " for " << (*it).second << " Earliest possible arrival=" << earliestArr.GetSeconds () << " Next arrival time=" << nextEarliest.GetSeconds ());
426  nextEarliest = arrivalTime + Seconds (req.length * 8.0 / dataRate) + Seconds (m_sifs.GetSeconds () * req.numFrames);
427 
428  UanHeaderRcCts ctsh;
429  ctsh.SetAddress (dest);
430  ctsh.SetRtsTimeStamp (req.rxTime);
431  ctsh.SetFrameNo (req.frameNo);
432  ctsh.SetRetryNo (req.retryNo);
433  ctsh.SetDelayToTx (arrivalTime);
434  cts->AddHeader (ctsh);
435 
436  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () <<
437  " GW Scheduling reception for " << (uint32_t) req.numFrames <<
438  " frames at " << (Simulator::Now () + arrivalTime).GetSeconds () << " (delaytiltx of " << arrivalTime.GetSeconds () << ") Total length is " << req.length << " with txtime " << req.length * 8 / dataRate << " seconds");
439  }
440 
444  ctsg.SetWindowTime (Seconds (effWinSize));
445  ctsg.SetTxTimeStamp (Simulator::Now ());
446  UanHeaderCommon ch;
448  ch.SetSrc (m_address);
450  cts->AddHeader (ctsg);
451  cts->AddHeader (ch);
453 
454  m_requests.clear ();
455  m_sortedRes.clear ();
456  Simulator::Schedule (nextEarliest, &UanMacRcGw::EndCycle, this);
457 
458 
459  m_cycleLogger (Simulator::Now (), minPdelay, numRts, totalBytes, cycleSeconds, ctlRate, actualX);
460 }
461 
462 void
464 {
465  m_state = INCYCLE;
466 }
467 void
469 {
470 
471  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW Ending cycle");
472 
473  Time nextAck = Seconds (0);
474 
475  Time ackTime = Seconds (m_ackSize * 8.0 / m_phy->GetMode (m_currentRateNum).GetDataRateBps ());
476 
477  std::map<UanAddress, AckData>::iterator it = m_ackData.begin ();
478  for (; it != m_ackData.end (); it++)
479  {
480  UanAddress dest = (*it).first;
481  AckData &data = (*it).second;
482 
483  std::list<uint32_t> toNack;
484  for (uint32_t i = 0; i < data.expFrames; i++)
485  {
486  if (data.rxFrames.find (i) == data.rxFrames.end ())
487  {
488  toNack.push_back (i);
489  }
490  }
491  UanHeaderCommon ch;
492  ch.SetDest (dest);
493  ch.SetSrc (m_address);
495  UanHeaderRcAck ah;
496  ah.SetFrameNo (data.frameNo);
497  std::list<uint32_t>::iterator nit = toNack.begin ();
498  for (; nit != toNack.end (); nit++)
499  {
500  ah.AddNackedFrame (*nit);
501  }
502 
503  Ptr<Packet> ack = Create<Packet> ();
504  ack->AddHeader (ah);
505  ack->AddHeader (ch);
507  nextAck = nextAck + ackTime + m_sifs;
508  }
509  m_ackData.clear ();
511 
512 }
513 void
515 {
516  UanHeaderCommon ch;
517  pkt->PeekHeader (ch);
518  std::string type;
519  switch (ch.GetType ())
520  {
521  case UanMacRc::TYPE_DATA:
522  type = "DATA";
523  break;
524  case UanMacRc::TYPE_RTS:
525  type = "RTS";
526  break;
527  case UanMacRc::TYPE_CTS:
528  type = "CTS";
529  break;
530  case UanMacRc::TYPE_ACK:
531  type = "ACK";
532  break;
534  type = "GWPING";
535  break;
536  default:
537  type = "UNKNOWN";
538  break;
539  }
540  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW sending " << type << " packet with size " << pkt->GetSize () << " to " << ch.GetDest () << " at rate " << rate);
541  m_phy->SendPacket (pkt, rate);
542 }
543 
544 
545 double
546 UanMacRcGw::ComputeAlpha (uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
547 {
548 
549  double alpha;
550  double lrae = m_rtsSize * 8.0 * a * std::exp (1.0);
551  if (totalFrames == 0)
552  {
553 
554  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)) ) /
555  (2 * lrae + 8.0 * m_rtsSize - 8.0 * m_ctsSizeG);
556  }
557  else
558  {
559  double w = totalBytes * 8.0 + totalFrames*m_sifs.GetSeconds () * m_totalRate;
560  double v = m_rtsSize * 8.0 + 2 * lrae;
561  double u = (2 * m_maxDelta.GetSeconds () - 2 * deltaK) * m_totalRate;
562 
563  double gamma = (w - u + v) / (2 * (u - totalFrames * m_sifs.GetSeconds () * m_totalRate));
564 
565  alpha = -gamma + std::sqrt (gamma * gamma + v / (u - totalFrames * m_sifs.GetSeconds () * m_totalRate));
566 
567  if (alpha < 0 || alpha > 1)
568  {
569  alpha = -gamma - std::sqrt (gamma * gamma + v / (u - totalFrames * m_sifs.GetSeconds () * m_totalRate));
570  }
571  }
572  NS_ASSERT_MSG (alpha > 0 && alpha < 1, "Error computing alpha. Alpha out of valid range!");
573  return alpha;
574 }
575 
576 std::vector<double>
578 {
579  uint32_t n = m_numNodes;
580  std::vector<double> pds;
581  std::map<UanAddress, Time>::iterator pdit = m_propDelay.begin ();
582 
583  for (; pdit != m_propDelay.end (); pdit++)
584  {
585  pds.push_back (pdit->second.GetSeconds ());
586  }
587  while (pds.size () < m_numNodes)
588  {
589  pds.push_back (m_maxDelta.GetSeconds ());
590  }
591 
592  std::sort (pds.begin (), pds.end ());
593  // Find expected min. prop. delay for k nodes
594  std::vector<double> exppdk;
595  exppdk.push_back (m_maxDelta.GetSeconds ());
596  for (uint32_t k = 1; k <= n; k++)
597  {
598  uint32_t ind = CompExpMinIndex (n,k) - 1;
599  exppdk.push_back (pds[ind]);
600  }
601  return exppdk;
602 }
603 
604 double
605 UanMacRcGw::ComputeExpS (uint32_t a, uint32_t ld, std::vector<double> exppdk)
606 {
607  UanHeaderCommon ch;
608  uint32_t lh = ch.GetSerializedSize ();
609 
610  uint32_t n = m_numNodes;
611  double expk = n * (1 - std::exp (-((double) a) / (double) n));
612  NS_LOG_DEBUG ("expk = " << expk);
613 
614  // Compute expected data per cycle
615  double expdata = 8 * ld * expk;
616 
617  // Compute expected time per cycle
618  double alpha0 = ComputeAlpha (0,0,n,a,exppdk[0]);
619  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);
620  double exptime = ComputePiK (a,n,0) * c0;
621  double expp = 0;
622  for (uint32_t i = 1; i <= n; i++)
623  {
624  expp += ComputePiK (a,n,i) * exppdk[i - 1];
625  }
626 
627  exptime += ComputeExpBOverA (n,a,ld + lh,exppdk) + expk * 2 * m_sifs.GetSeconds () + m_sifs.GetSeconds () + 2 * expp;
628  double s = (1.0 / m_totalRate) * expdata / exptime;
629 
630  return s;
631 }
632 
633 double
634 UanMacRcGw::ComputeExpS (uint32_t a, uint32_t ld)
635 {
636  return ComputeExpS (a, ld, GetExpPdk ());
637 }
638 
639 uint32_t
640 UanMacRcGw::CompExpMinIndex (uint32_t n, uint32_t k)
641 {
642  double sum = 0;
643  for (uint32_t i = 1; i <= n - k + 1; i++)
644  {
645  double nChK = NchooseK (n, k);
646  double p = (nChK > 0) ? (NchooseK (n - i, k - 1) / nChK) : DBL_MAX;
647  sum += p * i;
648  }
649  return (uint32_t)(sum + 0.5);
650 }
651 
652 double
653 UanMacRcGw::ComputePiK (uint32_t a, uint32_t n, uint32_t k)
654 {
655  double nck = (double) NchooseK (n, k);
656  return nck * std::pow ( (std::exp ( (double) a / (double) n) - 1.0), (double) k) * std::exp (-( (double) a));
657 }
658 
659 double
660 UanMacRcGw::ComputeExpBOverA (uint32_t n, uint32_t a, uint32_t ldlh, std::vector<double> deltaK)
661 {
662 
663  double sum = 0;
664  uint32_t lt = 8 * (m_ctsSizeN + ldlh + m_ackSize);
665  for (uint32_t k = 1; k <= n; k++)
666  {
667  double num = 8.0 * m_ctsSizeG + k * lt;
668  double denom = (1.0 - ComputeAlpha (k, k * ldlh, n, a, deltaK[k])) * m_totalRate;
669  double pik = ComputePiK (a, n, k);
670  double term = pik * num / denom;
671 
672  sum += term;
673  }
674 
675  return sum;
676 }
677 
678 uint64_t
679 UanMacRcGw::NchooseK (uint32_t n, uint32_t k)
680 {
681  if (k > n)
682  {
683  return 0;
684  }
685 
686  if (k > n / 2)
687  {
688  k = n - k;
689  }
690 
691  double accum = 1;
692  for (uint32_t i = 1; i <= k; i++)
693  {
694  accum = accum * (n - k + i) / i;
695  }
696 
697  return (uint64_t)(accum + 0.5);
698 
699 }
700 
701 uint32_t
703 {
704  double tput = 0;
705  uint32_t a = 1;
706  while (1)
707  {
708 
709  double newtput = ComputeExpS (a, m_frameSize);
710  if (newtput < tput)
711  {
712  a--;
713  break;
714  }
715  else
716  {
717  tput = newtput;
718  a++;
719  }
720  }
721  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " GW: Found optimum a = " << a);
722  return a;
723 }
724 
725 int64_t
727 {
728  NS_LOG_FUNCTION (this << stream);
729  return 0;
730 }
731 
732 } // namespace ns3
std::set< std::pair< Time, UanAddress > > m_sortedRes
Queued request times.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:268
Time GetPropDelay(void) const
Get the propagation delay found in handshaking.
double m_retryStep
Retry rate increment.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
virtual void AttachPhy(Ptr< UanPhy > phy)
Attach PHY layer to this MAC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Time rxTime
Time request received.
Cycle broadcast information.
void SetRateNum(uint16_t rate)
Set the 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.
virtual uint32_t GetSerializedSize(void) const
Callback template class.
Definition: callback.h:978
TracedCallback< Time, Time, uint32_t, uint32_t, double, uint32_t, double > m_cycleLogger
A packet was destined for and received at this MAC layer.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
uint32_t m_ctsSizeG
Size of UanHeaderCommon and UanHeaderRcCtsGlobal.
Header used for ACK packets by protocol UanMacRc.
bool m_cleared
Flag when we've been cleared.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
void SetAddress(UanAddress addr)
Set the destination address, for scheduling info.
uint32_t m_numRates
Number of rates per Phy layer.
Time m_sifs
Spacing between frames to account for timing error and processing delay.
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:62
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
std::map< UanAddress, Time > m_propDelay
Propagation delay to each node.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
uint16_t m_currentRetryRate
Retry rate number for current cycle.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:338
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
double m_minRetryRate
Smallest allowed RTS retry rate.
Initial idle state.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:819
virtual void Clear(void)
Clears all pointer references.
virtual Address GetBroadcast(void) const
Get the broadcast address.
State m_state
Gateway processing state.
uint8_t GetType(void) const
Get the header type value.
void SetWindowTime(Time t)
Set the window time (time duration following blocking time to allow RTS transmissions).
Callback< void, Ptr< Packet >, const UanAddress & > m_forwardUpCb
Forwarding up callback.
virtual ~UanMacRcGw()
Dummy destructor, see DoDispose.
uint8_t GetFrameNo(void) const
Get the frame number.
a polymophic address class
Definition: address.h:90
uint8_t numFrames
Number of frames.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:439
std::vector< double > GetExpPdk(void)
Get the expected propagation delay to each node.
void ReceiveError(Ptr< Packet > pkt, double sinr)
PHY receive error callback.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:327
Time m_maxDelta
Maximum propagation delay between gateway and non-gateway nodes .
double ComputeExpS(uint32_t a, uint32_t ld, std::vector< double > exppdk)
Throughput for a reservations with framesize ld, given expected delays exppdk.
void SendPacket(Ptr< Packet > pkt, uint32_t rate)
Send packet on PHY.
Virtual base class for all UAN MAC protocols.
Definition: uan-mac.h:48
virtual Address GetAddress(void)
Get the MAC Address.
uint64_t NchooseK(uint32_t n, uint32_t k)
Binomial coefficient.
AttributeValue implementation for Time.
Definition: nstime.h:921
A class used for addressing UAN MAC's.
Definition: uan-address.h:40
virtual uint32_t GetSerializedSize(void) const
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetSrc(UanAddress src)
Set the source address.
uint8_t data[writeSize]
Ptr< SampleEmitter > s
uint32_t m_numNodes
Number of non-gateway nodes in this gateway's neighborhood.
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
void ReceivePacket(Ptr< Packet > pkt, double sinr, UanTxMode mode)
PHY recieve ok callback.
uint8_t frameNo
Current frame number.
virtual void DoDispose()
Destructor implementation.
uint32_t m_rateStep
Increments available for rate assignment in bps.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1290
virtual void SetAddress(UanAddress addr)
Set the address.
uint16_t length
Request header length.
TracedCallback< Ptr< const Packet >, UanTxMode > m_rxLogger
A packet was destined for and received at this MAC layer.
uint32_t m_currentRateNum
Rate number corresponding to data rate of current cycle.
void SetDest(UanAddress dest)
Set the destination address.
void AddNackedFrame(uint8_t frame)
NACK a frame.
uint8_t GetRetryNo(void) const
Get the retry number of this RTS packet.
static UanAddress GetBroadcast(void)
Get the broadcast address (255).
Definition: uan-address.cc:92
uint32_t FindOptA(void)
Compute the optimum maximum number of reservations to accept per cycle.
uint8_t expFrames
Expected number of frames.
uint8_t GetFrameNo(void) const
Get the frame number of the reservation being transmitted.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Definition: packet.cc:277
uint32_t m_ctsSizeN
Size of UanHeaderRcCts.
static TypeId GetTypeId(void)
Register this type.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Common packet header fields.
UanAddress GetDest(void) const
Get the destination address.
Cycling through nodes.
Reservation request.
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:922
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
void SetTxTimeStamp(Time timeStamp)
Set the CTS timestamp.
uint8_t frameNo
Frame number being ACK'ed.
std::map< UanAddress, Request > m_requests
Request for each node.
uint8_t GetNoFrames(void) const
Get the number of data frames in the reservation.
Ptr< UanPhy > m_phy
PHY layer attached to this MAC.
#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:84
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
uint32_t m_frameSize
Size of data frames in bytes.
uint32_t m_totalRate
Total available channel rate in bps (for a single channel, without splitting reservation channel)...
void StartCycle(void)
Cycle through pending requests.
UanMacRcGw()
Constructor.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
uint32_t m_maxRes
Maximum number of reservations to accept per cycle.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
void SetFrameNo(uint8_t frameNo)
Set the frame number of the reservation being acknowledged.
void CycleStarted(void)
Set state to INCYCLE.
double ComputePiK(uint32_t a, uint32_t n, uint32_t k)
Numeric function.
uint32_t m_rtsSize
Size of UanHeaderCommon and UanHeaderRcRts.
virtual uint32_t GetSerializedSize(void) const
void SetType(uint8_t type)
Set the header type.
void EndCycle(void)
End cycle by scheduling pending ACKs.
UanAddress GetSrc(void) const
Get the source address.
std::map< UanAddress, AckData > m_ackData
AckData for each node.
UanAddress m_address
The MAC address.
uint8_t retryNo
Retry number.
virtual bool Enqueue(Ptr< Packet > pkt, const Address &dest, uint16_t protocolNumber)
Enqueue packet to be transmitted.
double ComputeAlpha(uint32_t totalFrames, uint32_t totalBytes, uint32_t n, uint32_t a, double deltaK)
Compute alpha parameter.
void SetRetryRate(uint16_t rate)
Set the retry rate number for the current cycle.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
virtual uint32_t GetSerializedSize(void) const
std::set< uint8_t > rxFrames
Received frames.
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
Packet ACK data.
a unique identifier for an interface.
Definition: type-id.h:51
uint32_t m_ackSize
Size of UanHeaderCommon and UanHeaderRcAck.
virtual uint32_t GetSerializedSize(void) const
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
double ComputeExpBOverA(uint32_t n, uint32_t a, uint32_t ldlh, std::vector< double > deltaK)
Numeric function.
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:253
Extra data header information.
Definition: uan-header-rc.h:41
uint16_t GetLength(void) const
Get the total number of bytes in the reservation, including headers.
virtual void SetForwardUpCb(Callback< void, Ptr< Packet >, const UanAddress & > cb)
Set the callback to forward packets up to higher layers.