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")
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")
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<UanPhyPer> ()
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<UanPhyPer> ()
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_pktTx (0),
362  m_cleared (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_state = DISABLED;
518  if(m_txEndEvent.IsRunning ())
519  {
522  m_pktTx = 0;
523  }
524  if(m_rxEndEvent.IsRunning ())
525  {
528  m_pktRx = 0;
529  }
530 }
531 
532 void
534 {
535  NS_LOG_FUNCTION (this);
536  NS_LOG_DEBUG ("Energy recharged at node " << m_device->GetNode ()->GetId () <<
537  ", restoring rx/tx activities");
538 
539  m_state = IDLE;
540 }
541 
542 void
543 UanPhyGen::SendPacket (Ptr<Packet> pkt, uint32_t modeNum)
544 {
545  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Transmitting packet");
546  if (m_state == DISABLED)
547  {
548  NS_LOG_DEBUG ("Energy depleted, node cannot transmit any packet. Dropping.");
549  return;
550  }
551 
552  if (m_state == TX)
553  {
554  NS_LOG_DEBUG ("PHY requested to TX while already Transmitting. Dropping packet.");
555  return;
556  }
557  else if (m_state == SLEEP)
558  {
559  NS_LOG_DEBUG ("PHY requested to TX while sleeping. Dropping packet.");
560  return;
561  }
562 
563  UanTxMode txMode = GetMode (modeNum);
564 
565  if (m_pktRx != 0)
566  {
567  m_minRxSinrDb = -1e30;
568  m_pktRx = 0;
569  }
570 
571  m_transducer->Transmit (Ptr<UanPhy> (this), pkt, m_txPwrDb, txMode);
572  m_state = TX;
574  double txdelay = pkt->GetSize () * 8.0 / txMode.GetDataRateBps ();
575  m_pktTx = pkt;
577  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << " notifying listeners");
578  NotifyListenersTxStart (Seconds (txdelay));
579  m_txLogger (pkt, m_txPwrDb, txMode);
580 }
581 
582 void
584 {
585  if (m_state == SLEEP || m_state == DISABLED)
586  {
587  NS_LOG_DEBUG ("Transmission ended but node sleeping or dead");
588  return;
589  }
590 
591  NS_ASSERT (m_state == TX);
593  {
594  m_state = CCABUSY;
596  }
597  else
598  {
599  m_state = IDLE;
600  }
602 }
603 
604 void
606 {
607  m_listeners.push_back (listener);
608 }
609 
610 
611 void
612 UanPhyGen::StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
613 {
614  switch (m_state)
615  {
616  case DISABLED:
617  NS_LOG_DEBUG ("Energy depleted, node cannot receive any packet. Dropping.");
618  NotifyRxDrop(pkt); // traced source netanim
619  return;
620  case TX:
621  NotifyRxDrop(pkt); // traced source netanim
622  NS_ASSERT (false);
623  break;
624  case RX:
625  {
626  NS_ASSERT (m_pktRx);
628  m_minRxSinrDb = (newSinrDb < m_minRxSinrDb) ? newSinrDb : m_minRxSinrDb;
629  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Starting RX in RX mode. SINR of pktRx = " << m_minRxSinrDb);
630  NotifyRxBegin(pkt); // traced source netanim
631  }
632  break;
633 
634  case CCABUSY:
635  case IDLE:
636  {
637  NS_ASSERT (!m_pktRx);
638  bool hasmode = false;
639  for (uint32_t i = 0; i < GetNModes (); i++)
640  {
641  if (txMode.GetUid () == GetMode (i).GetUid ())
642  {
643  hasmode = true;
644  break;
645  }
646  }
647  if (!hasmode)
648  {
649  break;
650  }
651 
652 
653  double newsinr = CalculateSinrDb (pkt, Simulator::Now (), rxPowerDb, txMode, pdp);
654  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Starting RX in IDLE mode. SINR = " << newsinr);
655  if (newsinr > m_rxThreshDb)
656  {
657  m_state = RX;
659  NotifyRxBegin(pkt); // traced source netanim
660  m_rxRecvPwrDb = rxPowerDb;
661  m_minRxSinrDb = newsinr;
662  m_pktRx = pkt;
664  m_pktRxMode = txMode;
665  m_pktRxPdp = pdp;
666  double txdelay = pkt->GetSize () * 8.0 / txMode.GetDataRateBps ();
667  m_rxEndEvent = Simulator::Schedule (Seconds (txdelay), &UanPhyGen::RxEndEvent, this, pkt, rxPowerDb, txMode);
669  }
670 
671  }
672  break;
673  case SLEEP:
674  NS_LOG_DEBUG ("Sleep mode. Dropping packet.");
675  NotifyRxDrop(pkt); // traced source netanim
676  break;
677  }
678 
680  {
681  m_state = CCABUSY;
683  }
684 
685 }
686 
687 void
688 UanPhyGen::RxEndEvent (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode)
689 {
690  if (pkt != m_pktRx)
691  {
692  return;
693  }
694 
695  if (m_state == DISABLED || m_state == SLEEP)
696  {
697  NS_LOG_DEBUG ("Sleep mode or dead. Dropping packet");
698  m_pktRx = 0;
699  NotifyRxDrop(pkt); // traced source netanim
700  return;
701  }
702 
703  NotifyRxEnd(pkt); // traced source netanim
705  {
706  m_state = CCABUSY;
708  }
709  else
710  {
711  m_state = IDLE;
713  }
714 
715  if (m_pg->GetValue (0, 1) > m_per->CalcPer (m_pktRx, m_minRxSinrDb, txMode))
716  {
717  m_rxOkLogger (pkt, m_minRxSinrDb, txMode);
719  if (!m_recOkCb.IsNull ())
720  {
721  m_recOkCb (pkt, m_minRxSinrDb, txMode);
722  }
723 
724  }
725  else
726  {
727  m_rxErrLogger (pkt, m_minRxSinrDb, txMode);
729  if (!m_recErrCb.IsNull ())
730  {
731  m_recErrCb (pkt, m_minRxSinrDb);
732  }
733  }
734 
735  m_pktRx = 0;
736 }
737 
738 void
740 {
741  m_recOkCb = cb;
742 }
743 
744 void
746 {
747  m_recErrCb = cb;
748 }
749 bool
751 {
752  return m_state == SLEEP;
753 }
754 bool
756 {
757  return m_state == IDLE;
758 }
759 bool
761 {
762  return !IsStateIdle () && !IsStateSleep ();
763 }
764 bool
766 {
767  return m_state == RX;
768 }
769 bool
771 {
772  return m_state == TX;
773 }
774 
775 bool
777 {
778  return m_state == CCABUSY;
779 }
780 
781 
782 void
784 {
785  m_rxGainDb = gain;
786 
787 }
788 void
790 {
791  m_txPwrDb = txpwr;
792 }
793 void
795 {
796  m_rxThreshDb = thresh;
797 }
798 void
800 {
801  m_ccaThreshDb = thresh;
802 }
803 double
805 {
806  return m_rxGainDb;
807 }
808 double
810 {
811  return m_txPwrDb;
812 
813 }
814 double
816 {
817  return m_rxThreshDb;
818 }
819 double
821 {
822  return m_ccaThreshDb;
823 }
824 
827 {
828  return m_channel;
829 }
830 
833 {
834  return m_device;
835 }
836 
839 {
840  return m_transducer;
841 }
842 void
844 {
845  m_channel = channel;
846 }
847 
848 void
850 {
851  m_device = device;
852 }
853 
854 void
856 {
857  m_mac = mac;
858 }
859 
860 void
862 {
863  m_transducer = trans;
864  m_transducer->AddPhy (this);
865 }
866 
867 void
869 {
870  if (sleep)
871  {
872  m_state = SLEEP;
873  if (!m_energyCallback.IsNull ())
874  {
876  }
877  }
878  else if (m_state == SLEEP)
879  {
881  {
882  m_state = CCABUSY;
884  }
885  else
886  {
887  m_state = IDLE;
888  }
889 
890  if (!m_energyCallback.IsNull ())
891  {
893  }
894  }
895 }
896 
897 int64_t
898 UanPhyGen::AssignStreams (int64_t stream)
899 {
900  NS_LOG_FUNCTION (this << stream);
901  m_pg->SetStream (stream);
902  return 1;
903 }
904 
905 void
906 UanPhyGen::NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode)
907 {
908  if (m_pktRx)
909  {
910  m_minRxSinrDb = -1e30;
911  }
912 }
913 
914 void
916 {
918  {
919  m_state = IDLE;
921  }
922 }
923 
924 double
925 UanPhyGen::CalculateSinrDb (Ptr<Packet> pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
926 {
927  double noiseDb = m_channel->GetNoiseDbHz ( (double) mode.GetCenterFreqHz () / 1000.0) + 10 * std::log10 (mode.GetBandwidthHz ());
928  return m_sinr->CalcSinrDb (pkt, arrTime, rxPowerDb, noiseDb, mode, pdp, m_transducer->GetArrivalList ());
929 }
930 
931 double
933 {
934 
935  const UanTransducer::ArrivalList &arrivalList = m_transducer->GetArrivalList ();
936 
937  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
938 
939  double interfPower = 0;
940 
941  for (; it != arrivalList.end (); it++)
942  {
943  if (pkt != it->GetPacket ())
944  {
945  interfPower += DbToKp (it->GetRxPowerDb ());
946  }
947  }
948 
949  return KpToDb (interfPower);
950 
951 }
952 
953 double
954 UanPhyGen::DbToKp (double db)
955 {
956  return std::pow (10, db / 10.0);
957 }
958 double
959 UanPhyGen::KpToDb (double kp)
960 {
961  return 10 * std::log10 (kp);
962 }
963 
964 void
966 {
967  ListenerList::const_iterator it = m_listeners.begin ();
968  for (; it != m_listeners.end (); it++)
969  {
970  (*it)->NotifyRxStart ();
971  }
972 
973 }
974 void
976 {
977  ListenerList::const_iterator it = m_listeners.begin ();
978  for (; it != m_listeners.end (); it++)
979  {
980  (*it)->NotifyRxEndOk ();
981  }
982 }
983 void
985 {
986  ListenerList::const_iterator it = m_listeners.begin ();
987  for (; it != m_listeners.end (); it++)
988  {
989  (*it)->NotifyRxEndError ();
990  }
991 }
992 void
994 {
995  ListenerList::const_iterator it = m_listeners.begin ();
996  for (; it != m_listeners.end (); it++)
997  {
998  (*it)->NotifyCcaStart ();
999  }
1000 }
1001 void
1003 {
1004  ListenerList::const_iterator it = m_listeners.begin ();
1005  for (; it != m_listeners.end (); it++)
1006  {
1007  (*it)->NotifyCcaEnd ();
1008  }
1009 }
1010 
1011 void
1013 {
1014  ListenerList::const_iterator it = m_listeners.begin ();
1015  for (; it != m_listeners.end (); it++)
1016  {
1017  (*it)->NotifyTxStart (duration);
1018  }
1019 }
1020 
1021 uint32_t
1023 {
1024  return m_modes.GetNModes ();
1025 }
1026 
1027 UanTxMode
1029 {
1030  NS_ASSERT (n < m_modes.GetNModes ());
1031 
1032  return m_modes[n];
1033 }
1034 
1037 {
1038  return m_pktRx;
1039 }
1040 
1041 
1042 } // 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:906
Phase shift keying.
Definition: uan-tx-mode.h:51
tuple channel
Definition: third.py:85
virtual bool IsStateBusy(void)
Definition: uan-phy-gen.cc:760
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
Definition: uan-phy-gen.cc:838
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
Definition: uan-phy-gen.cc:815
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:765
#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:959
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:205
#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
Ptr< Packet > m_pktTx
Sent packet.
Definition: uan-phy-gen.h:303
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:745
#define min(a, b)
Definition: 80211b.c:44
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:925
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:861
def start()
Definition: core.py:1482
Sleeping.
Definition: uan-phy.h:185
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
#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:316
Receiving.
Definition: uan-phy.h:183
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:75
#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:305
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:75
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:792
virtual void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
Definition: uan-phy-gen.cc:868
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
Definition: uan-phy-gen.cc:612
virtual uint32_t GetNModes(void)
Get the number of transmission modes supported by this Phy.
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:809
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: simulator.cc:321
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
Definition: uan-phy-gen.cc:820
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
EventId m_rxEndEvent
Rx event.
Definition: uan-phy-gen.h:313
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:299
void NotifyTxDrop(Ptr< const Packet > packet)
Called when the transducer attempts to transmit a new packet while already transmitting a prior packe...
Definition: uan-phy.cc:126
void NotifyRxEnd(Ptr< const Packet > packet)
Called when a packet is received without error.
Definition: uan-phy.cc:138
EventId m_txEndEvent
Tx event.
Definition: uan-phy-gen.h:312
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:294
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:306
bool m_cleared
Flag when we've been cleared.
Definition: uan-phy-gen.h:310
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
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:181
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:220
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
virtual bool IsStateTx(void)
Definition: uan-phy-gen.cc:770
#define max(a, b)
Definition: 80211b.c:45
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
Definition: uan-phy-gen.cc:849
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:898
double m_rxGainDb
Receive gain.
Definition: uan-phy-gen.h:297
virtual void EnergyRechargeHandler(void)
Handle the energy recharge event.
Definition: uan-phy-gen.cc:533
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:323
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:292
virtual Ptr< Packet > GetPacketRx(void) const
Get the packet currently being received.
double m_txPwrDb
Transmit power.
Definition: uan-phy-gen.h:298
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:61
Calculate packet error probability, based on received SINR and modulation (mode). ...
Definition: uan-phy.h:110
DeviceEnergyModel::ChangeStateCallback m_energyCallback
Energy model callback.
Definition: uan-phy-gen.h:319
double m_ccaThreshDb
CCA busy threshold.
Definition: uan-phy-gen.h:300
void NotifyListenersRxGood(void)
Call UanListener::NotifyRxEndOk on all listeners.
Definition: uan-phy-gen.cc:975
void NotifyListenersCcaEnd(void)
Call UanListener::NotifyCcaEnd on all listeners.
Generic PHY model.
Definition: uan-phy-gen.h:220
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Ptr< Packet > m_pktRx
Received packet.
Definition: uan-phy-gen.h:302
tuple mac
Definition: third.py:92
virtual void SetCcaThresholdDb(double thresh)
Set the threshold for detecting channel busy.
Definition: uan-phy-gen.cc:799
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:915
UanPdp m_pktRxPdp
Power delay profile of pakket.
Definition: uan-phy-gen.h:307
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:826
Ptr< UanPhyCalcSinr > m_sinr
SINR calculator.
Definition: uan-phy-gen.h:295
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:794
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:583
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:954
virtual void SetRxGainDb(double gain)
Set the receiver gain.
Definition: uan-phy-gen.cc:783
Frequency shift keying.
Definition: uan-tx-mode.h:53
RxOkCallback m_recOkCb
Callback for packets received without error.
Definition: uan-phy-gen.h:288
UanModesList m_modes
List of modes supported by this PHY.
Definition: uan-phy-gen.h:284
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)
Get the next random value, as a double in 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:965
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:286
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:688
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
Definition: uan-phy.h:82
virtual Ptr< UanNetDevice > GetDevice(void) const
Get the device hosting this Phy.
Definition: uan-phy-gen.cc:832
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
Definition: uan-phy-gen.cc:843
Default SINR calculator for UanPhyGen.
Definition: uan-phy-gen.h:128
Class used for calculating SINR of packet in UanPhy.
Definition: uan-phy.h:44
Ptr< UanMac > m_mac
MAC layer.
Definition: uan-phy-gen.h:293
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
#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:325
virtual bool IsStateIdle(void)
Definition: uan-phy-gen.cc:755
RxErrCallback m_recErrCb
Callback for packets received with errors.
Definition: uan-phy-gen.h:289
#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:290
void NotifyListenersCcaStart(void)
Call UanListener::NotifyCcaStart on all listeners.
Definition: uan-phy-gen.cc:993
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
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:932
void NotifyListenersRxBad(void)
Call UanListener::NotifyRxEndError on all listeners.
Definition: uan-phy-gen.cc:984
Ptr< UanTransducer > m_transducer
Associated transducer.
Definition: uan-phy-gen.h:291
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:1274
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
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:543
Default Packet Error Rate calculator for UanPhyGen.
Definition: uan-phy-gen.h:44
Iterator GetBegin(void) const
Get the beginning of the tap vector.
UanTxMode m_pktRxMode
Packet transmission mode at receiver.
Definition: uan-phy-gen.h:308
ListenerList m_listeners
List of listeners.
Definition: uan-phy-gen.h:287
virtual bool IsStateCcaBusy(void)
Definition: uan-phy-gen.cc:776
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
Definition: uan-phy-gen.cc:605
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
Definition: uan-phy-gen.cc:804
double m_minRxSinrDb
Minimum receive SINR during packet reception.
Definition: uan-phy-gen.h:304
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:750
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
Definition: uan-phy-gen.cc:855
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
Definition: uan-phy-gen.cc:739
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:58
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
Transmitting.
Definition: uan-phy.h:184
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
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:321
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
AttributeValue implementation for UanModesList.
Definition: uan-tx-mode.h:314
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
Definition: uan-phy-gen.cc:789