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  .SetGroupName ("Uan")
67  .AddConstructor<UanPhyCalcSinrDefault> ()
68  ;
69  return tid;
70 }
71 
72 double
74  Time arrTime,
75  double rxPowerDb,
76  double ambNoiseDb,
77  UanTxMode mode,
78  UanPdp pdp,
79  const UanTransducer::ArrivalList &arrivalList) const
80 {
81  if (mode.GetModType () == UanTxMode::OTHER)
82  {
83  NS_LOG_WARN ("Calculating SINR for unsupported modulation type");
84  }
85 
86  double intKp = -DbToKp (rxPowerDb); // This packet is in the arrivalList
87  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
88  for (; it != arrivalList.end (); it++)
89  {
90  intKp += DbToKp (it->GetRxPowerDb ());
91  }
92 
93  double totalIntDb = KpToDb (intKp + DbToKp (ambNoiseDb));
94 
95  NS_LOG_DEBUG ("Calculating SINR: RxPower = " << rxPowerDb << " dB. Number of interferers = " << arrivalList.size () << " Interference + noise power = " << totalIntDb << " dB. SINR = " << rxPowerDb - totalIntDb << " dB.");
96  return rxPowerDb - totalIntDb;
97 }
98 
99 /*************** UanPhyCalcSinrFhFsk definition *****************/
101 {
102 
103 }
105 {
106 
107 }
108 
109 TypeId
111 {
112  static TypeId tid = TypeId ("ns3::UanPhyCalcSinrFhFsk")
113  .SetParent<Object> ()
114  .SetGroupName ("Uan")
115  .AddConstructor<UanPhyCalcSinrFhFsk> ()
116  .AddAttribute ("NumberOfHops",
117  "Number of frequencies in hopping pattern.",
118  UintegerValue (13),
120  MakeUintegerChecker<uint32_t> ())
121  ;
122  return tid;
123 }
124 double
126  Time arrTime,
127  double rxPowerDb,
128  double ambNoiseDb,
129  UanTxMode mode,
130  UanPdp pdp,
131  const UanTransducer::ArrivalList &arrivalList) const
132 {
133  if (mode.GetModType () != UanTxMode::FSK)
134  {
135  NS_LOG_WARN ("Calculating SINR for unsupported mode type");
136  }
137 
138 
139 
140  double ts = 1.0 / mode.GetPhyRateSps ();
141  double clearingTime = (m_hops - 1.0) * ts;
142  double csp = pdp.SumTapsFromMaxNc (Seconds (0), Seconds (ts));
143 
144  // Get maximum arrival offset
145  double maxAmp = -1;
146  double maxTapDelay = 0.0;
147  UanPdp::Iterator pit = pdp.GetBegin ();
148  for (; pit != pdp.GetEnd (); pit++)
149  {
150  if (std::abs (pit->GetAmp ()) > maxAmp)
151  {
152  maxAmp = std::abs (pit->GetAmp ());
153  maxTapDelay = pit->GetDelay ().GetSeconds ();
154  }
155  }
156 
157 
158  double effRxPowerDb = rxPowerDb + KpToDb (csp);
159 
160  double isiUpa = rxPowerDb * pdp.SumTapsFromMaxNc (Seconds (ts + clearingTime), Seconds (ts));
161  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
162  double intKp = -DbToKp (effRxPowerDb);
163  for (; it != arrivalList.end (); it++)
164  {
165  UanPdp intPdp = it->GetPdp ();
166  double tDelta = std::abs (arrTime.GetSeconds () + maxTapDelay - it->GetArrivalTime ().GetSeconds ());
167  // We want tDelta in terms of a single symbol (i.e. if tDelta = 7.3 symbol+clearing
168  // times, the offset in terms of the arriving symbol power is
169  // 0.3 symbol+clearing times.
170 
171  int32_t syms = (uint32_t)( (double) tDelta / (ts + clearingTime));
172  tDelta = tDelta - syms * (ts + clearingTime);
173 
174  // Align to pktRx
175  if (arrTime + Seconds (maxTapDelay) > it->GetArrivalTime ())
176  {
177  tDelta = ts + clearingTime - tDelta;
178  }
179 
180  double intPower = 0.0;
181  if (tDelta < ts)
182  {
183  intPower += intPdp.SumTapsNc (Seconds (0), Seconds (ts - tDelta));
184  intPower += intPdp.SumTapsNc (Seconds (ts - tDelta + clearingTime),
185  Seconds (2 * ts - tDelta + clearingTime));
186  }
187  else
188  {
189  Time start = Seconds (ts + clearingTime - tDelta);
190  Time end = start + Seconds (ts);
191  intPower += intPdp.SumTapsNc (start, end);
192 
193  start = start + Seconds (ts + clearingTime);
194  end = start + Seconds (ts);
195  intPower += intPdp.SumTapsNc (start, end);
196  }
197  intKp += DbToKp (it->GetRxPowerDb ()) * intPower;
198  }
199 
200  double totalIntDb = KpToDb (isiUpa + intKp + DbToKp (ambNoiseDb));
201 
202  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.");
203  return effRxPowerDb - totalIntDb;
204 }
205 
206 /*************** UanPhyPerGenDefault definition *****************/
208 {
209 
210 }
211 
213 {
214 
215 }
216 TypeId
218 {
219  static TypeId tid = TypeId ("ns3::UanPhyPerGenDefault")
220  .SetParent<Object> ()
221  .SetGroupName ("Uan")
222  .AddConstructor<UanPhyPerGenDefault> ()
223  .AddAttribute ("Threshold", "SINR cutoff for good packet reception.",
224  DoubleValue (8),
226  MakeDoubleChecker<double> ());
227  return tid;
228 }
229 
230 
231 // Default PER calculation simply compares SINR to a threshold which is configurable
232 // via an attribute.
233 double
235 {
236  if (sinrDb >= m_thresh)
237  {
238  return 0;
239  }
240  else
241  {
242  return 1;
243  }
244 }
245 
246 /*************** UanPhyPerUmodem definition *****************/
248 {
249 
250 }
252 {
253 
254 }
255 
257 {
258  static TypeId tid = TypeId ("ns3::UanPhyPerUmodem")
259  .SetParent<Object> ()
260  .SetGroupName ("Uan")
261  .AddConstructor<UanPhyPerUmodem> ()
262  ;
263  return tid;
264 }
265 
266 double
267 UanPhyPerUmodem::NChooseK (uint32_t n, uint32_t k)
268 {
269  double result;
270 
271  result = 1.0;
272 
273  for (uint32_t i = std::max (k,n - k) + 1; i <= n; ++i)
274  {
275  result *= i;
276  }
277 
278  for (uint32_t i = 2; i <= std::min (k,n - k); ++i)
279  {
280  result /= i;
281  }
282 
283  return result;
284 }
285 
286 double
288 {
289  uint32_t d[] =
290  { 12, 14, 16, 18, 20, 22, 24, 26, 28 };
291  double Bd[] =
292  {
293  33, 281, 2179, 15035LLU, 105166LLU, 692330LLU, 4580007LLU, 29692894LLU,
294  190453145LLU
295  };
296 
297  // double Rc = 1.0 / 2.0;
298  double ebno = std::pow (10.0, sinr / 10.0);
299  double perror = 1.0 / (2.0 + ebno);
300  double P[9];
301 
302  if (sinr >= 10)
303  {
304  return 0;
305  }
306  if (sinr <= 6)
307  {
308  return 1;
309  }
310 
311  for (uint32_t r = 0; r < 9; r++)
312  {
313  double sumd = 0;
314  for (uint32_t k = 0; k < d[r]; k++)
315  {
316  sumd = sumd + NChooseK (d[r] - 1 + k, k) * std::pow (1 - perror, (double) k);
317  }
318  P[r] = std::pow (perror, (double) d[r]) * sumd;
319 
320  }
321 
322  double Pb = 0;
323  for (uint32_t r = 0; r < 8; r++)
324  {
325  Pb = Pb + Bd[r] * P[r];
326  }
327 
328  // cout << "Pb = " << Pb << endl;
329  uint32_t bits = pkt->GetSize () * 8;
330 
331  double Ppacket = 1;
332  double temp = NChooseK (bits, 0);
333  temp *= std::pow ( (1 - Pb), (double) bits);
334  Ppacket -= temp;
335  temp = NChooseK (288, 1) * Pb * std::pow ( (1 - Pb), bits - 1.0);
336  Ppacket -= temp;
337 
338  if (Ppacket > 1)
339  {
340  return 1;
341  }
342  else
343  {
344  return Ppacket;
345  }
346 }
347 
348 /*************** UanPhyGen definition *****************/
350  : UanPhy (),
351  m_state (IDLE),
352  m_channel (0),
353  m_transducer (0),
354  m_device (0),
355  m_mac (0),
356  m_rxGainDb (0),
357  m_txPwrDb (0),
358  m_rxThreshDb (0),
359  m_ccaThreshDb (0),
360  m_pktRx (0),
361  m_cleared (false),
362  m_disabled (false)
363 {
364  m_pg = CreateObject<UniformRandomVariable> ();
365 
367 }
368 
370 {
371 
372 }
373 
374 void
376 {
377  if (m_cleared)
378  {
379  return;
380  }
381  m_cleared = true;
382  m_listeners.clear ();
383  if (m_channel)
384  {
385  m_channel->Clear ();
386  m_channel = 0;
387  }
388  if (m_transducer)
389  {
390  m_transducer->Clear ();
391  m_transducer = 0;
392  }
393  if (m_device)
394  {
395  m_device->Clear ();
396  m_device = 0;
397  }
398  if (m_mac)
399  {
400  m_mac->Clear ();
401  m_mac = 0;
402  }
403  if (m_per)
404  {
405  m_per->Clear ();
406  m_per = 0;
407  }
408  if (m_sinr)
409  {
410  m_sinr->Clear ();
411  m_sinr = 0;
412  }
413  m_pktRx = 0;
414 }
415 
416 void
418 {
419  Clear ();
422 }
423 
426 {
427  UanModesList l;
428  l.AppendMode (UanTxModeFactory::CreateMode (UanTxMode::FSK,80,80,22000,4000,13,"FSK"));
429  l.AppendMode (UanTxModeFactory::CreateMode (UanTxMode::PSK,200, 200, 22000, 4000, 4, "QPSK"));
430  return l;
431 }
432 TypeId
434 {
435 
436  static TypeId tid = TypeId ("ns3::UanPhyGen")
437  .SetParent<UanPhy> ()
438  .SetGroupName ("Uan")
439  .AddConstructor<UanPhyGen> ()
440  .AddAttribute ("CcaThreshold",
441  "Aggregate energy of incoming signals to move to CCA Busy state dB.",
442  DoubleValue (10),
444  MakeDoubleChecker<double> ())
445  .AddAttribute ("RxThreshold",
446  "Required SNR for signal acquisition in dB.",
447  DoubleValue (10),
449  MakeDoubleChecker<double> ())
450  .AddAttribute ("TxPower",
451  "Transmission output power in dB.",
452  DoubleValue (190),
454  MakeDoubleChecker<double> ())
455  .AddAttribute ("RxGain",
456  "Gain added to incoming signal at receiver.",
457  DoubleValue (0),
459  MakeDoubleChecker<double> ())
460  .AddAttribute ("SupportedModes",
461  "List of modes supported by this PHY.",
465  .AddAttribute ("PerModel",
466  "Functor to calculate PER based on SINR and TxMode.",
467  StringValue ("ns3::UanPhyPerGenDefault"),
469  MakePointerChecker<UanPhyPer> ())
470  .AddAttribute ("SinrModel",
471  "Functor to calculate SINR based on pkt arrivals and modes.",
472  StringValue ("ns3::UanPhyCalcSinrDefault"),
474  MakePointerChecker<UanPhyCalcSinr> ())
475  .AddTraceSource ("RxOk",
476  "A packet was received successfully.",
478  "ns3::UanPhy::TracedCallback")
479  .AddTraceSource ("RxError",
480  "A packet was received unsuccessfully.",
482  "ns3::UanPhy::TracedCallback")
483  .AddTraceSource ("Tx",
484  "Packet transmission beginning.",
486  "ns3::UanPhy::TracedCallback")
487  ;
488  return tid;
489 
490 }
491 
492 void
494 {
495  NS_LOG_FUNCTION (this);
496  m_energyCallback = cb;
497 }
498 
499 void
501 {
502  NS_LOG_FUNCTION (this);
503 
504  if (!m_energyCallback.IsNull ())
505  {
506  m_energyCallback (state);
507  }
508 }
509 
510 void
512 {
513  NS_LOG_FUNCTION (this);
514  NS_LOG_DEBUG ("Energy depleted at node " << m_device->GetNode ()->GetId () <<
515  ", stopping rx/tx activities");
516 
517  m_disabled = true;
518 }
519 
520 void
521 UanPhyGen::SendPacket (Ptr<Packet> pkt, uint32_t modeNum)
522 {
523  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Transmitting packet");
524  if (m_disabled)
525  {
526  NS_LOG_DEBUG ("Energy depleted, node cannot transmit any packet. Dropping.");
527  return;
528  }
529 
530  if (m_state == TX)
531  {
532  NS_LOG_DEBUG ("PHY requested to TX while already Transmitting. Dropping packet.");
533  return;
534  }
535  else if (m_state == SLEEP)
536  {
537  NS_LOG_DEBUG ("PHY requested to TX while sleeping. Dropping packet.");
538  return;
539  }
540 
541  UanTxMode txMode = GetMode (modeNum);
542 
543  if (m_pktRx != 0)
544  {
545  m_minRxSinrDb = -1e30;
546  m_pktRx = 0;
547  }
548 
549  m_transducer->Transmit (Ptr<UanPhy> (this), pkt, m_txPwrDb, txMode);
550  m_state = TX;
552  double txdelay = pkt->GetSize () * 8.0 / txMode.GetDataRateBps ();
554  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << " notifying listeners");
555  NotifyListenersTxStart (Seconds (txdelay));
556  m_txLogger (pkt, m_txPwrDb, txMode);
557 }
558 
559 void
561 {
562  if (m_state == SLEEP || m_disabled == true)
563  {
564  NS_LOG_DEBUG ("Transmission ended but node sleeping or dead");
565  return;
566  }
567 
568  NS_ASSERT (m_state == TX);
570  {
571  m_state = CCABUSY;
573  }
574  else
575  {
576  m_state = IDLE;
577  }
579 }
580 
581 void
583 {
584  m_listeners.push_back (listener);
585 }
586 
587 
588 void
589 UanPhyGen::StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
590 {
591  if (m_disabled)
592  {
593  NS_LOG_DEBUG ("Energy depleted, node cannot receive any packet. Dropping.");
594  NotifyRxDrop(pkt); // traced source netanim
595  return;
596  }
597 
598  switch (m_state)
599  {
600  case TX:
601  NotifyRxDrop(pkt); // traced source netanim
602  NS_ASSERT (false);
603  break;
604  case RX:
605  {
606  NS_ASSERT (m_pktRx);
608  m_minRxSinrDb = (newSinrDb < m_minRxSinrDb) ? newSinrDb : m_minRxSinrDb;
609  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Starting RX in RX mode. SINR of pktRx = " << m_minRxSinrDb);
610  NotifyRxBegin(pkt); // traced source netanim
611  }
612  break;
613 
614  case CCABUSY:
615  case IDLE:
616  {
617  NS_ASSERT (!m_pktRx);
618  bool hasmode = false;
619  for (uint32_t i = 0; i < GetNModes (); i++)
620  {
621  if (txMode.GetUid () == GetMode (i).GetUid ())
622  {
623  hasmode = true;
624  break;
625  }
626  }
627  if (!hasmode)
628  {
629  break;
630  }
631 
632 
633  double newsinr = CalculateSinrDb (pkt, Simulator::Now (), rxPowerDb, txMode, pdp);
634  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Starting RX in IDLE mode. SINR = " << newsinr);
635  if (newsinr > m_rxThreshDb)
636  {
637  m_state = RX;
639  NotifyRxBegin(pkt); // traced source netanim
640  m_rxRecvPwrDb = rxPowerDb;
641  m_minRxSinrDb = newsinr;
642  m_pktRx = pkt;
644  m_pktRxMode = txMode;
645  m_pktRxPdp = pdp;
646  double txdelay = pkt->GetSize () * 8.0 / txMode.GetDataRateBps ();
647  Simulator::Schedule (Seconds (txdelay), &UanPhyGen::RxEndEvent, this, pkt, rxPowerDb, txMode);
649  }
650 
651  }
652  break;
653  case SLEEP:
654  NS_LOG_DEBUG ("Sleep mode. Dropping packet.");
655  NotifyRxDrop(pkt); // traced source netanim
656  break;
657  }
658 
660  {
661  m_state = CCABUSY;
663  }
664 
665 }
666 
667 void
668 UanPhyGen::RxEndEvent (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode)
669 {
670  if (pkt != m_pktRx)
671  {
672  return;
673  }
674 
675  if (m_disabled || m_state == SLEEP)
676  {
677  NS_LOG_DEBUG ("Sleep mode or dead. Dropping packet");
678  m_pktRx = 0;
679  NotifyRxDrop(pkt); // traced source netanim
680  return;
681  }
682 
683  NotifyRxEnd(pkt); // traced source netanim
685  {
686  m_state = CCABUSY;
688  }
689  else
690  {
691  m_state = IDLE;
693  }
694 
695  if (m_pg->GetValue (0, 1) > m_per->CalcPer (m_pktRx, m_minRxSinrDb, txMode))
696  {
697  m_rxOkLogger (pkt, m_minRxSinrDb, txMode);
699  if (!m_recOkCb.IsNull ())
700  {
701  m_recOkCb (pkt, m_minRxSinrDb, txMode);
702  }
703 
704  }
705  else
706  {
707  m_rxErrLogger (pkt, m_minRxSinrDb, txMode);
709  if (!m_recErrCb.IsNull ())
710  {
711  m_recErrCb (pkt, m_minRxSinrDb);
712  }
713  }
714 
715  m_pktRx = 0;
716 }
717 
718 void
720 {
721  m_recOkCb = cb;
722 }
723 
724 void
726 {
727  m_recErrCb = cb;
728 }
729 bool
731 {
732  return m_state == SLEEP;
733 }
734 bool
736 {
737  return m_state == IDLE;
738 }
739 bool
741 {
742  return !IsStateIdle () && !IsStateSleep ();
743 }
744 bool
746 {
747  return m_state == RX;
748 }
749 bool
751 {
752  return m_state == TX;
753 }
754 
755 bool
757 {
758  return m_state == CCABUSY;
759 }
760 
761 
762 void
764 {
765  m_rxGainDb = gain;
766 
767 }
768 void
770 {
771  m_txPwrDb = txpwr;
772 }
773 void
775 {
776  m_rxThreshDb = thresh;
777 }
778 void
780 {
781  m_ccaThreshDb = thresh;
782 }
783 double
785 {
786  return m_rxGainDb;
787 }
788 double
790 {
791  return m_txPwrDb;
792 
793 }
794 double
796 {
797  return m_rxThreshDb;
798 }
799 double
801 {
802  return m_ccaThreshDb;
803 }
804 
807 {
808  return m_channel;
809 }
810 
813 {
814  return m_device;
815 }
816 
819 {
820  return m_transducer;
821 }
822 void
824 {
825  m_channel = channel;
826 }
827 
828 void
830 {
831  m_device = device;
832 }
833 
834 void
836 {
837  m_mac = mac;
838 }
839 
840 void
842 {
843  m_transducer = trans;
844  m_transducer->AddPhy (this);
845 }
846 
847 void
849 {
850  if (sleep)
851  {
852  m_state = SLEEP;
853  if (!m_energyCallback.IsNull ())
854  {
856  }
857  }
858  else if (m_state == SLEEP)
859  {
861  {
862  m_state = CCABUSY;
864  }
865  else
866  {
867  m_state = IDLE;
868  }
869 
870  if (!m_energyCallback.IsNull ())
871  {
873  }
874  }
875 }
876 
877 int64_t
878 UanPhyGen::AssignStreams (int64_t stream)
879 {
880  NS_LOG_FUNCTION (this << stream);
881  m_pg->SetStream (stream);
882  return 1;
883 }
884 
885 void
886 UanPhyGen::NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode)
887 {
888  if (m_pktRx)
889  {
890  m_minRxSinrDb = -1e30;
891  }
892 }
893 
894 void
896 {
898  {
899  m_state = IDLE;
901  }
902 }
903 
904 double
905 UanPhyGen::CalculateSinrDb (Ptr<Packet> pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
906 {
907  double noiseDb = m_channel->GetNoiseDbHz ( (double) mode.GetCenterFreqHz () / 1000.0) + 10 * std::log10 (mode.GetBandwidthHz ());
908  return m_sinr->CalcSinrDb (pkt, arrTime, rxPowerDb, noiseDb, mode, pdp, m_transducer->GetArrivalList ());
909 }
910 
911 double
913 {
914 
915  const UanTransducer::ArrivalList &arrivalList = m_transducer->GetArrivalList ();
916 
917  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
918 
919  double interfPower = 0;
920 
921  for (; it != arrivalList.end (); it++)
922  {
923  if (pkt != it->GetPacket ())
924  {
925  interfPower += DbToKp (it->GetRxPowerDb ());
926  }
927  }
928 
929  return KpToDb (interfPower);
930 
931 }
932 
933 double
934 UanPhyGen::DbToKp (double db)
935 {
936  return std::pow (10, db / 10.0);
937 }
938 double
939 UanPhyGen::KpToDb (double kp)
940 {
941  return 10 * std::log10 (kp);
942 }
943 
944 void
946 {
947  ListenerList::const_iterator it = m_listeners.begin ();
948  for (; it != m_listeners.end (); it++)
949  {
950  (*it)->NotifyRxStart ();
951  }
952 
953 }
954 void
956 {
957  ListenerList::const_iterator it = m_listeners.begin ();
958  for (; it != m_listeners.end (); it++)
959  {
960  (*it)->NotifyRxEndOk ();
961  }
962 }
963 void
965 {
966  ListenerList::const_iterator it = m_listeners.begin ();
967  for (; it != m_listeners.end (); it++)
968  {
969  (*it)->NotifyRxEndError ();
970  }
971 }
972 void
974 {
975  ListenerList::const_iterator it = m_listeners.begin ();
976  for (; it != m_listeners.end (); it++)
977  {
978  (*it)->NotifyCcaStart ();
979  }
980 }
981 void
983 {
984  ListenerList::const_iterator it = m_listeners.begin ();
985  for (; it != m_listeners.end (); it++)
986  {
987  (*it)->NotifyCcaEnd ();
988  }
989 }
990 
991 void
993 {
994  ListenerList::const_iterator it = m_listeners.begin ();
995  for (; it != m_listeners.end (); it++)
996  {
997  (*it)->NotifyTxStart (duration);
998  }
999 }
1000 
1001 uint32_t
1003 {
1004  return m_modes.GetNModes ();
1005 }
1006 
1007 UanTxMode
1009 {
1010  NS_ASSERT (n < m_modes.GetNModes ());
1011 
1012  return m_modes[n];
1013 }
1014 
1017 {
1018  return m_pktRx;
1019 }
1020 
1021 
1022 } // 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:886
Phase shift keying.
Definition: uan-tx-mode.h:51
virtual bool IsStateBusy(void)
Definition: uan-phy-gen.cc:740
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
Definition: uan-phy-gen.cc:818
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
Definition: uan-phy-gen.cc:795
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
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:745
#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:939
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:493
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:144
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:725
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:905
virtual void EnergyDepletionHandler(void)
Handle the energy depletion event.
Definition: uan-phy-gen.cc:511
virtual void SetTransducer(Ptr< UanTransducer > trans)
Attach a transducer to this Phy.
Definition: uan-phy-gen.cc:841
def start()
Definition: core.py:1482
Sleeping.
Definition: uan-phy.h:185
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1078
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
virtual ~UanPhyGen()
Dummy destructor, see DoDispose.
Definition: uan-phy-gen.cc:369
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 ...
Packet error rate calculation assuming WHOI Micromodem-like PHY.
Definition: uan-phy-gen.h:74
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:848
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
Definition: uan-phy-gen.cc:589
virtual uint32_t GetNModes(void)
Get the number of transmission modes supported by this Phy.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:339
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:789
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
Definition: uan-phy-gen.cc:800
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:138
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:417
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:334
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:256
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
Definition: uan-phy-gen.cc:267
WHOI Micromodem like FH-FSK model.
Definition: uan-phy-gen.h:180
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:433
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:73
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:750
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
Definition: uan-phy-gen.cc:829
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:878
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:251
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:955
void NotifyListenersCcaEnd(void)
Call UanListener::NotifyCcaEnd on all listeners.
Definition: uan-phy-gen.cc:982
Generic PHY model.
Definition: uan-phy-gen.h:219
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:779
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:895
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:125
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
Definition: uan-phy-gen.cc:806
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:774
void NotifyRxBegin(Ptr< const Packet > packet)
Called when the Phy begins to receive a packet.
Definition: uan-phy.cc:132
void TxEndEvent()
Event to process end of packet transmission.
Definition: uan-phy-gen.cc:560
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:934
virtual void SetRxGainDb(double gain)
Set the receiver gain.
Definition: uan-phy-gen.cc:763
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:217
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:500
void NotifyListenersRxStart(void)
Call UanListener::NotifyRxStart on all listeners.
Definition: uan-phy-gen.cc:945
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:287
State m_state
Phy state.
Definition: uan-phy-gen.h:284
virtual ~UanPhyCalcSinrFhFsk()
Destructor.
Definition: uan-phy-gen.cc:104
void RxEndEvent(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode)
Event to process end of packet reception.
Definition: uan-phy-gen.cc:668
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:823
Default SINR calculator for UanPhyGen.
Definition: uan-phy-gen.h:127
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:212
UanPhyCalcSinrFhFsk()
Constructor.
Definition: uan-phy-gen.cc:100
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:735
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:973
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
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:912
void NotifyListenersRxBad(void)
Call UanListener::NotifyRxEndError on all listeners.
Definition: uan-phy-gen.cc:964
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:1082
UanPhyPerUmodem()
Constructor.
Definition: uan-phy-gen.cc:247
UanPhyPerGenDefault()
Constructor.
Definition: uan-phy-gen.cc:207
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:110
UanPhyGen()
Constructor.
Definition: uan-phy-gen.cc:349
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:521
Default Packet Error Rate calculator for UanPhyGen.
Definition: uan-phy-gen.h:43
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:756
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
Definition: uan-phy-gen.cc:582
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
Definition: uan-phy-gen.cc:784
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:730
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
Definition: uan-phy-gen.cc:835
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
Definition: uan-phy-gen.cc:719
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:425
a unique identifier for an interface.
Definition: type-id.h:57
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:234
virtual Ptr< UanNetDevice > GetDevice(void)
Get the device hosting this Phy.
Definition: uan-phy-gen.cc:812
Transmitting.
Definition: uan-phy.h:184
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
virtual void Clear(void)
Clear all pointer references.
Definition: uan-phy-gen.cc:375
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:992
AttributeValue implementation for UanModesList.
Definition: uan-tx-mode.h:314
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
Definition: uan-phy-gen.cc:769