A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/log.h"
32 #include "ns3/uan-tx-mode.h"
33 #include "ns3/node.h"
34 #include "ns3/uinteger.h"
35 #include "ns3/energy-source-container.h"
36 #include "ns3/acoustic-modem-energy-model.h"
37 
38 
39 NS_LOG_COMPONENT_DEFINE ("UanPhyGen");
40 
41 namespace ns3 {
42 
44  ;
45 NS_OBJECT_ENSURE_REGISTERED (UanPhyPerGenDefault)
46  ;
47 NS_OBJECT_ENSURE_REGISTERED (UanPhyCalcSinrDefault)
48  ;
49 NS_OBJECT_ENSURE_REGISTERED (UanPhyCalcSinrFhFsk)
50  ;
51 NS_OBJECT_ENSURE_REGISTERED (UanPhyPerUmodem)
52  ;
53 
54 
55 /*************** UanPhyCalcSinrDefault definition *****************/
57 {
58 
59 }
61 {
62 
63 }
64 
65 TypeId
67 {
68  static TypeId tid = TypeId ("ns3::UanPhyCalcSinrDefault")
69  .SetParent<Object> ()
70  .AddConstructor<UanPhyCalcSinrDefault> ()
71  ;
72  return tid;
73 }
74 
75 double
77  Time arrTime,
78  double rxPowerDb,
79  double ambNoiseDb,
80  UanTxMode mode,
81  UanPdp pdp,
82  const UanTransducer::ArrivalList &arrivalList) const
83 {
84  if (mode.GetModType () == UanTxMode::OTHER)
85  {
86  NS_LOG_WARN ("Calculating SINR for unsupported modulation type");
87  }
88 
89  double intKp = -DbToKp (rxPowerDb); // This packet is in the arrivalList
90  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
91  for (; it != arrivalList.end (); it++)
92  {
93  intKp += DbToKp (it->GetRxPowerDb ());
94  }
95 
96  double totalIntDb = KpToDb (intKp + DbToKp (ambNoiseDb));
97 
98  NS_LOG_DEBUG ("Calculating SINR: RxPower = " << rxPowerDb << " dB. Number of interferers = " << arrivalList.size () << " Interference + noise power = " << totalIntDb << " dB. SINR = " << rxPowerDb - totalIntDb << " dB.");
99  return rxPowerDb - totalIntDb;
100 }
101 
102 /*************** UanPhyCalcSinrFhFsk definition *****************/
104 {
105 
106 }
108 {
109 
110 }
111 
112 TypeId
114 {
115  static TypeId tid = TypeId ("ns3::UanPhyCalcSinrFhFsk")
116  .SetParent<Object> ()
117  .AddConstructor<UanPhyCalcSinrFhFsk> ()
118  .AddAttribute ("NumberOfHops",
119  "Number of frequencies in hopping pattern.",
120  UintegerValue (13),
121  MakeUintegerAccessor (&UanPhyCalcSinrFhFsk::m_hops),
122  MakeUintegerChecker<uint32_t> ())
123  ;
124  return tid;
125 }
126 double
128  Time arrTime,
129  double rxPowerDb,
130  double ambNoiseDb,
131  UanTxMode mode,
132  UanPdp pdp,
133  const UanTransducer::ArrivalList &arrivalList) const
134 {
135  if (mode.GetModType () != UanTxMode::FSK)
136  {
137  NS_LOG_WARN ("Calculating SINR for unsupported mode type");
138  }
139 
140 
141 
142  double ts = 1.0 / mode.GetPhyRateSps ();
143  double clearingTime = (m_hops - 1.0) * ts;
144  double csp = pdp.SumTapsFromMaxNc (Seconds (0), Seconds (ts));
145 
146  // Get maximum arrival offset
147  double maxAmp = -1;
148  double maxTapDelay = 0.0;
149  UanPdp::Iterator pit = pdp.GetBegin ();
150  for (; pit != pdp.GetEnd (); pit++)
151  {
152  if (std::abs (pit->GetAmp ()) > maxAmp)
153  {
154  maxAmp = std::abs (pit->GetAmp ());
155  maxTapDelay = pit->GetDelay ().GetSeconds ();
156  }
157  }
158 
159 
160  double effRxPowerDb = rxPowerDb + KpToDb (csp);
161 
162  double isiUpa = rxPowerDb * pdp.SumTapsFromMaxNc (Seconds (ts + clearingTime), Seconds (ts));
163  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
164  double intKp = -DbToKp (effRxPowerDb);
165  for (; it != arrivalList.end (); it++)
166  {
167  UanPdp intPdp = it->GetPdp ();
168  double tDelta = std::abs (arrTime.GetSeconds () + maxTapDelay - it->GetArrivalTime ().GetSeconds ());
169  // We want tDelta in terms of a single symbol (i.e. if tDelta = 7.3 symbol+clearing
170  // times, the offset in terms of the arriving symbol power is
171  // 0.3 symbol+clearing times.
172 
173  int32_t syms = (uint32_t)( (double) tDelta / (ts + clearingTime));
174  tDelta = tDelta - syms * (ts + clearingTime);
175 
176  // Align to pktRx
177  if (arrTime + Seconds (maxTapDelay) > it->GetArrivalTime ())
178  {
179  tDelta = ts + clearingTime - tDelta;
180  }
181 
182  double intPower = 0.0;
183  if (tDelta < ts)
184  {
185  intPower += intPdp.SumTapsNc (Seconds (0), Seconds (ts - tDelta));
186  intPower += intPdp.SumTapsNc (Seconds (ts - tDelta + clearingTime),
187  Seconds (2 * ts - tDelta + clearingTime));
188  }
189  else
190  {
191  Time start = Seconds (ts + clearingTime - tDelta);
192  Time end = start + Seconds (ts);
193  intPower += intPdp.SumTapsNc (start, end);
194 
195  start = start + Seconds (ts + clearingTime);
196  end = start + Seconds (ts);
197  intPower += intPdp.SumTapsNc (start, end);
198  }
199  intKp += DbToKp (it->GetRxPowerDb ()) * intPower;
200  }
201 
202  double totalIntDb = KpToDb (isiUpa + intKp + DbToKp (ambNoiseDb));
203 
204  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.");
205  return effRxPowerDb - totalIntDb;
206 }
207 
208 /*************** UanPhyPerGenDefault definition *****************/
210 {
211 
212 }
213 
215 {
216 
217 }
218 TypeId
220 {
221  static TypeId tid = TypeId ("ns3::UanPhyPerGenDefault")
222  .SetParent<Object> ()
223  .AddConstructor<UanPhyPerGenDefault> ()
224  .AddAttribute ("Threshold", "SINR cutoff for good packet reception.",
225  DoubleValue (8),
226  MakeDoubleAccessor (&UanPhyPerGenDefault::m_thresh),
227  MakeDoubleChecker<double> ());
228  return tid;
229 }
230 
231 
232 // Default PER calculation simply compares SINR to a threshold which is configurable
233 // via an attribute.
234 double
236 {
237  if (sinrDb >= m_thresh)
238  {
239  return 0;
240  }
241  else
242  {
243  return 1;
244  }
245 }
246 
247 /*************** UanPhyPerUmodem definition *****************/
249 {
250 
251 }
253 {
254 
255 }
256 
258 {
259  static TypeId tid = TypeId ("ns3::UanPhyPerUmodem")
260  .SetParent<Object> ()
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  .AddConstructor<UanPhyGen> ()
439  .AddAttribute ("CcaThreshold",
440  "Aggregate energy of incoming signals to move to CCA Busy state dB.",
441  DoubleValue (10),
442  MakeDoubleAccessor (&UanPhyGen::m_ccaThreshDb),
443  MakeDoubleChecker<double> ())
444  .AddAttribute ("RxThreshold",
445  "Required SNR for signal acquisition in dB.",
446  DoubleValue (10),
447  MakeDoubleAccessor (&UanPhyGen::m_rxThreshDb),
448  MakeDoubleChecker<double> ())
449  .AddAttribute ("TxPower",
450  "Transmission output power in dB.",
451  DoubleValue (190),
452  MakeDoubleAccessor (&UanPhyGen::m_txPwrDb),
453  MakeDoubleChecker<double> ())
454  .AddAttribute ("RxGain",
455  "Gain added to incoming signal at receiver.",
456  DoubleValue (0),
457  MakeDoubleAccessor (&UanPhyGen::m_rxGainDb),
458  MakeDoubleChecker<double> ())
459  .AddAttribute ("SupportedModes",
460  "List of modes supported by this PHY.",
462  MakeUanModesListAccessor (&UanPhyGen::m_modes),
463  MakeUanModesListChecker () )
464  .AddAttribute ("PerModel",
465  "Functor to calculate PER based on SINR and TxMode.",
466  PointerValue (CreateObject<UanPhyPerGenDefault> ()),
467  MakePointerAccessor (&UanPhyGen::m_per),
468  MakePointerChecker<UanPhyPer> ())
469  .AddAttribute ("SinrModel",
470  "Functor to calculate SINR based on pkt arrivals and modes.",
471  PointerValue (CreateObject<UanPhyCalcSinrDefault> ()),
472  MakePointerAccessor (&UanPhyGen::m_sinr),
473  MakePointerChecker<UanPhyCalcSinr> ())
474  .AddTraceSource ("RxOk",
475  "A packet was received successfully.",
477  .AddTraceSource ("RxError",
478  "A packet was received unsuccessfully.",
480  .AddTraceSource ("Tx",
481  "Packet transmission beginning.",
483  ;
484  return tid;
485 
486 }
487 
488 void
490 {
491  NS_LOG_FUNCTION (this);
492  m_energyCallback = cb;
493 }
494 
495 void
497 {
498  NS_LOG_FUNCTION (this);
499 
500  if (!m_energyCallback.IsNull ())
501  {
502  m_energyCallback (state);
503  }
504 }
505 
506 void
508 {
509  NS_LOG_FUNCTION (this);
510  NS_LOG_DEBUG ("Energy depleted at node " << m_device->GetNode ()->GetId () <<
511  ", stopping rx/tx activities");
512 
513  m_disabled = true;
514 }
515 
516 void
517 UanPhyGen::SendPacket (Ptr<Packet> pkt, uint32_t modeNum)
518 {
519  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Transmitting packet");
520  if (m_disabled)
521  {
522  NS_LOG_DEBUG ("Energy depleted, node cannot transmit any packet. Dropping.");
523  return;
524  }
525 
526  if (m_state == TX)
527  {
528  NS_LOG_DEBUG ("PHY requested to TX while already Transmitting. Dropping packet.");
529  return;
530  }
531  else if (m_state == SLEEP)
532  {
533  NS_LOG_DEBUG ("PHY requested to TX while sleeping. Dropping packet.");
534  return;
535  }
536 
537  UanTxMode txMode = GetMode (modeNum);
538 
539  if (m_pktRx != 0)
540  {
541  m_minRxSinrDb = -1e30;
542  m_pktRx = 0;
543  }
544 
545  m_transducer->Transmit (Ptr<UanPhy> (this), pkt, m_txPwrDb, txMode);
546  m_state = TX;
548  double txdelay = pkt->GetSize () * 8.0 / txMode.GetDataRateBps ();
549  Simulator::Schedule (Seconds (txdelay), &UanPhyGen::TxEndEvent, this);
550  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << " notifying listeners");
551  NotifyListenersTxStart (Seconds (txdelay));
552  m_txLogger (pkt, m_txPwrDb, txMode);
553 }
554 
555 void
557 {
558  if (m_state == SLEEP || m_disabled == true)
559  {
560  NS_LOG_DEBUG ("Transmission ended but node sleeping or dead");
561  return;
562  }
563 
564  NS_ASSERT (m_state == TX);
566  {
567  m_state = CCABUSY;
569  }
570  else
571  {
572  m_state = IDLE;
573  }
575 }
576 
577 void
579 {
580  m_listeners.push_back (listener);
581 }
582 
583 
584 void
585 UanPhyGen::StartRxPacket (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
586 {
587  if (m_disabled)
588  {
589  NS_LOG_DEBUG ("Energy depleted, node cannot receive any packet. Dropping.");
590  NotifyRxDrop(pkt); // traced source netanim
591  return;
592  }
593 
594  switch (m_state)
595  {
596  case TX:
597  NotifyRxDrop(pkt); // traced source netanim
598  NS_ASSERT (false);
599  break;
600  case RX:
601  {
602  NS_ASSERT (m_pktRx);
604  m_minRxSinrDb = (newSinrDb < m_minRxSinrDb) ? newSinrDb : m_minRxSinrDb;
605  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Starting RX in RX mode. SINR of pktRx = " << m_minRxSinrDb);
606  NotifyRxBegin(pkt); // traced source netanim
607  }
608  break;
609 
610  case CCABUSY:
611  case IDLE:
612  {
613  NS_ASSERT (!m_pktRx);
614  bool hasmode = false;
615  for (uint32_t i = 0; i < GetNModes (); i++)
616  {
617  if (txMode.GetUid () == GetMode (i).GetUid ())
618  {
619  hasmode = true;
620  break;
621  }
622  }
623  if (!hasmode)
624  {
625  break;
626  }
627 
628 
629  double newsinr = CalculateSinrDb (pkt, Simulator::Now (), rxPowerDb, txMode, pdp);
630  NS_LOG_DEBUG ("PHY " << m_mac->GetAddress () << ": Starting RX in IDLE mode. SINR = " << newsinr);
631  if (newsinr > m_rxThreshDb)
632  {
633  m_state = RX;
635  NotifyRxBegin(pkt); // traced source netanim
636  m_rxRecvPwrDb = rxPowerDb;
637  m_minRxSinrDb = newsinr;
638  m_pktRx = pkt;
640  m_pktRxMode = txMode;
641  m_pktRxPdp = pdp;
642  double txdelay = pkt->GetSize () * 8.0 / txMode.GetDataRateBps ();
643  Simulator::Schedule (Seconds (txdelay), &UanPhyGen::RxEndEvent, this, pkt, rxPowerDb, txMode);
645  }
646 
647  }
648  break;
649  case SLEEP:
650  NS_LOG_DEBUG ("Sleep mode. Dropping packet.");
651  NotifyRxDrop(pkt); // traced source netanim
652  break;
653  }
654 
656  {
657  m_state = CCABUSY;
659  }
660 
661 }
662 
663 void
664 UanPhyGen::RxEndEvent (Ptr<Packet> pkt, double rxPowerDb, UanTxMode txMode)
665 {
666  if (pkt != m_pktRx)
667  {
668  return;
669  }
670 
671  if (m_disabled || m_state == SLEEP)
672  {
673  NS_LOG_DEBUG ("Sleep mode or dead. Dropping packet");
674  m_pktRx = 0;
675  NotifyRxDrop(pkt); // traced source netanim
676  return;
677  }
678 
679  NotifyRxEnd(pkt); // traced source netanim
681  {
682  m_state = CCABUSY;
684  }
685  else
686  {
687  m_state = IDLE;
689  }
690 
691  if (m_pg->GetValue (0, 1) > m_per->CalcPer (m_pktRx, m_minRxSinrDb, txMode))
692  {
693  m_rxOkLogger (pkt, m_minRxSinrDb, txMode);
695  if (!m_recOkCb.IsNull ())
696  {
697  m_recOkCb (pkt, m_minRxSinrDb, txMode);
698  }
699 
700  }
701  else
702  {
703  m_rxErrLogger (pkt, m_minRxSinrDb, txMode);
705  if (!m_recErrCb.IsNull ())
706  {
707  m_recErrCb (pkt, m_minRxSinrDb);
708  }
709  }
710 
711  m_pktRx = 0;
712 }
713 
714 void
716 {
717  m_recOkCb = cb;
718 }
719 
720 void
722 {
723  m_recErrCb = cb;
724 }
725 bool
727 {
728  return m_state == SLEEP;
729 }
730 bool
732 {
733  return m_state == IDLE;
734 }
735 bool
737 {
738  return !IsStateIdle () && !IsStateSleep ();
739 }
740 bool
742 {
743  return m_state == RX;
744 }
745 bool
747 {
748  return m_state == TX;
749 }
750 
751 bool
753 {
754  return m_state == CCABUSY;
755 }
756 
757 
758 void
760 {
761  m_rxGainDb = gain;
762 
763 }
764 void
766 {
767  m_txPwrDb = txpwr;
768 }
769 void
771 {
772  m_rxThreshDb = thresh;
773 }
774 void
776 {
777  m_ccaThreshDb = thresh;
778 }
779 double
781 {
782  return m_rxGainDb;
783 }
784 double
786 {
787  return m_txPwrDb;
788 
789 }
790 double
792 {
793  return m_rxThreshDb;
794 }
795 double
797 {
798  return m_ccaThreshDb;
799 }
800 
803 {
804  return m_channel;
805 }
806 
809 {
810  return m_device;
811 }
812 
815 {
816  return m_transducer;
817 }
818 void
820 {
821  m_channel = channel;
822 }
823 
824 void
826 {
827  m_device = device;
828 }
829 
830 void
832 {
833  m_mac = mac;
834 }
835 
836 void
838 {
839  m_transducer = trans;
840  m_transducer->AddPhy (this);
841 }
842 
843 void
845 {
846  if (sleep)
847  {
848  m_state = SLEEP;
849  if (!m_energyCallback.IsNull ())
850  {
852  }
853  }
854  else if (m_state == SLEEP)
855  {
857  {
858  m_state = CCABUSY;
860  }
861  else
862  {
863  m_state = IDLE;
864  }
865 
866  if (!m_energyCallback.IsNull ())
867  {
869  }
870  }
871 }
872 
873 int64_t
874 UanPhyGen::AssignStreams (int64_t stream)
875 {
876  NS_LOG_FUNCTION (this << stream);
877  m_pg->SetStream (stream);
878  return 1;
879 }
880 
881 void
882 UanPhyGen::NotifyTransStartTx (Ptr<Packet> packet, double txPowerDb, UanTxMode txMode)
883 {
884  if (m_pktRx)
885  {
886  m_minRxSinrDb = -1e30;
887  }
888 }
889 
890 void
892 {
894  {
895  m_state = IDLE;
897  }
898 }
899 
900 double
901 UanPhyGen::CalculateSinrDb (Ptr<Packet> pkt, Time arrTime, double rxPowerDb, UanTxMode mode, UanPdp pdp)
902 {
903  double noiseDb = m_channel->GetNoiseDbHz ( (double) mode.GetCenterFreqHz () / 1000.0) + 10 * std::log10 (mode.GetBandwidthHz ());
904  return m_sinr->CalcSinrDb (pkt, arrTime, rxPowerDb, noiseDb, mode, pdp, m_transducer->GetArrivalList ());
905 }
906 
907 double
909 {
910 
911  const UanTransducer::ArrivalList &arrivalList = m_transducer->GetArrivalList ();
912 
913  UanTransducer::ArrivalList::const_iterator it = arrivalList.begin ();
914 
915  double interfPower = 0;
916 
917  for (; it != arrivalList.end (); it++)
918  {
919  if (pkt != it->GetPacket ())
920  {
921  interfPower += DbToKp (it->GetRxPowerDb ());
922  }
923  }
924 
925  return KpToDb (interfPower);
926 
927 }
928 
929 double
930 UanPhyGen::DbToKp (double db)
931 {
932  return std::pow (10, db / 10.0);
933 }
934 double
935 UanPhyGen::KpToDb (double kp)
936 {
937  return 10 * std::log10 (kp);
938 }
939 
940 void
942 {
943  ListenerList::const_iterator it = m_listeners.begin ();
944  for (; it != m_listeners.end (); it++)
945  {
946  (*it)->NotifyRxStart ();
947  }
948 
949 }
950 void
952 {
953  ListenerList::const_iterator it = m_listeners.begin ();
954  for (; it != m_listeners.end (); it++)
955  {
956  (*it)->NotifyRxEndOk ();
957  }
958 }
959 void
961 {
962  ListenerList::const_iterator it = m_listeners.begin ();
963  for (; it != m_listeners.end (); it++)
964  {
965  (*it)->NotifyRxEndError ();
966  }
967 }
968 void
970 {
971  ListenerList::const_iterator it = m_listeners.begin ();
972  for (; it != m_listeners.end (); it++)
973  {
974  (*it)->NotifyCcaStart ();
975  }
976 }
977 void
979 {
980  ListenerList::const_iterator it = m_listeners.begin ();
981  for (; it != m_listeners.end (); it++)
982  {
983  (*it)->NotifyCcaEnd ();
984  }
985 }
986 
987 void
989 {
990  ListenerList::const_iterator it = m_listeners.begin ();
991  for (; it != m_listeners.end (); it++)
992  {
993  (*it)->NotifyTxStart (duration);
994  }
995 }
996 
997 uint32_t
999 {
1000  return m_modes.GetNModes ();
1001 }
1002 
1003 UanTxMode
1005 {
1006  NS_ASSERT (n < m_modes.GetNModes ());
1007 
1008  return m_modes[n];
1009 }
1010 
1013 {
1014  return m_pktRx;
1015 }
1016 
1017 
1018 } // 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:882
virtual bool IsStateBusy(void)
Definition: uan-phy-gen.cc:736
virtual Ptr< UanTransducer > GetTransducer(void)
Get the attached transducer.
Definition: uan-phy-gen.cc:814
virtual double GetRxThresholdDb(void)
Get the minimum received signal strength required to receive a packet without errors.
Definition: uan-phy-gen.cc:791
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
uint32_t GetNModes(void) const
Get the number of modes in this list.
Definition: uan-tx-mode.cc:259
std::vector< Tap >::const_iterator Iterator
Convenience iterator typedef.
virtual bool IsStateRx(void)
Definition: uan-phy-gen.cc:741
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
double KpToDb(double kp)
Convert kilopascals to dB.
Definition: uan-phy-gen.cc:935
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:489
uint32_t m_hops
Number of hops.
Definition: uan-phy-gen.h:204
Transmitting.
Definition: uan-phy.h:184
void NotifyRxDrop(Ptr< const Packet > packet)
Called when the Phy drops a packet.
Definition: uan-phy.cc:130
virtual void SetReceiveErrorCallback(RxErrCallback cb)
Set the callback to be used when a packet is received with errors.
Definition: uan-phy-gen.cc:721
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:901
virtual void EnergyDepletionHandler(void)
Handle the energy depletion event.
Definition: uan-phy-gen.cc:507
virtual void SetTransducer(Ptr< UanTransducer > trans)
Attach a transducer to this Phy.
Definition: uan-phy-gen.cc:837
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1014
#define NS_ASSERT(condition)
Definition: assert.h:64
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
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
Channel is IDLE, no packet is being transmitted.
Definition: csma-channel.h:62
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
Definition: packet.h:650
virtual void SetSleepMode(bool sleep)
Set the Phy SLEEP mode.
Definition: uan-phy-gen.cc:844
virtual void StartRxPacket(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode, UanPdp pdp)
Packet arriving from channel: i.e.
Definition: uan-phy-gen.cc:585
Channel busy.
Definition: uan-phy.h:182
virtual uint32_t GetNModes(void)
Get the number of transmission modes supported by this Phy.
Definition: uan-phy-gen.cc:998
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: object.cc:336
Container for UanTxModes.
Definition: uan-tx-mode.h:255
virtual double GetTxPowerDb(void)
Get the current transmit power, in dB.
Definition: uan-phy-gen.cc:785
virtual double GetCcaThresholdDb(void)
Get the CCA threshold signal strength required to detect channel busy.
Definition: uan-phy-gen.cc:796
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:824
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:124
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
Unspecified/undefined.
Definition: uan-tx-mode.h:54
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: uan-phy-gen.cc:417
Time m_pktRxArrTime
Packet arrival time.
Definition: uan-phy-gen.h:303
NS_LOG_COMPONENT_DEFINE("UanPhyGen")
bool m_cleared
Flag when we've been cleared.
Definition: uan-phy-gen.h:307
TracedCallback< Ptr< const Packet >, double, UanTxMode > m_txLogger
A packet was sent from this Phy.
Definition: uan-phy-gen.h:320
double GetSeconds(void) const
Definition: nstime.h:274
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:257
double NChooseK(uint32_t n, uint32_t k)
Binomial coefficient.
Definition: uan-phy-gen.cc:267
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:76
virtual bool IsStateTx(void)
Definition: uan-phy-gen.cc:746
virtual void SetDevice(Ptr< UanNetDevice > device)
Set the device hosting this Phy.
Definition: uan-phy-gen.cc:825
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:874
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
virtual ~UanPhyPerUmodem()
Destructor.
Definition: uan-phy-gen.cc:252
Hold an unsigned integer type.
Definition: uinteger.h:46
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.
Receiving.
Definition: uan-phy.h:183
Abstraction of packet modulation information.
Definition: uan-tx-mode.h:41
double m_thresh
SINR threshold.
Definition: uan-phy-gen.h:60
Idle state.
Definition: uan-phy.h:181
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:951
void NotifyListenersCcaEnd(void)
Call UanListener::NotifyCcaEnd on all listeners.
Definition: uan-phy-gen.cc:978
std::list< UanPacketArrival > ArrivalList
List of arriving packets overlapping in time.
Ptr< Packet > m_pktRx
Received packet.
Definition: uan-phy-gen.h:300
Phase shift keying.
Definition: uan-tx-mode.h:51
virtual void SetCcaThresholdDb(double thresh)
Set the threshold for detecting channel busy.
Definition: uan-phy-gen.cc:775
Sleeping.
Definition: uan-phy.h:185
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:891
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:127
virtual Ptr< UanChannel > GetChannel(void) const
Get the attached channel.
Definition: uan-phy-gen.cc:802
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:770
Frequency shift keying.
Definition: uan-tx-mode.h:53
void NotifyRxBegin(Ptr< const Packet > packet)
Called when the Phy begins to receive a packet.
Definition: uan-phy.cc:118
void TxEndEvent()
Event to process end of packet transmission.
Definition: uan-phy-gen.cc:556
double DbToKp(double db)
Convert dB to kilopascals.
Definition: uan-phy-gen.cc:930
hold objects of type Ptr
Definition: pointer.h:33
virtual void SetRxGainDb(double gain)
Set the receiver gain.
Definition: uan-phy-gen.cc:759
RxOkCallback m_recOkCb
Callback for packets received without error.
Definition: uan-phy-gen.h:286
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
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:219
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:496
void NotifyListenersRxStart(void)
Call UanListener::NotifyRxStart on all listeners.
Definition: uan-phy-gen.cc:941
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:107
void RxEndEvent(Ptr< Packet > pkt, double rxPowerDb, UanTxMode txMode)
Event to process end of packet reception.
Definition: uan-phy-gen.cc:664
double DbToKp(double db) const
Convert dB re 1 uPa to kilopascals.
Definition: uan-phy.h:82
TracedCallback< Ptr< const Packet >, double, UanTxMode > m_rxOkLogger
A packet destined for this Phy was received without error.
Definition: uan-phy-gen.h:316
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
virtual void SetChannel(Ptr< UanChannel > channel)
Attach to a channel.
Definition: uan-phy-gen.cc:819
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
uint32_t GetPhyRateSps(void) const
Get the physical signaling rate.
Definition: uan-tx-mode.cc:51
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 ~UanPhyPerGenDefault()
Destructor.
Definition: uan-phy-gen.cc:214
UanPhyCalcSinrFhFsk()
Constructor.
Definition: uan-phy-gen.cc:103
bool m_disabled
Energy depleted.
Definition: uan-phy-gen.h:308
#define NS_LOG_WARN(msg)
Definition: log.h:280
virtual bool IsStateIdle(void)
Definition: uan-phy-gen.cc:731
RxErrCallback m_recErrCb
Callback for packets received with errors.
Definition: uan-phy-gen.h:287
#define NS_LOG_DEBUG(msg)
Definition: log.h:289
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:66
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:969
void AppendMode(UanTxMode mode)
Add mode to this list.
Definition: uan-tx-mode.cc:232
double GetInterferenceDb(Ptr< Packet > pkt)
Calculate interference power from overlapping packet arrivals, in dB.
Definition: uan-phy-gen.cc:908
void NotifyListenersRxBad(void)
Call UanListener::NotifyRxEndError on all listeners.
Definition: uan-phy-gen.cc:960
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:1018
UanPhyPerUmodem()
Constructor.
Definition: uan-phy-gen.cc:248
UanPhyPerGenDefault()
Constructor.
Definition: uan-phy-gen.cc:209
static TypeId GetTypeId(void)
Register this type.
Definition: uan-phy-gen.cc:113
UanPhyGen()
Constructor.
Definition: uan-phy-gen.cc:349
virtual ~UanPhyCalcSinrDefault()
Destructor.
Definition: uan-phy-gen.cc:60
a base class which provides memory management and object aggregation
Definition: object.h:63
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:517
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:752
virtual void RegisterListener(UanPhyListener *listener)
Register a UanPhyListener to be notified of common UanPhy events.
Definition: uan-phy-gen.cc:578
virtual double GetRxGainDb(void)
Get the receiver gain added to signal at receiver in dB.
Definition: uan-phy-gen.cc:780
double m_minRxSinrDb
Minimum receive SINR during packet reception.
Definition: uan-phy-gen.h:301
Hold a floating point type.
Definition: double.h:41
virtual bool IsStateSleep(void)
Definition: uan-phy-gen.cc:726
virtual void SetMac(Ptr< UanMac > mac)
Set the MAC forwarding messages to this Phy.
Definition: uan-phy-gen.cc:831
virtual void SetReceiveOkCallback(RxOkCallback cb)
Set the callback to be used when a packet is received without error.
Definition: uan-phy-gen.cc:715
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.
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:49
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:235
virtual Ptr< UanNetDevice > GetDevice(void)
Get the device hosting this Phy.
Definition: uan-phy-gen.cc:808
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
virtual void Clear(void)
Clear all pointer references.
Definition: uan-phy-gen.cc:375
UanPhyCalcSinrDefault()
Constructor.
Definition: uan-phy-gen.cc:56
void NotifyListenersTxStart(Time duration)
Call UanListener::NotifyTxStart on all listeners.
Definition: uan-phy-gen.cc:988
Attribute Value class for UanTxModes.
virtual void SetTxPowerDb(double txpwr)
Set the transmit power.
Definition: uan-phy-gen.cc:765