A Discrete-Event Network Simulator
API
simple-ofdm-wimax-phy.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007,2008, 2009 INRIA, UDcast
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: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
19  * <amine.ismail@udcast.com>
20  */
21 
22 #include "ns3/simulator.h"
23 #include "ns3/packet.h"
24 #include "ns3/node.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/double.h"
27 #include "ns3/string.h"
28 #include "wimax-net-device.h"
29 #include "simple-ofdm-wimax-phy.h"
30 #include "wimax-channel.h"
31 #include "ns3/packet-burst.h"
32 #include "wimax-mac-header.h"
34 #include "ns3/trace-source-accessor.h"
35 #include <string>
36 #include <cmath>
37 
38 namespace ns3 {
39 
40 NS_LOG_COMPONENT_DEFINE ("SimpleOfdmWimaxPhy");
41 
42 NS_OBJECT_ENSURE_REGISTERED (SimpleOfdmWimaxPhy);
43 
45 {
46  static TypeId
47  tid =
48  TypeId ("ns3::SimpleOfdmWimaxPhy").SetParent<WimaxPhy> ()
49 
50  .AddAttribute ("NoiseFigure",
51  "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.",
52  DoubleValue (5),
54  MakeDoubleChecker<double> ())
55 
56  .AddAttribute ("TxPower",
57  "Transmission power (dB).",
58  DoubleValue (30),
60  MakeDoubleChecker<double> ())
61 
62  .AddAttribute ("G",
63  "This is the ratio of CP time to useful time.",
64  DoubleValue (0.25),
66  MakeDoubleChecker<double> ())
67 
68  .AddAttribute ("TxGain",
69  "Transmission gain (dB).",
70  DoubleValue (0),
72  MakeDoubleChecker<double> ())
73 
74  .AddAttribute ("RxGain",
75  "Reception gain (dB).",
76  DoubleValue (0),
78  MakeDoubleChecker<double> ())
79 
80  .AddAttribute ("Nfft",
81  "FFT size",
82  UintegerValue (256),
84  MakeUintegerChecker<uint16_t> (256, 1024))
85 
86  .AddAttribute ("TraceFilePath",
87  "Path to the directory containing SNR to block error rate files",
88  StringValue (""),
92 
93  .AddTraceSource ("Rx", "Receive trace",
95  "ns3::PacketBurst::Traced::Ptr")
96  .AddTraceSource ("Tx", "Transmit trace",
98  "ns3::PacketBurst::TracedCallback")
99 
100  .AddTraceSource ("PhyTxBegin",
101  "Trace source indicating a packet has begun transmitting over the channel medium",
103  "ns3::PacketBurst::TracedCallback")
104 
105  .AddTraceSource ("PhyTxEnd",
106  "Trace source indicating a packet has been completely transmitted over the channel",
108  "ns3::PacketBurst::TracedCallback")
109 
110  .AddTraceSource ("PhyTxDrop",
111  "Trace source indicating a packet has been dropped by the device during transmission",
113  "ns3::PacketBurst::TracedCallback")
114 
115  .AddTraceSource ("PhyRxBegin",
116  "Trace source indicating a packet has begun being received from the channel medium by the device",
118  "ns3::PacketBurst::TracedCallback")
119 
120  .AddTraceSource ("PhyRxEnd",
121  "Trace source indicating a packet has been completely received from the channel medium by the device",
123  "ns3::PacketBurst::TracedCallback")
124 
125  .AddTraceSource ("PhyRxDrop",
126  "Trace source indicating a packet has been dropped by the device during reception",
128  "ns3::PacketBurst::TracedCallback");
129  return tid;
130 }
131 
132 void
134 {
135  m_fecBlockSize = 0;
136  m_nrFecBlocksSent = 0;
137  m_dataRateBpsk12 = 0;
138  m_dataRateQpsk12 = 0;
139  m_dataRateQpsk34 = 0;
140  m_dataRateQam16_12 = 0;
141 
142  m_dataRateQam16_34 = 0;
143  m_dataRateQam64_23 = 0;
144  m_dataRateQam64_34 = 0;
145 
146  m_nrBlocks = 0;
147  m_blockSize = 0;
148  m_paddingBits = 0;
149  m_rxGain = 0;
150  m_txGain = 0;
151  m_nfft = 256;
152  m_g = (double) 1 / 4;
153  SetNrCarriers (192);
154  m_fecBlocks = new std::list<bvec>;
155  m_receivedFecBlocks = new std::list<bvec>;
156  m_currentBurstSize = 0;
157  m_noiseFigure = 5; // dB
158  m_txPower = 30; // dBm
159  SetBandwidth (10000000); // 10Mhz
160  m_nbErroneousBlock = 0;
163 }
164 
166 {
167  m_URNG = CreateObject<UniformRandomVariable> ();
168 
172 }
173 
175 {
179 }
180 
182 {
183 
184 }
185 
186 void
188 {
190 }
191 
192 void
194 {
197 }
198 
199 uint32_t
201 {
203 }
204 
205 void
207 {
209 }
210 
211 double
213 {
214  return m_txPower;
215 }
216 void
218 {
219  m_txPower = txPower;
220 }
221 
222 double
224 {
225  return m_noiseFigure;
226 }
227 void
229 {
230  m_noiseFigure = noiseFigure;
231 }
232 
233 void
235 {
236  delete m_receivedFecBlocks;
237  delete m_fecBlocks;
239  m_fecBlocks = 0;
242 }
243 
244 void
246 {
247  GetChannel ()->Attach (this);
248 }
249 
250 void
252 {
253  OfdmSendParams *o_params = dynamic_cast<OfdmSendParams*> (params);
254  NS_ASSERT (o_params !=0);
255  Send (o_params->GetBurst (),
257  o_params->GetDirection ());
258 
259 }
260 
263 {
265 }
266 
267 void
269  WimaxPhy::ModulationType modulationType,
270  uint8_t direction)
271 {
272 
273  if (GetState () != PHY_STATE_TX)
274  {
275  m_currentBurstSize = burst->GetSize ();
276  m_nrFecBlocksSent = 0;
277  m_currentBurst = burst;
278  SetBlockParameters (burst->GetSize (), modulationType);
280  StartSendDummyFecBlock (true, modulationType, direction);
281  m_traceTx (burst);
282  }
283 }
284 
285 void
287  WimaxPhy::ModulationType modulationType,
288  uint8_t direction)
289 {
291  bool isLastFecBlock = 0;
292  if (isFirstBlock)
293  {
294  m_blockTime = GetBlockTransmissionTime (modulationType);
295  }
296 
297  SimpleOfdmWimaxChannel *channel = dynamic_cast<SimpleOfdmWimaxChannel*> (PeekPointer (GetChannel ()));
298  NS_ASSERT (channel != 0);
299 
301  {
302  isLastFecBlock = true;
303  }
304  else
305  {
306  isLastFecBlock = false;
307  }
308  channel->Send (m_blockTime,
310  this,
311  isFirstBlock,
312  isLastFecBlock,
313  GetTxFrequency (),
314  modulationType,
315  direction,
316  m_txPower,
318 
320  Simulator::Schedule (m_blockTime, &SimpleOfdmWimaxPhy::EndSendFecBlock, this, modulationType, direction);
321 }
322 
323 
324 void
326  uint8_t direction)
327 {
330 
332  {
333  // this is the last FEC block of the burst
334  NS_ASSERT_MSG (m_nrRemainingBlocksToSend == 0, "Error while sending a burst");
336  }
337  else
338  {
339  StartSendDummyFecBlock (false,modulationType,direction);
340  }
341 }
342 
343 void
345 {
347 }
348 
349 void
351  bool isFirstBlock,
352  uint64_t frequency,
353  WimaxPhy::ModulationType modulationType,
354  uint8_t direction,
355  double rxPower,
356  Ptr<PacketBurst> burst)
357 {
358 
359  uint8_t drop = 0;
360  double Nwb = -114 + m_noiseFigure + 10 * std::log (GetBandwidth () / 1000000000.0) / 2.303;
361  double SNR = rxPower - Nwb;
362 
364  double I1 = record->GetI1 ();
365  double I2 = record->GetI2 ();
366 
367  double blockErrorRate = m_URNG->GetValue (I1, I2);
368 
369  double rand = m_URNG->GetValue (0.0, 1.0);
370 
371  if (rand < blockErrorRate)
372  {
373  drop = 1;
374  }
375  if (rand > blockErrorRate)
376  {
377  drop = 0;
378  }
379 
380  if (blockErrorRate == 1.0)
381  {
382  drop = 1;
383  }
384  if (blockErrorRate == 0.0)
385  {
386  drop = 0;
387  }
388  delete record;
389 
390  NS_LOG_INFO ("PHY: Receive rxPower=" << rxPower << ", Nwb=" << Nwb << ", SNR=" << SNR << ", Modulation="
391  << modulationType << ", BlocErrorRate=" << blockErrorRate << ", drop=" << (int) drop);
392 
393  switch (GetState ())
394  {
395  case PHY_STATE_SCANNING:
396  if (frequency == GetScanningFrequency ())
397  {
400  SetSimplex (frequency);
402  }
403  break;
404  case PHY_STATE_IDLE:
405  if (frequency == GetRxFrequency ())
406  {
407  if (isFirstBlock)
408  {
409  NotifyRxBegin (burst);
410  m_receivedFecBlocks->clear ();
412  SetBlockParameters (burstSize, modulationType);
413  m_blockTime = GetBlockTransmissionTime (modulationType);
414  }
415 
418  this,
419  burstSize,
420  modulationType,
421  direction,
422  drop,
423  burst);
424 
426  }
427  break;
428  case PHY_STATE_RX:
429  // drop
430  break;
431  case PHY_STATE_TX:
432  if (IsDuplex () && frequency == GetRxFrequency ())
433  {
434 
435  }
436  break;
437  }
438 }
439 
440 void
442  WimaxPhy::ModulationType modulationType,
443  uint8_t direction,
444  uint8_t drop,
445  Ptr<PacketBurst> burst)
446 {
449 
450  if (drop == true)
451  {
453  }
454 
455  if ((uint32_t) m_nrRecivedFecBlocks * m_blockSize == burstSize * 8 + m_paddingBits)
456  {
457  NotifyRxEnd (burst);
458  if (m_nbErroneousBlock == 0)
459  {
462  this,
463  burst);
464  }
465  else
466  {
467  NotifyRxDrop (burst);
468  }
469  m_nbErroneousBlock = 0;
471  }
472 }
473 
474 void
476 {
477  Ptr<PacketBurst> b = burst->Copy ();
478  GetReceiveCallback () (b);
479  m_traceRx (burst);
480 }
481 
482 bvec
484 {
485  bvec buffer (burst->GetSize () * 8, 0);
486 
487  std::list<Ptr<Packet> > packets = burst->GetPackets ();
488 
489  uint32_t j = 0;
490  for (std::list<Ptr<Packet> >::iterator iter = packets.begin (); iter != packets.end (); ++iter)
491  {
492  Ptr<Packet> packet = *iter;
493  uint8_t *pstart = (uint8_t*) std::malloc (packet->GetSize ());
494  std::memset (pstart, 0, packet->GetSize ());
495  packet->CopyData (pstart, packet->GetSize ());
496  bvec temp (8);
497  temp.resize (0, 0);
498  temp.resize (8, 0);
499  for (uint32_t i = 0; i < packet->GetSize (); i++)
500  {
501  for (uint8_t l = 0; l < 8; l++)
502  {
503  temp[l] = (bool)((((uint8_t) pstart[i]) >> (7 - l)) & 0x01);
504  buffer.at (j * 8 + l) = temp[l];
505  }
506  j++;
507  }
508  std::free (pstart);
509  }
510 
511  return buffer;
512 }
513 
514 /*
515  Converts back the bit buffer (bvec) to the actual burst.
516  Actually creates byte buffer from the bvec and resets the buffer
517  of each packet in the copy of the orifinal burst stored before transmitting.
518  By doing this it preserves the metadata and tags in the packet.
519  Function could also be named DeserializeBurst because actually it
520  copying to the burst's byte buffer.
521  */
524 {
525  uint8_t init[buffer.size () / 8];
526  uint8_t *pstart = init;
527  uint8_t temp;
528  int32_t j = 0;
529  // recreating byte buffer from bit buffer (bvec)
530  for (uint32_t i = 0; i < buffer.size (); i += 8)
531  {
532 
533  temp = 0;
534  for (int l = 0; l < 8; l++)
535  {
536  bool bin = buffer.at (i + l);
537  temp += (uint8_t)(bin * std::pow (2.0, (7 - l)));
538  }
539 
540  *(pstart + j) = temp;
541  j++;
542  }
543  uint16_t bufferSize = buffer.size () / 8;
544  uint16_t pos = 0;
545  Ptr<PacketBurst> RecvBurst = Create<PacketBurst> ();
546  while (pos < bufferSize)
547  {
548  uint16_t packetSize = 0;
549  // Get the header type: first bit
550  uint8_t ht = (pstart[pos] >> 7) & 0x01;
551  if (ht == 1)
552  {
553  // BW request header. Size is always 8 bytes
554  packetSize = 6;
555  }
556  else
557  {
558  // Read the size
559  uint8_t Len_MSB = pstart[pos + 1] & 0x07;
560  packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(pstart[pos + 2]));
561  if (packetSize == 0)
562  {
563  break; // padding
564  }
565  }
566 
567  Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize);
568  RecvBurst->AddPacket (p);
569  pos += packetSize;
570  }
571  return RecvBurst;
572 }
573 
574 void
576 {
577 
578  bvec fecBlock (m_blockSize);
579  for (uint32_t i = 0, j = m_nrBlocks; j > 0; i += m_blockSize, j--)
580  {
581 
582  if (j == 1 && m_paddingBits > 0) // last block can be smaller than block size
583  {
584  fecBlock = bvec (buffer.begin () + i, buffer.end ());
585  fecBlock.resize (m_blockSize, 0);
586  }
587  else
588  {
589  fecBlock = bvec (buffer.begin () + i, buffer.begin () + i + m_blockSize);
590  }
591 
592  m_fecBlocks->push_back (fecBlock);
593  }
594 }
595 
596 bvec
598 {
599 
600  bvec buffer (m_blockSize * (unsigned long)m_nrBlocks);
601  bvec block (m_blockSize);
602  uint32_t i = 0;
603  for (uint32_t j = 0; j < m_nrBlocks; j++)
604  {
605  bvec tmpRecFecBloc = m_receivedFecBlocks->front ();
606  buffer.insert (buffer.begin () + i, tmpRecFecBloc.begin (), tmpRecFecBloc.end ());
607  m_receivedFecBlocks->pop_front ();
608  i += m_blockSize;
609  }
610  return buffer;
611 }
612 
613 void
615 {
623 }
624 
625 void
627  uint8_t &bitsPerSymbol,
628  double &fecCode) const
629 {
630  switch (modulationType)
631  {
633  bitsPerSymbol = 1;
634  fecCode = (double) 1 / 2;
635  break;
637  bitsPerSymbol = 2;
638  fecCode = (double) 1 / 2;
639  break;
641  bitsPerSymbol = 2;
642  fecCode = (double) 3 / 4;
643  break;
645  bitsPerSymbol = 4;
646  fecCode = (double) 1 / 2;
647  break;
649  bitsPerSymbol = 4;
650  fecCode = (double) 3 / 4;
651  break;
653  bitsPerSymbol = 6;
654  fecCode = (double) 2 / 3;
655  break;
657  bitsPerSymbol = 6;
658  fecCode = 0.75;
659  break;
660  }
661 }
662 
663 uint32_t
665 {
666  uint8_t bitsPerSymbol = 0;
667  double fecCode = 0;
668  GetModulationFecParams (modulationType, bitsPerSymbol, fecCode);
669  double symbolsPerSecond = 1 / GetSymbolDuration ().GetSeconds ();
670  uint16_t bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol * GetNrCarriers () * fecCode);
671  // 96, 192, 288, 384, 576, 767 and 864 bits per symbol for the seven modulations, respectively
672 
673  return (uint32_t) symbolsPerSecond * bitsTransmittedPerSymbol;
674 }
675 
676 uint32_t
678 {
679  switch (modulationType)
680  {
682  return m_dataRateBpsk12;
683  break;
685  return m_dataRateQpsk12;
686  break;
688  return m_dataRateQpsk34;
689  break;
691  return m_dataRateQam16_12;
692  break;
694  return m_dataRateQam16_34;
695  break;
697  return m_dataRateQam64_23;
698  break;
700  return m_dataRateQam64_34;
701  break;
702  }
703  NS_FATAL_ERROR ("Invalid modulation type");
704  return 0;
705 }
706 
707 Time
709 {
710  return Seconds ((double) GetFecBlockSize (modulationType) / DoGetDataRate (modulationType));
711 }
712 
713 Time
715 {
716  /*adding 3 extra nano second to cope with the loss of precision problem.
717  the time is internally stored in a 64 bit hence a floating-point time would loss
718  precision, e.g., 0.00001388888888888889 seconds will become 13888888888 femtoseconds.*/
719  return Seconds (DoGetNrSymbols (size, modulationType) * GetSymbolDuration ().GetSeconds ()) + NanoSeconds (3);
720 }
721 
722 uint64_t
724 {
725  Time transmissionTime = Seconds ((double)(GetNrBlocks (size, modulationType) * GetFecBlockSize (modulationType))
726  / DoGetDataRate (modulationType));
727  return (uint64_t) std::ceil (transmissionTime.GetSeconds () / GetSymbolDuration ().GetSeconds ());
728 }
729 
730 uint64_t
731 SimpleOfdmWimaxPhy::DoGetNrBytes (uint32_t symbols, WimaxPhy::ModulationType modulationType) const
732 {
733  Time transmissionTime = Seconds (symbols * GetSymbolDuration ().GetSeconds ());
734  return (uint64_t) std::floor ((transmissionTime.GetSeconds () * DoGetDataRate (modulationType)) / 8);
735 }
736 
737 uint32_t
739 {
740  uint32_t blockSize = 0;
741  switch (modulationType)
742  {
744  blockSize = 12;
745  break;
747  blockSize = 24;
748  break;
750  blockSize = 36;
751  break;
753  blockSize = 48;
754  break;
756  blockSize = 72;
757  break;
759  blockSize = 96;
760  break;
762  blockSize = 108;
763  break;
764  default:
765  NS_FATAL_ERROR ("Invalid modulation type");
766  break;
767  }
768  return blockSize * 8; // in bits
769 }
770 
771 // Channel coding block size, Table 215, page 434
772 uint32_t
774 {
775  uint32_t blockSize = 0;
776  switch (modulationType)
777  {
779  blockSize = 24;
780  break;
782  blockSize = 48;
783  break;
785  blockSize = 48;
786  break;
788  blockSize = 96;
789  break;
791  blockSize = 96;
792  break;
794  blockSize = 144;
795  break;
797  blockSize = 144;
798  break;
799  default:
800  NS_FATAL_ERROR ("Invalid modulation type");
801  break;
802  }
803  return blockSize * 8; // in bits
804 }
805 
806 void
808 {
809  m_blockSize = GetFecBlockSize (modulationType);
810  m_nrBlocks = GetNrBlocks (burstSize, modulationType);
811  m_paddingBits = (m_nrBlocks * m_blockSize) - (burstSize * 8);
813  NS_ASSERT_MSG (static_cast<uint32_t> (m_nrBlocks * m_blockSize) >= (burstSize * 8), "Size of padding bytes < 0");
814 }
815 
816 uint16_t
818 {
819  // assumed equal to 2 symbols
820  return 2 * GetPsPerSymbol ();
821 }
822 
823 uint16_t
825 {
826  // assumed equal to 2 symbols
827  return 2 * GetPsPerSymbol ();
828 }
829 
830 uint8_t
832 {
833  uint16_t duration = 0;
834  duration = (uint16_t)(GetFrameDuration ().GetSeconds () * 10000);
835  uint8_t retval = 0;
836  switch (duration)
837  {
838  case 25:
839  {
841  break;
842  }
843  case 40:
844  {
845  retval = FRAME_DURATION_4_MS;
846  break;
847  }
848  case 50:
849  {
850  retval = FRAME_DURATION_5_MS;
851  break;
852  }
853  case 80:
854  {
855  retval = FRAME_DURATION_8_MS;
856  break;
857  }
858  case 100:
859  {
860  retval = FRAME_DURATION_10_MS;
861  break;
862  }
863  case 125:
864  {
866  break;
867  }
868  case 200:
869  {
870  retval = FRAME_DURATION_20_MS;
871  break;
872  }
873  default:
874  {
875  NS_FATAL_ERROR ("Invalid frame duration = " << duration);
876  retval = 0;
877  }
878  }
879  return retval;
880 }
881 
882 Time
883 SimpleOfdmWimaxPhy::DoGetFrameDuration (uint8_t frameDurationCode) const
884 {
885  switch (frameDurationCode)
886  {
888  return Seconds (2.5);
889  break;
890  case FRAME_DURATION_4_MS:
891  return Seconds (4);
892  break;
893  case FRAME_DURATION_5_MS:
894  return Seconds (5);
895  break;
896  case FRAME_DURATION_8_MS:
897  return Seconds (8);
898  break;
900  return Seconds (10);
901  break;
903  return Seconds (12.5);
904  break;
906  return Seconds (20);
907  break;
908  default:
909  NS_FATAL_ERROR ("Invalid modulation type");
910  }
911  return Seconds (0);
912 }
913 
914 /*
915  Retruns number of blocks (FEC blocks) the burst will be splitted in.
916  The size of the block is specific for each modulation type.
917  */
918 uint16_t
919 SimpleOfdmWimaxPhy::GetNrBlocks (uint32_t burstSize, WimaxPhy::ModulationType modulationType) const
920 {
921  uint32_t blockSize = GetFecBlockSize (modulationType);
922  uint16_t nrBlocks = (burstSize * 8) / blockSize;
923 
924  if ((burstSize * 8) % blockSize > 0)
925  {
926  nrBlocks += 1;
927  }
928 
929  return nrBlocks;
930 }
931 /*---------------------PHY parameters functions-----------------------*/
932 
933 void
935 {
936  /*Calculations as per section 8.3.2.
937  Currently assuming license-exempt 5 GHz band. For channel bandwidth 20 MHz (Table B.28, page 812) and frame duration 10 ms
938  (Table 232, page 460) i.e, 100 frames per second, sampling frequency is 23040000, symbol (OFDM symbol) duration is
939  1.388888888888889e-05 seconds, PS duration is 1.7361111111111112e-07 seconds. Hence PSs per frame is 57600, symbols per frame
940  is 720 and PSs per symbol is 80. Note that defining these parameters (symbol and PS duration) as Time may not result in exaclty
941  these values therefore lrint has been used (otherwise should be defined as double).
942  For licensed bands set channel bandwidth according to Table B.26, page 810.*/
943 
944  double samplingFrequency = DoGetSamplingFrequency ();
945  Time psDuration = Seconds ((double) 4 / samplingFrequency);
946 
947  SetPsDuration (psDuration);
948  uint16_t psPerFrame = (uint16_t)(GetFrameDuration ().GetSeconds () / psDuration.GetSeconds ());
949  SetPsPerFrame (psPerFrame);
950  double subcarrierSpacing = samplingFrequency / DoGetNfft ();
951  double tb = (double) 1 / subcarrierSpacing; // Tb (useful symbol time)
952  double tg = DoGetGValue () * tb; // Tg (cyclic prefix time)
953  Time symbolDuration = Seconds (tb + tg); // OFDM Symbol Time
954  SetSymbolDuration (symbolDuration);
955  uint16_t psPerSymbol = lrint (symbolDuration.GetSeconds () / psDuration.GetSeconds ());
956  SetPsPerSymbol (psPerSymbol);
957  uint32_t symbolsPerFrame = lrint (GetFrameDuration ().GetSeconds () / symbolDuration.GetSeconds ());
958  SetSymbolsPerFrame (symbolsPerFrame);
959 }
960 
961 void
963 {
964  m_nfft = nfft;
965 
966 }
967 
968 uint16_t
970 {
971  return m_nfft;
972 
973 }
974 
975 double
977 {
978  // sampling factor (n), see Table 213, page 429
979 
980  uint32_t channelBandwidth = GetChannelBandwidth ();
981 
982  if (channelBandwidth % 1750000 == 0)
983  {
984  return (double) 8 / 7;
985  }
986  else if (channelBandwidth % 1500000 == 0)
987  {
988  return (double) 86 / 75;
989  }
990  else if (channelBandwidth % 1250000 == 0)
991  {
992  return (double) 144 / 125;
993  }
994  else if (channelBandwidth % 2750000 == 0)
995  {
996  return (double) 316 / 275;
997  }
998  else if (channelBandwidth % 2000000 == 0)
999  {
1000  return (double) 57 / 50;
1001  }
1002  else
1003  {
1004  NS_LOG_DEBUG ("Oops may be wrong channel bandwidth for OFDM PHY!");
1005  NS_FATAL_ERROR ("wrong channel bandwidth for OFDM PHY");
1006  }
1007 
1008  return (double) 8 / 7;
1009 }
1010 
1011 double
1013 {
1014  // sampling frequency (Fs), see 8.3.2.2
1015 
1016  return (DoGetSamplingFactor () * GetChannelBandwidth () / 8000) * 8000;
1017 }
1018 
1019 double
1021 {
1022 
1023  return m_g;
1024 }
1025 
1026 void
1028 {
1029  m_g = g;
1030 
1031 }
1032 
1033 void
1035 {
1036  m_txGain = txGain;
1037 }
1038 
1039 void
1041 {
1042  m_rxGain = txRain;
1043 }
1044 
1045 double
1047 {
1048  return m_txGain;
1049 }
1050 
1051 double
1053 {
1054  return m_rxGain;
1055 }
1056 
1057 std::string
1059 {
1061 }
1062 
1063 void
1065 {
1066 
1067  m_snrToBlockErrorRateManager->SetTraceFilePath ((char*) path.c_str ());
1069 }
1070 
1071 void
1073 {
1074  m_phyTxBeginTrace (burst);
1075 }
1076 
1077 void
1079 {
1080  m_phyTxEndTrace (burst);
1081 }
1082 
1083 void
1085 {
1086  m_phyTxDropTrace (burst);
1087 }
1088 
1089 void
1091 {
1092  m_phyRxBeginTrace (burst);
1093 }
1094 
1095 void
1097 {
1098  m_phyRxEndTrace (burst);
1099 }
1100 
1101 void
1103 {
1104  m_phyRxDropTrace (burst);
1105 }
1106 
1107 int64_t
1109 {
1110  NS_LOG_FUNCTION (this << stream);
1111  m_URNG->SetStream (stream);
1112  return 1;
1113 }
1114 
1115 } // namespace ns3
void SetNoiseFigure(double nf)
set the noise figure of the device
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
uint32_t GetCodedFecBlockSize(WimaxPhy::ModulationType modulationType) const
void StartReceive(uint32_t burstSize, bool isFirstBlock, uint64_t frequency, WimaxPhy::ModulationType modulationType, uint8_t direction, double rxPower, Ptr< PacketBurst > burst)
start the reception of a fec block
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Callback< void, Ptr< const PacketBurst > > GetReceiveCallback(void) const
Definition: wimax-phy.cc:151
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
void SetSNRToBlockErrorRateTracesPath(char *tracesPath)
Set the path of the repository containing the traces.
TracedCallback< Ptr< PacketBurst > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
void EndReceiveFecBlock(uint32_t burstSize, WimaxPhy::ModulationType modulationType, uint8_t direction, uint8_t drop, Ptr< PacketBurst > burst)
Hold variables of type string.
Definition: string.h:41
void Send(Ptr< PacketBurst > burst, WimaxPhy::ModulationType modulationType, uint8_t direction)
Sends a burst on the channel.
double DoGetSamplingFrequency(void) const
void NotifyRxDrop(Ptr< PacketBurst > burst)
Public method used to fire a PhyRxDrop trace.
virtual void DoDispose(void)
Destructor implementation.
Definition: wimax-phy.cc:95
void NotifyRxBegin(Ptr< PacketBurst > burst)
Public method used to fire a PhyRxBegin trace.
TracedCallback< Ptr< const PacketBurst > > m_traceRx
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
bool IsDuplex(void) const
Definition: wimax-phy.cc:200
uint32_t GetChannelBandwidth(void) const
Definition: wimax-phy.cc:328
#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
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:562
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
std::list< bvec > * m_receivedFecBlocks
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:766
SNRToBlockErrorRateManager * m_snrToBlockErrorRateManager
void SetSimplex(uint64_t frequency)
configure the physical layer in simplex mode
Definition: wimax-phy.cc:164
void NotifyTxDrop(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxDrop trace.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
Time DoGetTransmissionTime(uint32_t size, WimaxPhy::ModulationType modulationType) const
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
uint64_t GetRxFrequency(void) const
Definition: wimax-phy.cc:171
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:311
uint8_t DoGetFrameDurationCode(void) const
Time GetSymbolDuration(void) const
Definition: wimax-phy.cc:370
void NotifyTxBegin(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxBegin trace.
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
uint32_t DoGetDataRate(WimaxPhy::ModulationType modulationType) const
void SetTraceFilePath(std::string path)
double DoGetSamplingFactor(void) const
void SetSymbolsPerFrame(uint32_t symbolsPerFrame)
set the number of symbols per frame
Definition: wimax-phy.cc:406
TracedCallback< Ptr< PacketBurst > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
void SetPsDuration(Time psDuration)
set the physical slot duration in seconds
Definition: wimax-phy.cc:352
Time GetFrameDuration(void) const
Definition: wimax-phy.cc:298
void SetBandwidth(uint32_t BW)
Set the bandwidth.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
This class represents a record (handled by SnrToBlockErrorRate manager) that keeps a mapping between ...
void CreateFecBlocks(const bvec &buffer, WimaxPhy::ModulationType modulationType)
void EndSendFecBlock(WimaxPhy::ModulationType modulationType, uint8_t direction)
TracedCallback< Ptr< PacketBurst > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
SNRToBlockErrorRateRecord * GetSNRToBlockErrorRateRecord(double SNR, uint8_t modulation)
returns a record of type SNRToBlockErrorRateRecord corresponding to a given modulation and SNR value ...
Ptr< UniformRandomVariable > m_URNG
Provides uniform random variables.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:334
bvec ConvertBurstToBits(Ptr< const PacketBurst > burst)
uint16_t DoGetTtg(void) const
The SendParams class defines the parameters with which Send() function of a particular PHY is called...
Definition: send-params.h:43
Time GetBlockTransmissionTime(WimaxPhy::ModulationType modulationType) const
Time DoGetFrameDuration(uint8_t frameDurationCode) const
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:890
void SetScanningCallback(void) const
calls the scanning call back function
Definition: wimax-phy.cc:212
Hold an unsigned integer type.
Definition: uinteger.h:44
void Send(Time BlockTime, uint32_t burstSize, Ptr< WimaxPhy > phy, bool isFirstBlock, bool isLastBlock, uint64_t frequency, WimaxPhy::ModulationType modulationType, uint8_t direction, double txPowerDbm, Ptr< PacketBurst > burst)
Sends a dummy fec block to all connected physical devices.
void EndReceive(Ptr< const PacketBurst > burst)
uint16_t DoGetNfft(void) const
void ActivateLoss(bool loss)
If activate loss is called with false, all the returned BlcER will be 0 (no losses) ...
void SetPsPerSymbol(uint16_t psPerSymbol)
set the number of physical slots per symbol
Definition: wimax-phy.cc:382
void SetTraceFilePath(char *traceFilePath)
Set the path of the repository containing the traces.
Ptr< WimaxChannel > GetChannel(void) const
Definition: wimax-phy.cc:109
#define list
uint8_t GetNrCarriers(void) const
Definition: wimax-phy.cc:286
Ptr< PacketBurst > m_currentBurst
void LoadTraces(void)
Loads the traces form the repository specified in the constructor or setted by SetTraceFilePath funct...
void NotifyRxEnd(Ptr< PacketBurst > burst)
Public method used to fire a PhyRxEnd trace.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void StartSendDummyFecBlock(bool isFirstBlock, WimaxPhy::ModulationType modulationType, uint8_t direction)
static TypeId GetTypeId(void)
void SetChannelBandwidth(uint32_t channelBandwidth)
Set the channel bandwidth.
Definition: wimax-phy.cc:322
double GetTxPower(void) const
uint8_t GetDirection() const
Definition: send-params.h:83
void DoDispose(void)
Destructor implementation.
double GetNoiseFigure(void) const
uint16_t DoGetRtg(void) const
double GetValue(double min, double max)
Returns a random double from the uniform distribution with the specified range.
uint16_t GetPsPerSymbol(void) const
Definition: wimax-phy.cc:388
void DoAttach(Ptr< WimaxChannel > channel)
Attach the physical layer to a channel.
void ActivateLoss(bool loss)
if called with true it will enable the loss model
uint64_t DoGetNrBytes(uint32_t symbols, WimaxPhy::ModulationType modulationType) const
uint64_t DoGetNrSymbols(uint32_t size, WimaxPhy::ModulationType modulationType) const
void NotifyTxEnd(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxEnd trace.
uint32_t CalculateDataRate(WimaxPhy::ModulationType modulationType) const
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
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
TracedCallback< Ptr< PacketBurst > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
std::string GetTraceFilePath(void) const
void SetTxPower(double txPower)
set the transmission power
TracedCallback< Ptr< PacketBurst > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium. ...
void SetSymbolDuration(Time symbolDuration)
set the OFMD symbol duration in second
Definition: wimax-phy.cc:364
uint16_t GetNrBlocks(uint32_t burstSize, WimaxPhy::ModulationType modulationType) const
uint32_t GetBandwidth(void) const
std::vector< bool > bvec
Definition: bvec.h:28
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Ptr< PacketBurst > ConvertBitsToBurst(bvec buffer)
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:866
void SetState(PhyState state)
set the state of the device
Definition: wimax-phy.cc:189
uint8_t GetModulationType() const
Definition: send-params.h:78
void SetBlockParameters(uint32_t burstSize, WimaxPhy::ModulationType modulationType)
WimaxPhy::PhyType GetPhyType(void) const
returns the type this physical layer
void SetNrCarriers(uint8_t nrCarriers)
Set the number of carriers in the physical frame.
Definition: wimax-phy.cc:280
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:368
void GetModulationFecParams(WimaxPhy::ModulationType modulationType, uint8_t &bitsPerSymbol, double &fecCode) const
Ptr< PacketBurst > GetBurst() const
Definition: send-params.h:73
uint32_t GetFecBlockSize(WimaxPhy::ModulationType type) const
static const uint32_t packetSize
uint64_t GetTxFrequency(void) const
Definition: wimax-phy.cc:177
This class handles the SNR to BlcER traces.
EventId GetChnlSrchTimeoutEvent(void) const
Definition: wimax-phy.cc:206
Ptr< const AttributeAccessor > MakeStringAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: string.h:42
void SetPsPerFrame(uint16_t psPerFrame)
set the number of physical slot per frame
Definition: wimax-phy.cc:394
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
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
a unique identifier for an interface.
Definition: type-id.h:57
TypeId SetParent(TypeId tid)
Definition: type-id.cc:638
PhyState GetState(void) const
Definition: wimax-phy.cc:194
uint64_t GetScanningFrequency(void) const
Definition: wimax-phy.cc:183
TracedCallback< Ptr< PacketBurst > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
TracedCallback< Ptr< const PacketBurst > > m_traceTx
std::list< bvec > * m_fecBlocks