A Discrete-Event Network Simulator
API
uan-phy-gen.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  * Andrea Sacco <andrea.sacco85@gmail.com>
20  */
21 
22 #include "uan-phy-gen.h"
23 #include "uan-transducer.h"
24 #include "uan-channel.h"
25 #include "uan-net-device.h"
26 #include "ns3/simulator.h"
27 #include "ns3/traced-callback.h"
28 #include "ns3/ptr.h"
29 #include "ns3/trace-source-accessor.h"
30 #include "ns3/double.h"
31 #include "ns3/string.h"
32 #include "ns3/log.h"
33 #include "ns3/uan-tx-mode.h"
34 #include "ns3/node.h"
35 #include "ns3/uinteger.h"
36 #include "ns3/energy-source-container.h"
37 #include "ns3/acoustic-modem-energy-model.h"
38 
39 
40 namespace ns3 {
41 
42 NS_LOG_COMPONENT_DEFINE ("UanPhyGen");
43 
44 NS_OBJECT_ENSURE_REGISTERED (UanPhyGen);
45 NS_OBJECT_ENSURE_REGISTERED (UanPhyPerGenDefault);
46 NS_OBJECT_ENSURE_REGISTERED (UanPhyCalcSinrDefault);
47 NS_OBJECT_ENSURE_REGISTERED (UanPhyCalcSinrFhFsk);
48 NS_OBJECT_ENSURE_REGISTERED (UanPhyPerUmodem);
49 
50 
51 /*************** UanPhyCalcSinrDefault definition *****************/
53 {
54 
55 }
57 {
58 
59 }
60 
61 TypeId
63 {
64  static TypeId tid = TypeId ("ns3::UanPhyCalcSinrDefault")
65  .SetParent<Object> ()
66  .AddConstructor<UanPhyCalcSinrDefault> ()
67  ;
68  return tid;
69 }
70 
71 double
73  Time arrTime,
74  double rxPowerDb,
75  double ambNoiseDb,
76  UanTxMode mode,
77  UanPdp pdp,
78  const UanTransducer::ArrivalList &arrivalList) const
79 {
80  if (mode.GetModType () == UanTxMode::OTHER)
81  {
82  NS_LOG_WARN ("Calculating SINR for unsupported modulation type");
83  }
84 
85  double intKp = -DbToKp (rxPowerDb); // This packet is in the arrivalList
86  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
87  for (; it != arrivalList.end (); it++)
88  {
89  intKp += DbToKp (it->GetRxPowerDb ());
90  }
91 
92  double totalIntDb = KpToDb (intKp + DbToKp (ambNoiseDb));
93 
94  NS_LOG_DEBUG ("Calculating SINR: RxPower = " << rxPowerDb << " dB. Number of interferers = " << arrivalList.size () << " Interference + noise power = " << totalIntDb << " dB. SINR = " << rxPowerDb - totalIntDb << " dB.");
95  return rxPowerDb - totalIntDb;
96 }
97 
98 /*************** UanPhyCalcSinrFhFsk definition *****************/
100 {
101 
102 }
104 {
105 
106 }
107 
108 TypeId
110 {
111  static TypeId tid = TypeId ("ns3::UanPhyCalcSinrFhFsk")
112  .SetParent<Object> ()
113  .AddConstructor<UanPhyCalcSinrFhFsk> ()
114  .AddAttribute ("NumberOfHops",
115  "Number of frequencies in hopping pattern.",
116  UintegerValue (13),
118  MakeUintegerChecker<uint32_t> ())
119  ;
120  return tid;
121 }
122 double
124  Time arrTime,
125  double rxPowerDb,
126  double ambNoiseDb,
127  UanTxMode mode,
128  UanPdp pdp,
129  const UanTransducer::ArrivalList &arrivalList) const
130 {
131  if (mode.GetModType () != UanTxMode::FSK)
132  {
133  NS_LOG_WARN ("Calculating SINR for unsupported mode type");
134  }
135 
136 
137 
138  double ts = 1.0 / mode.GetPhyRateSps ();
139  double clearingTime = (m_hops - 1.0) * ts;
140  double csp = pdp.SumTapsFromMaxNc (Seconds (0), Seconds (ts));
141 
142  // Get maximum arrival offset
143  double maxAmp = -1;
144  double maxTapDelay = 0.0;
145  UanPdp::Iterator pit = pdp.GetBegin ();
146  for (; pit != pdp.GetEnd (); pit++)
147  {
148  if (std::abs (pit->GetAmp ()) > maxAmp)
149  {
150  maxAmp = std::abs (pit->GetAmp ());
151  maxTapDelay = pit->GetDelay ().GetSeconds ();
152  }
153  }
154 
155 
156  double effRxPowerDb = rxPowerDb + KpToDb (csp);
157 
158  double isiUpa = rxPowerDb * pdp.SumTapsFromMaxNc (Seconds (ts + clearingTime), Seconds (ts));
159  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
160  double intKp = -DbToKp (effRxPowerDb);
161  for (; it != arrivalList.end (); it++)
162  {
163  UanPdp intPdp = it->GetPdp ();
164  double tDelta = std::abs (arrTime.GetSeconds () + maxTapDelay - it->GetArrivalTime ().GetSeconds ());
165  // We want tDelta in terms of a single symbol (i.e. if tDelta = 7.3 symbol+clearing
166  // times, the offset in terms of the arriving symbol power is
167  // 0.3 symbol+clearing times.
168 
169  int32_t syms = (uint32_t)( (double) tDelta / (ts + clearingTime));
170  tDelta = tDelta - syms * (ts + clearingTime);
171 
172  // Align to pktRx
173  if (arrTime + Seconds (maxTapDelay) > it->GetArrivalTime ())
174  {
175  tDelta = ts + clearingTime - tDelta;
176  }
177 
178  double intPower = 0.0;
179  if (tDelta < ts)
180  {
181  intPower += intPdp.SumTapsNc (Seconds (0), Seconds (ts - tDelta));
182  intPower += intPdp.SumTapsNc (Seconds (ts - tDelta + clearingTime),
183  Seconds (2 * ts - tDelta + clearingTime));
184  }
185  else
186  {
187  Time start = Seconds (ts + clearingTime - tDelta);
188  Time end = start + Seconds (ts);
189  intPower += intPdp.SumTapsNc (start, end);
190 
191  start = start + Seconds (ts + clearingTime);
192  end = start + Seconds (ts);
193  intPower += intPdp.SumTapsNc (start, end);
194  }
195  intKp += DbToKp (it->GetRxPowerDb ()) * intPower;
196  }
197 
198  double totalIntDb = KpToDb (isiUpa + intKp + DbToKp (ambNoiseDb));
199 
200  NS_LOG_DEBUG ("Calculating SINR: RxPower = " << rxPowerDb << " dB. Effective Rx power " << effRxPowerDb << " dB. Number of interferers = " << arrivalList.size () << " Interference + noise power = " << totalIntDb << " dB. SINR = " << effRxPowerDb - totalIntDb << " dB.");
201  return effRxPowerDb - totalIntDb;
202 }
203 
204 /*************** UanPhyPerGenDefault definition *****************/
206 {
207 
208 }
209 
211 {
212 
213 }
214 TypeId
216 {
217  static TypeId tid = TypeId ("ns3::UanPhyPerGenDefault")
218  .SetParent<Object> ()
219  .AddConstructor<UanPhyPerGenDefault> ()
220  .AddAttribute ("Threshold", "SINR cutoff for good packet reception.",
221  DoubleValue (8),
223  MakeDoubleChecker<double> ());
224  return tid;
225 }
226 
227 
228 // Default PER calculation simply compares SINR to a threshold which is configurable
229 // via an attribute.
230 double
232 {
233  if (sinrDb >= m_thresh)
234  {
235  return 0;
236  }
237  else
238  {
239  return 1;
240  }
241 }
242 
243 /*************** UanPhyPerUmodem definition *****************/
245 {
246 
247 }
249 {
250 
251 }
252 
254 {
255  static TypeId tid = TypeId ("ns3::UanPhyPerUmodem")
256  .SetParent<Object> ()
257  .AddConstructor<UanPhyPerUmodem> ()
258  ;
259  return tid;
260 }
261 
262 double
263 UanPhyPerUmodem::NChooseK (uint32_t n, uint32_t k)
264 {
265  double result;
266 
267  result = 1.0;
268 
269  for (uint32_t i = std::max (k,n - k) + 1; i <= n; ++i)
270  {
271  result *= i;
272  }
273 
274  for (uint32_t i = 2; i <= std::min (k,n - k); ++i)
275  {
276  result /= i;
277  }
278 
279  return result;
280 }
281 
282 double
284 {
285  uint32_t d[] =
286  { 12, 14, 16, 18, 20, 22, 24, 26, 28 };
287  double Bd[] =
288  {
289  33, 281, 2179, 15035LLU, 105166LLU, 692330LLU, 4580007LLU, 29692894LLU,
290  190453145LLU
291  };
292 
293  // double Rc = 1.0 / 2.0;
294  double ebno = std::pow (10.0, sinr / 10.0);
295  double perror = 1.0 / (2.0 + ebno);
296  double P[9];
297 
298  if (sinr >= 10)
299  {
300  return 0;
301  }
302  if (sinr <= 6)
303  {
304  return 1;
305  }
306 
307  for (uint32_t r = 0; r < 9; r++)
308  {
309  double sumd = 0;
310  for (uint32_t k = 0; k < d[r]; k++)
311  {
312  sumd = sumd + NChooseK (d[r] - 1 + k, k) * std::pow (1 - perror, (double) k);
313  }
314  P[r] = std::pow (perror, (double) d[r]) * sumd;
315 
316  }
317 
318  double Pb = 0;
319  for (uint32_t r = 0; r < 8; r++)
320  {
321  Pb = Pb + Bd[r] * P[r];
322  }
323 
324  // cout << "Pb = " << Pb << endl;
325  uint32_t bits = pkt->GetSize () * 8;
326 
327  double Ppacket = 1;
328  double temp = NChooseK (bits, 0);
329  temp *= std::pow ( (1 - Pb), (double) bits);
330  Ppacket -= temp;
331  temp = NChooseK (288, 1) * Pb * std::pow ( (1 - Pb), bits - 1.0);
332  Ppacket -= temp;
333 
334  if (Ppacket > 1)
335  {
336  return 1;
337  }
338  else
339  {
340  return Ppacket;
341  }
342 }
343 
344 /*************** UanPhyGen definition *****************/
346  : UanPhy (),
347  m_state (IDLE),
348  m_channel (0),
349  m_transducer (0),
350  m_device (0),
351  m_mac (0),
352  m_rxGainDb (0),
353  m_txPwrDb (0),
354  m_rxThreshDb (0),
355  m_ccaThreshDb (0),
356  m_pktRx (0),
357  m_cleared (false),
358  m_disabled (false)
359 {
360  m_pg = CreateObject<UniformRandomVariable> ();
361 
363 }
364 
366 {
367 
368 }
369 
370 void
372 {
373  if (m_cleared)
374  {
375  return;
376  }
377  m_cleared = true;
378  m_listeners.clear ();
379  if (m_channel)
380  {
381  m_channel->Clear ();
382  m_channel = 0;
383  }
384  if (m_transducer)
385  {
386  m_transducer->Clear ();
387  m_transducer = 0;
388  }
389  if (m_device)
390  {
391  m_device->Clear ();
392  m_device = 0;
393  }
394  if (m_mac)
395  {
396  m_mac->Clear ();
397  m_mac = 0;
398  }
399  if (m_per)
400  {
401  m_per->Clear ();
402  m_per = 0;
403  }
404  if (m_sinr)
405  {
406  m_sinr->Clear ();
407  m_sinr = 0;
408  }
409  m_pktRx = 0;
410 }
411 
412 void
414 {
415  Clear ();
418 }
419 
422 {
423  UanModesList l;
424  l.AppendMode (UanTxModeFactory::CreateMode (UanTxMode::FSK,80,80,22000,4000,13,"FSK"));
425  l.AppendMode (UanTxModeFactory::CreateMode (UanTxMode::PSK,200, 200, 22000, 4000, 4, "QPSK"));
426  return l;
427 }
428 TypeId
430 {
431 
432  static TypeId tid = TypeId ("ns3::UanPhyGen")
433  .SetParent<UanPhy> ()
434  .AddConstructor<UanPhyGen> ()
435  .AddAttribute ("CcaThreshold",
436  "Aggregate energy of incoming signals to move to CCA Busy state dB.",
437  DoubleValue (10),
439  MakeDoubleChecker<double> ())
440  .AddAttribute ("RxThreshold",
441  "Required SNR for signal acquisition in dB.",
442  DoubleValue (10),
444  MakeDoubleChecker<double> ())
445  .AddAttribute ("TxPower",
446  "Transmission output power in dB.",
447  DoubleValue (190),
449  MakeDoubleChecker<double> ())
450  .AddAttribute ("RxGain",
451  "Gain added to incoming signal at receiver.",
452  DoubleValue (0),
454  MakeDoubleChecker<double> ())
455  .AddAttribute ("SupportedModes",
456  "List of modes supported by this PHY.",
460  .AddAttribute ("PerModel",
461  "Functor to calculate PER based on SINR and TxMode.",
462  StringValue ("ns3::UanPhyPerGenDefault"),
464  MakePointerChecker<UanPhyPer> ())
465  .AddAttribute ("SinrModel",
466  "Functor to calculate SINR based on pkt arrivals and modes.",
467  StringValue ("ns3::UanPhyCalcSinrDefault"),
469  MakePointerChecker<UanPhyCalcSinr> ())
470  .AddTraceSource ("RxOk",
471  "A packet was received successfully.",
473  "ns3::UanPhy::TracedCallback")
474  .AddTraceSource ("RxError",
475  "A packet was received unsuccessfully.",
477  "ns3::UanPhy::TracedCallback")
478  .AddTraceSource ("Tx",
479  "Packet transmission beginning.",
481  "ns3::UanPhy::TracedCallback")
482  ;
483  return tid;
484 
485 }
486 
487 void
489 {
490  NS_LOG_FUNCTION (this);
491  m_energyCallback = cb;
492 }
493 
494 void
496 {
497  NS_LOG_FUNCTION (this);
498 
499  if (!m_energyCallback.IsNull ())
500  {
501  m_energyCallback (state);
502  }
503 }
504 
505 void
507 {
508  NS_LOG_FUNCTION (this);
509  NS_LOG_DEBUG ("Energy depleted at node " << m_device->GetNode ()->GetId () <<
510  ", stopping rx/tx activities");
511 
512  m_disabled = true;
513 }
514 
515 void
516 UanPhyGen::SendPacket (Ptr<Packet> pkt, uint32_t modeNum)
517 {
518  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Transmitting packet");
519  if (m_disabled)
520  {
521  NS_LOG_DEBUG ("Energy depleted, node cannot transmit any packet. Dropping.");
522  return;
523  }
524 
525  if (m_state == TX)
526  {
527  NS_LOG_DEBUG ("PHY requested to TX while already Transmitting. Dropping packet.");
528  return;
529  }
530  else if (m_state == SLEEP)
531  {
532  NS_LOG_DEBUG ("PHY requested to TX while sleeping. Dropping packet.");
533  return;
534  }
535 
536  UanTxMode txMode = GetMode (modeNum);
537 
538  if (m_pktRx != 0)
539  {
540  m_minRxSinrDb = -1e30;
541  m_pktRx = 0;
542  }
543 
544  m_transducer->Transmit (Ptr<UanPhy> (this), pkt, m_txPwrDb, txMode);
545  m_state = TX;
547  double txdelay = pkt->GetSize () * 8.0 / txMode.GetDataRateBps ();
549  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << " notifying listeners");
550  NotifyListenersTxStart (Seconds (txdelay));
551  m_txLogger (pkt, m_txPwrDb, txMode);
552 }
553 
554 void
556 {
557  if (m_state == SLEEP || m_disabled == true)
558  {
559  NS_LOG_DEBUG ("Transmission ended but node sleeping or dead");
560  return;
561  }
562 
563  NS_ASSERT (m_state == TX);
565  {
566  m_state = CCABUSY;
568  }
569  else
570  {
571  m_state = IDLE;
572  }
574 }
575 
576 void
578 {
579  m_listeners.push_back (listener);
580 }
581 
582 
583 void
584 UanPhyGen::StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
585 {
586  if (m_disabled)
587  {
588  NS_LOG_DEBUG ("Energy depleted, node cannot receive any packet. Dropping.");
589  NotifyRxDrop(pkt); // traced source netanim
590  return;
591  }
592 
593  switch (m_state)
594  {
595  case TX:
596  NotifyRxDrop(pkt); // traced source netanim
597  NS_ASSERT (false);
598  break;
599  case RX:
600  {
601  NS_ASSERT (m_pktRx);
603  m_minRxSinrDb = (newSinrDb < m_minRxSinrDb) ? newSinrDb : m_minRxSinrDb;
604  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Starting RX in RX mode. SINR of pktRx = " << m_minRxSinrDb);
605  NotifyRxBegin(pkt); // traced source netanim
606  }
607  break;
608 
609  case CCABUSY:
610  case IDLE:
611  {
612  NS_ASSERT (!m_pktRx);
613  bool hasmode = false;
614  for (uint32_t i = 0; i < GetNModes (); i++)
615  {
616  if (txMode.GetUid () == GetMode (i).GetUid ())
617  {
618  hasmode = true;
619  break;
620  }
621  }
622  if (!hasmode)
623  {
624  break;
625  }
626 
627 
628  double newsinr = CalculateSinrDb (pkt, Simulator::Now (), rxPowerDb, txMode, pdp);
629  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Starting RX in IDLE mode. SINR = " << newsinr);
630  if (newsinr > m_rxThreshDb)
631  {
632  m_state = RX;
634  NotifyRxBegin(pkt); // traced source netanim
635  m_rxRecvPwrDb = rxPowerDb;
636  m_minRxSinrDb = newsinr;
637  m_pktRx = pkt;
639  m_pktRxMode = txMode;
640  m_pktRxPdp = pdp;
641  double txdelay = pkt->GetSize () * 8.0 / txMode.GetDataRateBps ();
642  Simulator::Schedule (Seconds (txdelay), &UanPhyGen::RxEndEvent, this, pkt, rxPowerDb, txMode);
644  }
645 
646  }
647  break;
648  case SLEEP:
649  NS_LOG_DEBUG ("Sleep mode. Dropping packet.");
650  NotifyRxDrop(pkt); // traced source netanim
651  break;
652  }
653 
655  {
656  m_state = CCABUSY;
658  }
659 
660 }
661 
662 void
663 UanPhyGen::RxEndEvent (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode)
664 {
665  if (pkt != m_pktRx)
666  {
667  return;
668  }
669 
670  if (m_disabled || m_state == SLEEP)
671  {
672  NS_LOG_DEBUG ("Sleep mode or dead. Dropping packet");
673  m_pktRx = 0;
674  NotifyRxDrop(pkt); // traced source netanim
675  return;
676  }
677 
678  NotifyRxEnd(pkt); // traced source netanim
680  {
681  m_state = CCABUSY;
683  }
684  else
685  {
686  m_state = IDLE;
688  }
689 
690  if (m_pg->GetValue (0, 1) > m_per->CalcPer (m_pktRx, m_minRxSinrDb, txMode))
691  {
692  m_rxOkLogger (pkt, m_minRxSinrDb, txMode);
694  if (!m_recOkCb.IsNull ())
695  {
696  m_recOkCb (pkt, m_minRxSinrDb, txMode);
697  }
698 
699  }
700  else
701  {
702  m_rxErrLogger (pkt, m_minRxSinrDb, txMode);
704  if (!m_recErrCb.IsNull ())
705  {
706  m_recErrCb (pkt, m_minRxSinrDb);
707  }
708  }
709 
710  m_pktRx = 0;
711 }
712 
713 void
715 {
716  m_recOkCb = cb;
717 }
718 
719 void
721 {
722  m_recErrCb = cb;
723 }
724 bool
726 {
727  return m_state == SLEEP;
728 }
729 bool
731 {
732  return m_state == IDLE;
733 }
734 bool
736 {
737  return !IsStateIdle () && !IsStateSleep ();
738 }
739 bool
741 {
742  return m_state == RX;
743 }
744 bool
746 {
747  return m_state == TX;
748 }
749 
750 bool
752 {
753  return m_state == CCABUSY;
754 }
755 
756 
757 void
759 {
760  m_rxGainDb = gain;
761 
762 }
763 void
765 {
766  m_txPwrDb = txpwr;
767 }
768 void
770 {
771  m_rxThreshDb = thresh;
772 }
773 void
775 {
776  m_ccaThreshDb = thresh;
777 }
778 double
780 {
781  return m_rxGainDb;
782 }
783 double
785 {
786  return m_txPwrDb;
787 
788 }
789 double
791 {
792  return m_rxThreshDb;
793 }
794 double
796 {
797  return m_ccaThreshDb;
798 }
799 
802 {
803  return m_channel;
804 }
805 
808 {
809  return m_device;
810 }
811 
814 {
815  return m_transducer;
816 }
817 void
819 {
820  m_channel = channel;
821 }
822 
823 void
825 {
826  m_device = device;
827 }
828 
829 void
831 {
832  m_mac = mac;
833 }
834 
835 void
837 {
838  m_transducer = trans;
839  m_transducer->AddPhy (this);
840 }
841 
842 void
844 {
845  if (sleep)
846  {
847  m_state = SLEEP;
848  if (!m_energyCallback.IsNull ())
849  {
851  }
852  }
853  else if (m_state == SLEEP)
854  {
856  {
857  m_state = CCABUSY;
859  }
860  else
861  {
862  m_state = IDLE;
863  }
864 
865  if (!m_energyCallback.IsNull ())
866  {
868  }
869  }
870 }
871 
872 int64_t
873 UanPhyGen::AssignStreams (int64_t stream)
874 {
875  NS_LOG_FUNCTION (this << stream);
876  m_pg->SetStream (stream);
877  return 1;
878 }
879 
880 void
881 UanPhyGen::NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode)
882 {
883  if (m_pktRx)
884  {
885  m_minRxSinrDb = -1e30;
886  }
887 }
888 
889 void
891 {
893  {
894  m_state = IDLE;
896  }
897 }
898 
899 double
900 UanPhyGen::CalculateSinrDb (Ptr<Packet> pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
901 {
902  double noiseDb = m_channel->GetNoiseDbHz ( (double) mode.GetCenterFreqHz () / 1000.0) + 10 * std::log10 (mode.GetBandwidthHz ());
903  return m_sinr->CalcSinrDb (pkt, arrTime, rxPowerDb, noiseDb, mode, pdp, m_transducer->GetArrivalList ());
904 }
905 
906 double
908 {
909 
910  const UanTransducer::ArrivalList &arrivalList = m_transducer->GetArrivalList ();
911 
912  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
913 
914  double interfPower = 0;
915 
916  for (; it != arrivalList.end (); it++)
917  {
918  if (pkt != it->GetPacket ())
919  {
920  interfPower += DbToKp (it->GetRxPowerDb ());
921  }
922  }
923 
924  return KpToDb (interfPower);
925 
926 }
927 
928 double
929 UanPhyGen::DbToKp (double db)
930 {
931  return std::pow (10, db / 10.0);
932 }
933 double
934 UanPhyGen::KpToDb (double kp)
935 {
936  return 10 * std::log10 (kp);
937 }
938 
939 void
941 {
942  ListenerList::const_iterator it = m_listeners.begin ();
943  for (; it != m_listeners.end (); it++)
944  {
945  (*it)->NotifyRxStart ();
946  }
947 
948 }
949 void
951 {
952  ListenerList::const_iterator it = m_listeners.begin ();
953  for (; it != m_listeners.end (); it++)
954  {
955  (*it)->NotifyRxEndOk ();
956  }
957 }
958 void
960 {
961  ListenerList::const_iterator it = m_listeners.begin ();
962  for (; it != m_listeners.end (); it++)
963  {
964  (*it)->NotifyRxEndError ();
965  }
966 }
967 void
969 {
970  ListenerList::const_iterator it = m_listeners.begin ();
971  for (; it != m_listeners.end (); it++)
972  {
973  (*it)->NotifyCcaStart ();
974  }
975 }
976 void
978 {
979  ListenerList::const_iterator it = m_listeners.begin ();
980  for (; it != m_listeners.end (); it++)
981  {
982  (*it)->NotifyCcaEnd ();
983  }
984 }
985 
986 void
988 {
989  ListenerList::const_iterator it = m_listeners.begin ();
990  for (; it != m_listeners.end (); it++)
991  {
992  (*it)->NotifyTxStart (duration);
993  }
994 }
995 
996 uint32_t
998 {
999  return m_modes.GetNModes ();
1000 }
1001 
1002 UanTxMode
1004 {
1005  NS_ASSERT (n < m_modes.GetNModes ());
1006 
1007  return m_modes[n];
1008 }
1009 
1012 {
1013  return m_pktRx;
1014 }
1015 
1016 
1017 } // namespace ns3
virtual void NotifyTransStartTx(Ptr< Packet > packet, double txPowerDb, UanTxMode txMode)
Called when a transmission is beginning on the attched transducer.
Definition: uan-phy-gen.cc:881
Phase shift keying.
Definition: uan-tx-mode.h:51
virtual bool IsStateBusy(void)
Definition: uan-phy-gen.cc:735
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
Definition: uan-phy-gen.cc:813
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
Definition: uan-phy-gen.cc:790
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
uint32_t GetNModes(void) const
Get the number of modes in this list.
Definition: uan-tx-mode.cc:259
Idle state.
Definition: uan-phy.h:181
Ptr< const AttributeChecker > MakeUanModesListChecker(void)
Definition: uan-tx-mode.cc:303
std::vector< Tap >::const_iterator Iterator
Convenience iterator typedef.
virtual bool IsStateRx(void)
Definition: uan-phy-gen.cc:740
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
double KpToDb(double kp)
Convert kilopascals to dB.
Definition: uan-phy-gen.cc:934
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
virtual void SetEnergyModelCallback(DeviceEnergyModel::ChangeStateCallback cb)
Set the DeviceEnergyModel callback for UanPhy device.
Definition: uan-phy-gen.cc:488
uint32_t m_hops
Number of hops.
Definition: uan-phy-gen.h:204
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void NotifyRxDrop(Ptr< const Packet > packet)
Called when the Phy drops a packet.
Definition: uan-phy.cc:139
Hold variables of type string.
Definition: string.h:41
virtual void SetReceiveErrorCallback(RxErrCallback cb)
Set the callback to be used when a packet is received with errors.
Definition: uan-phy-gen.cc:720
double CalculateSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
Calculate the SINR value for a packet.
Definition: uan-phy-gen.cc:900
virtual void EnergyDepletionHandler(void)
Handle the energy depletion event.
Definition: uan-phy-gen.cc:506
virtual void SetTransducer(Ptr< UanTransducer > trans)
Attach a transducer to this Phy.
Definition: uan-phy-gen.cc:836
def start()
Definition: core.py:1482
Sleeping.
Definition: uan-phy.h:185
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1072
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
virtual ~UanPhyGen()
Dummy destructor, see DoDispose.
Definition: uan-phy-gen.cc:365
Ptr< UniformRandomVariable > m_pg
Provides uniform random variables.
Definition: uan-phy-gen.h:311
Receiving.
Definition: uan-phy.h:183
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
double m_rxRecvPwrDb
Receiver power.
Definition: uan-phy-gen.h:302
double SumTapsFromMaxNc(Time delay, Time duration) const
Compute the non-coherent sum of tap amplitudes starting after a delay from the maximum amplitude for ...
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
virtual void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
Definition: uan-phy-gen.cc:843
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
Definition: uan-phy-gen.cc:584
virtual uint32_t GetNModes(void)
Get the number of transmission modes supported by this Phy.
Definition: uan-phy-gen.cc:997
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:338
Container for UanTxModes.
Definition: uan-tx-mode.h:257
virtual double GetTxPowerDb(void)
Get the current transmit power, in dB.
Definition: uan-phy-gen.cc:784
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
Definition: uan-phy-gen.cc:795
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
ModulationType GetModType(void) const
Get the modulation type of the mode.
Definition: uan-tx-mode.cc:39
double m_rxThreshDb
Receive SINR threshold.
Definition: uan-phy-gen.h:297
void NotifyRxEnd(Ptr< const Packet > packet)
Called when a packet is received without error.
Definition: uan-phy.cc:133
static UanTxMode CreateMode(UanTxMode::ModulationType type, uint32_t dataRateBps, uint32_t phyRateSps, uint32_t cfHz, uint32_t bwHz, uint32_t constSize, std::string name)
Definition: uan-tx-mode.cc:132
Ptr< UanPhyPer > m_per
Error model.
Definition: uan-phy-gen.h:292
virtual void DoDispose()
Destructor implementation.
Definition: uan-phy-gen.cc:413
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Time m_pktRxArrTime
Packet arrival time.
Definition: uan-phy-gen.h:303
bool m_cleared
Flag when we've been cleared.
Definition: uan-phy-gen.h:307
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:327
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:253
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
Definition: uan-phy-gen.cc:263
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:429
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Calculate the SINR value for a packet.
Definition: uan-phy-gen.cc:72
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: pointer.h:210
virtual bool IsStateTx(void)
Definition: uan-phy-gen.cc:745
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
Definition: uan-phy-gen.cc:824
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Definition: uan-phy-gen.cc:873
double m_rxGainDb
Receive gain.
Definition: uan-phy-gen.h:295
uint32_t GetDataRateBps(void) const
Get the data rate of the transmit mode.
Definition: uan-tx-mode.cc:45
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxErrLogger
A packet destined for this Phy was received with error.
Definition: uan-phy-gen.h:318
virtual ~UanPhyPerUmodem()
Destructor.
Definition: uan-phy-gen.cc:248
Channel busy.
Definition: uan-phy.h:182
Hold an unsigned integer type.
Definition: uinteger.h:44
double KpToDb(double kp) const
Convert kilopascals to dB re 1 uPa.
Definition: uan-phy.h:92
Ptr< UanNetDevice > m_device
Device hosting this Phy.
Definition: uan-phy-gen.h:290
virtual Ptr< Packet > GetPacketRx(void) const
Get the packet currently being received.
double m_txPwrDb
Transmit power.
Definition: uan-phy-gen.h:296
The power delay profile returned by propagation models.
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
double m_thresh
SINR threshold.
Definition: uan-phy-gen.h:60
DeviceEnergyModel::ChangeStateCallback m_energyCallback
Energy model callback.
Definition: uan-phy-gen.h:314
double m_ccaThreshDb
CCA busy threshold.
Definition: uan-phy-gen.h:298
void NotifyListenersRxGood(void)
Call UanListener::NotifyRxEndOk on all listeners.
Definition: uan-phy-gen.cc:950
void NotifyListenersCcaEnd(void)
Call UanListener::NotifyCcaEnd on all listeners.
Definition: uan-phy-gen.cc:977
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Ptr< Packet > m_pktRx
Received packet.
Definition: uan-phy-gen.h:300
virtual void SetCcaThresholdDb(double thresh)
Set the threshold for detecting channel busy.
Definition: uan-phy-gen.cc:774
virtual void NotifyIntChange(void)
Called when there has been a change in the ammount of interference this node is experiencing from oth...
Definition: uan-phy-gen.cc:890
UanPdp m_pktRxPdp
Power delay profile of pakket.
Definition: uan-phy-gen.h:304
virtual double CalcSinrDb(Ptr< Packet > pkt, Time arrTime, double rxPowerDb, double ambNoiseDb, UanTxMode mode, UanPdp pdp, const UanTransducer::ArrivalList &arrivalList) const
Calculate the SINR value for a packet.
Definition: uan-phy-gen.cc:123
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
Definition: uan-phy-gen.cc:801
Ptr< UanPhyCalcSinr > m_sinr
SINR calculator.
Definition: uan-phy-gen.h:293
virtual UanTxMode GetMode(uint32_t n)
Get a specific transmission mode.
virtual void SetRxThresholdDb(double thresh)
Set the minimum SINR threshold to receive a packet without errors.
Definition: uan-phy-gen.cc:769
void NotifyRxBegin(Ptr< const Packet > packet)
Called when the Phy begins to receive a packet.
Definition: uan-phy.cc:127
void TxEndEvent()
Event to process end of packet transmission.
Definition: uan-phy-gen.cc:555
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double DbToKp(double db)
Convert dB to kilopascals.
Definition: uan-phy-gen.cc:929
virtual void SetRxGainDb(double gain)
Set the receiver gain.
Definition: uan-phy-gen.cc:758
Frequency shift keying.
Definition: uan-tx-mode.h:53
RxOkCallback m_recOkCb
Callback for packets received without error.
Definition: uan-phy-gen.h:286
UanModesList m_modes
List of modes supported by this PHY.
Definition: uan-phy-gen.h:282
uint32_t GetCenterFreqHz(void) const
Get the transmission center frequency.
Definition: uan-tx-mode.cc:57
Interface for PHY event listener.
Definition: uan-phy.h:146
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:215
double GetValue(double min, double max)
Returns a random double from the uniform distribution with the specified range.
void UpdatePowerConsumption(const State state)
Update energy source with new state.
Definition: uan-phy-gen.cc:495
void NotifyListenersRxStart(void)
Call UanListener::NotifyRxStart on all listeners.
Definition: uan-phy-gen.cc:940
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Calculate the packet error probability based on SINR at the receiver and a tx mode.
Definition: uan-phy-gen.cc:283
State m_state
Phy state.
Definition: uan-phy-gen.h:284
virtual ~UanPhyCalcSinrFhFsk()
Destructor.
Definition: uan-phy-gen.cc:103
void RxEndEvent(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode)
Event to process end of packet reception.
Definition: uan-phy-gen.cc:663
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
Definition: uan-phy.h:82
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:223
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
Definition: uan-phy-gen.cc:818
Ptr< UanMac > m_mac
MAC layer.
Definition: uan-phy-gen.h:291
Iterator GetEnd(void) const
Get the end of the tap list (one beyond the last entry).
Base class for UAN Phy models.
Definition: uan-phy.h:175
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 GetPhyRateSps(void) const
Get the physical signaling rate.
Definition: uan-tx-mode.cc:51
virtual ~UanPhyPerGenDefault()
Destructor.
Definition: uan-phy-gen.cc:210
UanPhyCalcSinrFhFsk()
Constructor.
Definition: uan-phy-gen.cc:99
bool m_disabled
Energy depleted.
Definition: uan-phy-gen.h:308
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
Definition: uan-phy-gen.h:320
virtual bool IsStateIdle(void)
Definition: uan-phy-gen.cc:730
RxErrCallback m_recErrCb
Callback for packets received with errors.
Definition: uan-phy-gen.h:287
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:62
Ptr< UanChannel > m_channel
Attached channel.
Definition: uan-phy-gen.h:288
void NotifyListenersCcaStart(void)
Call UanListener::NotifyCcaStart on all listeners.
Definition: uan-phy-gen.cc:968
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
void AppendMode(UanTxMode mode)
Add mode to this list.
Definition: uan-tx-mode.cc:232
Unspecified/undefined.
Definition: uan-tx-mode.h:54
double GetInterferenceDb(Ptr< Packet > pkt)
Calculate interference power from overlapping packet arrivals, in dB.
Definition: uan-phy-gen.cc:907
void NotifyListenersRxBad(void)
Call UanListener::NotifyRxEndError on all listeners.
Definition: uan-phy-gen.cc:959
Ptr< UanTransducer > m_transducer
Associated transducer.
Definition: uan-phy-gen.h:289
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:1076
UanPhyPerUmodem()
Constructor.
Definition: uan-phy-gen.cc:244
UanPhyPerGenDefault()
Constructor.
Definition: uan-phy-gen.cc:205
Ptr< const AttributeAccessor > MakeUanModesListAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uan-tx-mode.h:314
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:109
UanPhyGen()
Constructor.
Definition: uan-phy-gen.cc:345
virtual ~UanPhyCalcSinrDefault()
Destructor.
Definition: uan-phy-gen.cc:56
A base class which provides memory management and object aggregation.
Definition: object.h:87
uint32_t GetBandwidthHz(void) const
Get the transmission signal bandwidth.
Definition: uan-tx-mode.cc:63
virtual void SendPacket(Ptr< Packet > pkt, uint32_t modeNum)
Send a packet using a specific transmission mode.
Definition: uan-phy-gen.cc:516
Iterator GetBegin(void) const
Get the beginning of the tap vector.
UanTxMode m_pktRxMode
Packet transmission mode at receiver.
Definition: uan-phy-gen.h:305
ListenerList m_listeners
List of listeners.
Definition: uan-phy-gen.h:285
virtual bool IsStateCcaBusy(void)
Definition: uan-phy-gen.cc:751
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
Definition: uan-phy-gen.cc:577
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
Definition: uan-phy-gen.cc:779
double m_minRxSinrDb
Minimum receive SINR during packet reception.
Definition: uan-phy-gen.h:301
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
virtual bool IsStateSleep(void)
Definition: uan-phy-gen.cc:725
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
Definition: uan-phy-gen.cc:830
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
Definition: uan-phy-gen.cc:714
uint32_t GetUid(void) const
Get a unique id for the mode.
Definition: uan-tx-mode.cc:81
double SumTapsNc(Time begin, Time end) const
Compute the non-coherent sum of tap amplitudes between a start and end time.
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
static UanModesList GetDefaultModes(void)
Get the default transmission modes.
Definition: uan-phy-gen.cc:421
a unique identifier for an interface.
Definition: type-id.h:51
virtual double CalcPer(Ptr< Packet > pkt, double sinrDb, UanTxMode mode)
Calculate the packet error probability based on SINR at the receiver and a tx mode.
Definition: uan-phy-gen.cc:231
virtual Ptr< UanNetDevice > GetDevice(void)
Get the device hosting this Phy.
Definition: uan-phy-gen.cc:807
Transmitting.
Definition: uan-phy.h:184
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
virtual void Clear(void)
Clear all pointer references.
Definition: uan-phy-gen.cc:371
UanPhyCalcSinrDefault()
Constructor.
Definition: uan-phy-gen.cc:52
ns3::TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet destined for this Phy was received without error.
Definition: uan-phy-gen.h:316
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
Definition: uan-phy-gen.cc:987
AttributeValue implementation for UanModesList.
Definition: uan-tx-mode.h:314
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
Definition: uan-phy-gen.cc:764