A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("SimpleOfdmWimaxPhy");
39 namespace ns3 {
40 
41 NS_OBJECT_ENSURE_REGISTERED (SimpleOfdmWimaxPhy)
42  ;
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 (""),
89  MakeStringAccessor (&SimpleOfdmWimaxPhy::GetTraceFilePath,
91  MakeStringChecker ())
92 
93  .AddTraceSource ("Rx", "Receive trace", MakeTraceSourceAccessor (&SimpleOfdmWimaxPhy::m_traceRx))
94 
95  .AddTraceSource ("Tx", "Transmit trace", MakeTraceSourceAccessor (&SimpleOfdmWimaxPhy::m_traceTx))
96 
97  .AddTraceSource ("PhyTxBegin",
98  "Trace source indicating a packet has begun transmitting over the channel medium",
100 
101  .AddTraceSource ("PhyTxEnd",
102  "Trace source indicating a packet has been completely transmitted over the channel",
104 
105  .AddTraceSource ("PhyTxDrop",
106  "Trace source indicating a packet has been dropped by the device during transmission",
108 
109  .AddTraceSource ("PhyRxBegin",
110  "Trace source indicating a packet has begun being received from the channel medium by the device",
112 
113  .AddTraceSource ("PhyRxEnd",
114  "Trace source indicating a packet has been completely received from the channel medium by the device",
116 
117  .AddTraceSource ("PhyRxDrop",
118  "Trace source indicating a packet has been dropped by the device during reception",
120  return tid;
121 }
122 
123 void
125 {
126  m_fecBlockSize = 0;
127  m_nrFecBlocksSent = 0;
128  m_dataRateBpsk12 = 0;
129  m_dataRateQpsk12 = 0;
130  m_dataRateQpsk34 = 0;
131  m_dataRateQam16_12 = 0;
132 
133  m_dataRateQam16_34 = 0;
134  m_dataRateQam64_23 = 0;
135  m_dataRateQam64_34 = 0;
136 
137  m_nrBlocks = 0;
138  m_blockSize = 0;
139  m_paddingBits = 0;
140  m_rxGain = 0;
141  m_txGain = 0;
142  m_nfft = 256;
143  m_g = (double) 1 / 4;
144  SetNrCarriers (192);
145  m_fecBlocks = new std::list<bvec>;
146  m_receivedFecBlocks = new std::list<bvec>;
147  m_currentBurstSize = 0;
148  m_noiseFigure = 5; // dB
149  m_txPower = 30; // dBm
150  SetBandwidth (10000000); // 10Mhz
151  m_nbErroneousBlock = 0;
154 }
155 
157 {
158  m_URNG = CreateObject<UniformRandomVariable> ();
159 
163 }
164 
166 {
170 }
171 
173 {
174 
175 }
176 
177 void
179 {
181 }
182 
183 void
185 {
188 }
189 
190 uint32_t
192 {
194 }
195 
196 void
198 {
200 }
201 
202 double
204 {
205  return m_txPower;
206 }
207 void
209 {
210  m_txPower = txPower;
211 }
212 
213 double
215 {
216  return m_noiseFigure;
217 }
218 void
220 {
221  m_noiseFigure = noiseFigure;
222 }
223 
224 void
226 {
227  delete m_receivedFecBlocks;
228  delete m_fecBlocks;
230  m_fecBlocks = 0;
233 }
234 
235 void
237 {
238  GetChannel ()->Attach (this);
239 }
240 
241 void
243 {
244  OfdmSendParams *o_params = dynamic_cast<OfdmSendParams*> (params);
245  NS_ASSERT (o_params !=0);
246  Send (o_params->GetBurst (),
248  o_params->GetDirection ());
249 
250 }
251 
254 {
256 }
257 
258 void
260  WimaxPhy::ModulationType modulationType,
261  uint8_t direction)
262 {
263 
264  if (GetState () != PHY_STATE_TX)
265  {
266  m_currentBurstSize = burst->GetSize ();
267  m_nrFecBlocksSent = 0;
268  m_currentBurst = burst;
269  SetBlockParameters (burst->GetSize (), modulationType);
271  StartSendDummyFecBlock (true, modulationType, direction);
272  m_traceTx (burst);
273  }
274 }
275 
276 void
278  WimaxPhy::ModulationType modulationType,
279  uint8_t direction)
280 {
282  bool isLastFecBlock = 0;
283  if (isFirstBlock)
284  {
285  m_blockTime = GetBlockTransmissionTime (modulationType);
286  }
287 
288  SimpleOfdmWimaxChannel *channel = dynamic_cast<SimpleOfdmWimaxChannel*> (PeekPointer (GetChannel ()));
289  NS_ASSERT (channel != 0);
290 
292  {
293  isLastFecBlock = true;
294  }
295  else
296  {
297  isLastFecBlock = false;
298  }
299  channel->Send (m_blockTime,
301  this,
302  isFirstBlock,
303  isLastFecBlock,
304  GetTxFrequency (),
305  modulationType,
306  direction,
307  m_txPower,
309 
311  Simulator::Schedule (m_blockTime, &SimpleOfdmWimaxPhy::EndSendFecBlock, this, modulationType, direction);
312 }
313 
314 
315 void
317  uint8_t direction)
318 {
321 
323  {
324  // this is the last FEC block of the burst
325  NS_ASSERT_MSG (m_nrRemainingBlocksToSend == 0, "Error while sending a burst");
327  }
328  else
329  {
330  StartSendDummyFecBlock (false,modulationType,direction);
331  }
332 }
333 
334 void
336 {
338 }
339 
340 void
342  bool isFirstBlock,
343  uint64_t frequency,
344  WimaxPhy::ModulationType modulationType,
345  uint8_t direction,
346  double rxPower,
347  Ptr<PacketBurst> burst)
348 {
349 
350  uint8_t drop = 0;
351  double Nwb = -114 + m_noiseFigure + 10 * std::log (GetBandwidth () / 1000000000.0) / 2.303;
352  double SNR = rxPower - Nwb;
353 
355  double I1 = record->GetI1 ();
356  double I2 = record->GetI2 ();
357 
358  double blockErrorRate = m_URNG->GetValue (I1, I2);
359 
360  double rand = m_URNG->GetValue (0.0, 1.0);
361 
362  if (rand < blockErrorRate)
363  {
364  drop = 1;
365  }
366  if (rand > blockErrorRate)
367  {
368  drop = 0;
369  }
370 
371  if (blockErrorRate == 1.0)
372  {
373  drop = 1;
374  }
375  if (blockErrorRate == 0.0)
376  {
377  drop = 0;
378  }
379  delete record;
380 
381  NS_LOG_INFO ("PHY: Receive rxPower=" << rxPower << ", Nwb=" << Nwb << ", SNR=" << SNR << ", Modulation="
382  << modulationType << ", BlocErrorRate=" << blockErrorRate << ", drop=" << (int) drop);
383 
384  switch (GetState ())
385  {
386  case PHY_STATE_SCANNING:
387  if (frequency == GetScanningFrequency ())
388  {
391  SetSimplex (frequency);
393  }
394  break;
395  case PHY_STATE_IDLE:
396  if (frequency == GetRxFrequency ())
397  {
398  if (isFirstBlock)
399  {
400  NotifyRxBegin (burst);
401  m_receivedFecBlocks->clear ();
403  SetBlockParameters (burstSize, modulationType);
404  m_blockTime = GetBlockTransmissionTime (modulationType);
405  }
406 
409  this,
410  burstSize,
411  modulationType,
412  direction,
413  drop,
414  burst);
415 
417  }
418  break;
419  case PHY_STATE_RX:
420  // drop
421  break;
422  case PHY_STATE_TX:
423  if (IsDuplex () && frequency == GetRxFrequency ())
424  {
425 
426  }
427  break;
428  }
429 }
430 
431 void
433  WimaxPhy::ModulationType modulationType,
434  uint8_t direction,
435  uint8_t drop,
436  Ptr<PacketBurst> burst)
437 {
440 
441  if (drop == true)
442  {
444  }
445 
446  if ((uint32_t) m_nrRecivedFecBlocks * m_blockSize == burstSize * 8 + m_paddingBits)
447  {
448  NotifyRxEnd (burst);
449  if (m_nbErroneousBlock == 0)
450  {
451  Simulator::Schedule (Seconds (0),
453  this,
454  burst);
455  }
456  else
457  {
458  NotifyRxDrop (burst);
459  }
460  m_nbErroneousBlock = 0;
462  }
463 }
464 
465 void
467 {
468  Ptr<PacketBurst> b = burst->Copy ();
469  GetReceiveCallback () (b);
470  m_traceRx (burst);
471 }
472 
473 bvec
475 {
476  bvec buffer (burst->GetSize () * 8, 0);
477 
478  std::list<Ptr<Packet> > packets = burst->GetPackets ();
479 
480  uint32_t j = 0;
481  for (std::list<Ptr<Packet> >::iterator iter = packets.begin (); iter != packets.end (); ++iter)
482  {
483  Ptr<Packet> packet = *iter;
484  uint8_t *pstart = (uint8_t*) std::malloc (packet->GetSize ());
485  std::memset (pstart, 0, packet->GetSize ());
486  packet->CopyData (pstart, packet->GetSize ());
487  bvec temp (8);
488  temp.resize (0, 0);
489  temp.resize (8, 0);
490  for (uint32_t i = 0; i < packet->GetSize (); i++)
491  {
492  for (uint8_t l = 0; l < 8; l++)
493  {
494  temp[l] = (bool)((((uint8_t) pstart[i]) >> (7 - l)) & 0x01);
495  buffer.at (j * 8 + l) = temp[l];
496  }
497  j++;
498  }
499  std::free (pstart);
500  }
501 
502  return buffer;
503 }
504 
505 /*
506  Converts back the bit buffer (bvec) to the actual burst.
507  Actually creates byte buffer from the bvec and resets the buffer
508  of each packet in the copy of the orifinal burst stored before transmitting.
509  By doing this it preserves the metadata and tags in the packet.
510  Function could also be named DeserializeBurst because actually it
511  copying to the burst's byte buffer.
512  */
515 {
516  uint8_t init[buffer.size () / 8];
517  uint8_t *pstart = init;
518  uint8_t temp;
519  int32_t j = 0;
520  // recreating byte buffer from bit buffer (bvec)
521  for (uint32_t i = 0; i < buffer.size (); i += 8)
522  {
523 
524  temp = 0;
525  for (int l = 0; l < 8; l++)
526  {
527  bool bin = buffer.at (i + l);
528  temp += (uint8_t)(bin * std::pow (2.0, (7 - l)));
529  }
530 
531  *(pstart + j) = temp;
532  j++;
533  }
534  uint16_t bufferSize = buffer.size () / 8;
535  uint16_t pos = 0;
536  Ptr<PacketBurst> RecvBurst = Create<PacketBurst> ();
537  while (pos < bufferSize)
538  {
539  uint16_t packetSize = 0;
540  // Get the header type: first bit
541  uint8_t ht = (pstart[pos] >> 7) & 0x01;
542  if (ht == 1)
543  {
544  // BW request header. Size is always 8 bytes
545  packetSize = 6;
546  }
547  else
548  {
549  // Read the size
550  uint8_t Len_MSB = pstart[pos + 1] & 0x07;
551  packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(pstart[pos + 2]));
552  if (packetSize == 0)
553  {
554  break; // padding
555  }
556  }
557 
558  Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize);
559  RecvBurst->AddPacket (p);
560  pos += packetSize;
561  }
562  return RecvBurst;
563 }
564 
565 void
567 {
568 
569  bvec fecBlock (m_blockSize);
570  for (uint32_t i = 0, j = m_nrBlocks; j > 0; i += m_blockSize, j--)
571  {
572 
573  if (j == 1 && m_paddingBits > 0) // last block can be smaller than block size
574  {
575  fecBlock = bvec (buffer.begin () + i, buffer.end ());
576  fecBlock.resize (m_blockSize, 0);
577  }
578  else
579  {
580  fecBlock = bvec (buffer.begin () + i, buffer.begin () + i + m_blockSize);
581  }
582 
583  m_fecBlocks->push_back (fecBlock);
584  }
585 }
586 
587 bvec
589 {
590 
591  bvec buffer (m_blockSize * (unsigned long)m_nrBlocks);
592  bvec block (m_blockSize);
593  uint32_t i = 0;
594  for (uint32_t j = 0; j < m_nrBlocks; j++)
595  {
596  bvec tmpRecFecBloc = m_receivedFecBlocks->front ();
597  buffer.insert (buffer.begin () + i, tmpRecFecBloc.begin (), tmpRecFecBloc.end ());
598  m_receivedFecBlocks->pop_front ();
599  i += m_blockSize;
600  }
601  return buffer;
602 }
603 
604 void
606 {
614 }
615 
616 void
618  uint8_t &bitsPerSymbol,
619  double &fecCode) const
620 {
621  switch (modulationType)
622  {
624  bitsPerSymbol = 1;
625  fecCode = (double) 1 / 2;
626  break;
628  bitsPerSymbol = 2;
629  fecCode = (double) 1 / 2;
630  break;
632  bitsPerSymbol = 2;
633  fecCode = (double) 3 / 4;
634  break;
636  bitsPerSymbol = 4;
637  fecCode = (double) 1 / 2;
638  break;
640  bitsPerSymbol = 4;
641  fecCode = (double) 3 / 4;
642  break;
644  bitsPerSymbol = 6;
645  fecCode = (double) 2 / 3;
646  break;
648  bitsPerSymbol = 6;
649  fecCode = 0.75;
650  break;
651  }
652 }
653 
654 uint32_t
656 {
657  uint8_t bitsPerSymbol = 0;
658  double fecCode = 0;
659  GetModulationFecParams (modulationType, bitsPerSymbol, fecCode);
660  double symbolsPerSecond = 1 / GetSymbolDuration ().GetSeconds ();
661  uint16_t bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol * GetNrCarriers () * fecCode);
662  // 96, 192, 288, 384, 576, 767 and 864 bits per symbol for the seven modulations, respectively
663 
664  return (uint32_t) symbolsPerSecond * bitsTransmittedPerSymbol;
665 }
666 
667 uint32_t
669 {
670  switch (modulationType)
671  {
673  return m_dataRateBpsk12;
674  break;
676  return m_dataRateQpsk12;
677  break;
679  return m_dataRateQpsk34;
680  break;
682  return m_dataRateQam16_12;
683  break;
685  return m_dataRateQam16_34;
686  break;
688  return m_dataRateQam64_23;
689  break;
691  return m_dataRateQam64_34;
692  break;
693  }
694  NS_FATAL_ERROR ("Invalid modulation type");
695  return 0;
696 }
697 
698 Time
700 {
701  return Seconds ((double) GetFecBlockSize (modulationType) / DoGetDataRate (modulationType));
702 }
703 
704 Time
706 {
707  /*adding 3 extra nano second to cope with the loss of precision problem.
708  the time is internally stored in a 64 bit hence a floating-point time would loss
709  precision, e.g., 0.00001388888888888889 seconds will become 13888888888 femtoseconds.*/
710  return Seconds (DoGetNrSymbols (size, modulationType) * GetSymbolDuration ().GetSeconds ()) + NanoSeconds (3);
711 }
712 
713 uint64_t
715 {
716  Time transmissionTime = Seconds ((double)(GetNrBlocks (size, modulationType) * GetFecBlockSize (modulationType))
717  / DoGetDataRate (modulationType));
718  return (uint64_t) std::ceil (transmissionTime.GetSeconds () / GetSymbolDuration ().GetSeconds ());
719 }
720 
721 uint64_t
722 SimpleOfdmWimaxPhy::DoGetNrBytes (uint32_t symbols, WimaxPhy::ModulationType modulationType) const
723 {
724  Time transmissionTime = Seconds (symbols * GetSymbolDuration ().GetSeconds ());
725  return (uint64_t) std::floor ((transmissionTime.GetSeconds () * DoGetDataRate (modulationType)) / 8);
726 }
727 
728 uint32_t
730 {
731  uint32_t blockSize = 0;
732  switch (modulationType)
733  {
735  blockSize = 12;
736  break;
738  blockSize = 24;
739  break;
741  blockSize = 36;
742  break;
744  blockSize = 48;
745  break;
747  blockSize = 72;
748  break;
750  blockSize = 96;
751  break;
753  blockSize = 108;
754  break;
755  default:
756  NS_FATAL_ERROR ("Invalid modulation type");
757  break;
758  }
759  return blockSize * 8; // in bits
760 }
761 
762 // Channel coding block size, Table 215, page 434
763 uint32_t
765 {
766  uint32_t blockSize = 0;
767  switch (modulationType)
768  {
770  blockSize = 24;
771  break;
773  blockSize = 48;
774  break;
776  blockSize = 48;
777  break;
779  blockSize = 96;
780  break;
782  blockSize = 96;
783  break;
785  blockSize = 144;
786  break;
788  blockSize = 144;
789  break;
790  default:
791  NS_FATAL_ERROR ("Invalid modulation type");
792  break;
793  }
794  return blockSize * 8; // in bits
795 }
796 
797 void
799 {
800  m_blockSize = GetFecBlockSize (modulationType);
801  m_nrBlocks = GetNrBlocks (burstSize, modulationType);
802  m_paddingBits = (m_nrBlocks * m_blockSize) - (burstSize * 8);
804  NS_ASSERT_MSG (static_cast<uint32_t> (m_nrBlocks * m_blockSize) >= (burstSize * 8), "Size of padding bytes < 0");
805 }
806 
807 uint16_t
809 {
810  // assumed equal to 2 symbols
811  return 2 * GetPsPerSymbol ();
812 }
813 
814 uint16_t
816 {
817  // assumed equal to 2 symbols
818  return 2 * GetPsPerSymbol ();
819 }
820 
821 uint8_t
823 {
824  uint16_t duration = 0;
825  duration = (uint16_t)(GetFrameDuration ().GetSeconds () * 10000);
826  uint8_t retval = 0;
827  switch (duration)
828  {
829  case 25:
830  {
832  break;
833  }
834  case 40:
835  {
836  retval = FRAME_DURATION_4_MS;
837  break;
838  }
839  case 50:
840  {
841  retval = FRAME_DURATION_5_MS;
842  break;
843  }
844  case 80:
845  {
846  retval = FRAME_DURATION_8_MS;
847  break;
848  }
849  case 100:
850  {
851  retval = FRAME_DURATION_10_MS;
852  break;
853  }
854  case 125:
855  {
857  break;
858  }
859  case 200:
860  {
861  retval = FRAME_DURATION_20_MS;
862  break;
863  }
864  default:
865  {
866  NS_FATAL_ERROR ("Invalid frame duration = " << duration);
867  retval = 0;
868  }
869  }
870  return retval;
871 }
872 
873 Time
874 SimpleOfdmWimaxPhy::DoGetFrameDuration (uint8_t frameDurationCode) const
875 {
876  switch (frameDurationCode)
877  {
879  return Seconds (2.5);
880  break;
881  case FRAME_DURATION_4_MS:
882  return Seconds (4);
883  break;
884  case FRAME_DURATION_5_MS:
885  return Seconds (5);
886  break;
887  case FRAME_DURATION_8_MS:
888  return Seconds (8);
889  break;
891  return Seconds (10);
892  break;
894  return Seconds (12.5);
895  break;
897  return Seconds (20);
898  break;
899  default:
900  NS_FATAL_ERROR ("Invalid modulation type");
901  }
902  return Seconds (0);
903 }
904 
905 /*
906  Retruns number of blocks (FEC blocks) the burst will be splitted in.
907  The size of the block is specific for each modulation type.
908  */
909 uint16_t
910 SimpleOfdmWimaxPhy::GetNrBlocks (uint32_t burstSize, WimaxPhy::ModulationType modulationType) const
911 {
912  uint32_t blockSize = GetFecBlockSize (modulationType);
913  uint16_t nrBlocks = (burstSize * 8) / blockSize;
914 
915  if ((burstSize * 8) % blockSize > 0)
916  {
917  nrBlocks += 1;
918  }
919 
920  return nrBlocks;
921 }
922 /*---------------------PHY parameters functions-----------------------*/
923 
924 void
926 {
927  /*Calculations as per section 8.3.2.
928  Currently assuming license-exempt 5 GHz band. For channel bandwidth 20 MHz (Table B.28, page 812) and frame duration 10 ms
929  (Table 232, page 460) i.e, 100 frames per second, sampling frequency is 23040000, symbol (OFDM symbol) duration is
930  1.388888888888889e-05 seconds, PS duration is 1.7361111111111112e-07 seconds. Hence PSs per frame is 57600, symbols per frame
931  is 720 and PSs per symbol is 80. Note that defining these parameters (symbol and PS duration) as Time may not result in exaclty
932  these values therefore lrint has been used (otherwise should be defined as double).
933  For licensed bands set channel bandwidth according to Table B.26, page 810.*/
934 
935  double samplingFrequency = DoGetSamplingFrequency ();
936  Time psDuration = Seconds ((double) 4 / samplingFrequency);
937 
938  SetPsDuration (psDuration);
939  uint16_t psPerFrame = (uint16_t)(GetFrameDuration ().GetSeconds () / psDuration.GetSeconds ());
940  SetPsPerFrame (psPerFrame);
941  double subcarrierSpacing = samplingFrequency / DoGetNfft ();
942  double tb = (double) 1 / subcarrierSpacing; // Tb (useful symbol time)
943  double tg = DoGetGValue () * tb; // Tg (cyclic prefix time)
944  Time symbolDuration = Seconds (tb + tg); // OFDM Symbol Time
945  SetSymbolDuration (symbolDuration);
946  uint16_t psPerSymbol = lrint (symbolDuration.GetSeconds () / psDuration.GetSeconds ());
947  SetPsPerSymbol (psPerSymbol);
948  uint32_t symbolsPerFrame = lrint (GetFrameDuration ().GetSeconds () / symbolDuration.GetSeconds ());
949  SetSymbolsPerFrame (symbolsPerFrame);
950 }
951 
952 void
954 {
955  m_nfft = nfft;
956 
957 }
958 
959 uint16_t
961 {
962  return m_nfft;
963 
964 }
965 
966 double
968 {
969  // sampling factor (n), see Table 213, page 429
970 
971  uint32_t channelBandwidth = GetChannelBandwidth ();
972 
973  if (channelBandwidth % 1750000 == 0)
974  {
975  return (double) 8 / 7;
976  }
977  else if (channelBandwidth % 1500000 == 0)
978  {
979  return (double) 86 / 75;
980  }
981  else if (channelBandwidth % 1250000 == 0)
982  {
983  return (double) 144 / 125;
984  }
985  else if (channelBandwidth % 2750000 == 0)
986  {
987  return (double) 316 / 275;
988  }
989  else if (channelBandwidth % 2000000 == 0)
990  {
991  return (double) 57 / 50;
992  }
993  else
994  {
995  NS_LOG_DEBUG ("Oops may be wrong channel bandwidth for OFDM PHY!");
996  NS_FATAL_ERROR ("wrong channel bandwidth for OFDM PHY");
997  }
998 
999  return (double) 8 / 7;
1000 }
1001 
1002 double
1004 {
1005  // sampling frequency (Fs), see 8.3.2.2
1006 
1007  return (DoGetSamplingFactor () * GetChannelBandwidth () / 8000) * 8000;
1008 }
1009 
1010 double
1012 {
1013 
1014  return m_g;
1015 }
1016 
1017 void
1019 {
1020  m_g = g;
1021 
1022 }
1023 
1024 void
1026 {
1027  m_txGain = txGain;
1028 }
1029 
1030 void
1032 {
1033  m_rxGain = txRain;
1034 }
1035 
1036 double
1038 {
1039  return m_txGain;
1040 }
1041 
1042 double
1044 {
1045  return m_rxGain;
1046 }
1047 
1048 std::string
1050 {
1052 }
1053 
1054 void
1056 {
1057 
1058  m_snrToBlockErrorRateManager->SetTraceFilePath ((char*) path.c_str ());
1060 }
1061 
1062 void
1064 {
1065  m_phyTxBeginTrace (burst);
1066 }
1067 
1068 void
1070 {
1071  m_phyTxEndTrace (burst);
1072 }
1073 
1074 void
1076 {
1077  m_phyTxDropTrace (burst);
1078 }
1079 
1080 void
1082 {
1083  m_phyRxBeginTrace (burst);
1084 }
1085 
1086 void
1088 {
1089  m_phyRxEndTrace (burst);
1090 }
1091 
1092 void
1094 {
1095  m_phyRxDropTrace (burst);
1096 }
1097 
1098 int64_t
1100 {
1101  NS_LOG_FUNCTION (this << stream);
1102  m_URNG->SetStream (stream);
1103  return 1;
1104 }
1105 
1106 } // namespace ns3
void SetNoiseFigure(double nf)
set the noise figure of the device
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
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
Callback< void, Ptr< const PacketBurst > > GetReceiveCallback(void) const
Definition: wimax-phy.cc:152
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
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.
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:19
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)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
Definition: wimax-phy.cc:96
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:201
uint32_t GetChannelBandwidth(void) const
Definition: wimax-phy.cc:329
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
std::list< bvec > * m_receivedFecBlocks
uint32_t GetSize(void) const
Definition: packet.h:650
SNRToBlockErrorRateManager * m_snrToBlockErrorRateManager
void SetSimplex(uint64_t frequency)
configure the physical layer in simplex mode
Definition: wimax-phy.cc:165
void NotifyTxDrop(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxDrop trace.
#define NS_LOG_INFO(msg)
Definition: log.h:298
Time DoGetTransmissionTime(uint32_t size, WimaxPhy::ModulationType modulationType) const
uint64_t GetRxFrequency(void) const
Definition: wimax-phy.cc:172
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:268
uint8_t DoGetFrameDurationCode(void) const
Time GetSymbolDuration(void) const
Definition: wimax-phy.cc:371
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:824
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:407
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:353
Time GetFrameDuration(void) const
Definition: wimax-phy.cc:299
void SetBandwidth(uint32_t BW)
Set the bandwidth.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
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
Definition: nstime.h:274
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
void SetScanningCallback(void) const
calls the scanning call back function
Definition: wimax-phy.cc:213
Hold an unsigned integer type.
Definition: uinteger.h:46
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.
T * PeekPointer(const Ptr< T > &p)
Definition: ptr.h:279
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:383
void SetTraceFilePath(char *traceFilePath)
Set the path of the repository containing the traces.
Ptr< WimaxChannel > GetChannel(void) const
Definition: wimax-phy.cc:110
#define list
uint8_t GetNrCarriers(void) const
Definition: wimax-phy.cc:287
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.
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:323
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
double GetTxPower(void) const
uint8_t GetDirection() const
Definition: send-params.h:83
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
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:389
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)
Definition: assert.h:86
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:365
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)
Definition: log.h:289
Ptr< PacketBurst > ConvertBitsToBurst(bvec buffer)
void SetState(PhyState state)
set the state of the device
Definition: wimax-phy.cc:190
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:281
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:381
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
uint64_t GetTxFrequency(void) const
Definition: wimax-phy.cc:178
This class handles the SNR to BlcER traces.
EventId GetChnlSrchTimeoutEvent(void) const
Definition: wimax-phy.cc:207
void SetPsPerFrame(uint16_t psPerFrame)
set the number of physical slot per frame
Definition: wimax-phy.cc:395
Hold a floating point type.
Definition: double.h:41
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
PhyState GetState(void) const
Definition: wimax-phy.cc:195
uint64_t GetScanningFrequency(void) const
Definition: wimax-phy.cc:184
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
NS_LOG_COMPONENT_DEFINE("SimpleOfdmWimaxPhy")