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 
44 {
45  static TypeId
46  tid =
47  TypeId ("ns3::SimpleOfdmWimaxPhy").SetParent<WimaxPhy> ()
48 
49  .AddAttribute ("NoiseFigure",
50  "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.",
51  DoubleValue (5),
53  MakeDoubleChecker<double> ())
54 
55  .AddAttribute ("TxPower",
56  "Transmission power (dB).",
57  DoubleValue (30),
59  MakeDoubleChecker<double> ())
60 
61  .AddAttribute ("G",
62  "This is the ratio of CP time to useful time.",
63  DoubleValue (0.25),
65  MakeDoubleChecker<double> ())
66 
67  .AddAttribute ("TxGain",
68  "Transmission gain (dB).",
69  DoubleValue (0),
71  MakeDoubleChecker<double> ())
72 
73  .AddAttribute ("RxGain",
74  "Reception gain (dB).",
75  DoubleValue (0),
77  MakeDoubleChecker<double> ())
78 
79  .AddAttribute ("Nfft",
80  "FFT size",
81  UintegerValue (256),
83  MakeUintegerChecker<uint16_t> (256, 1024))
84 
85  .AddAttribute ("TraceFilePath",
86  "Path to the directory containing SNR to block error rate files",
87  StringValue (""),
88  MakeStringAccessor (&SimpleOfdmWimaxPhy::GetTraceFilePath,
90  MakeStringChecker ())
91 
92  .AddTraceSource ("Rx", "Receive trace", MakeTraceSourceAccessor (&SimpleOfdmWimaxPhy::m_traceRx))
93 
94  .AddTraceSource ("Tx", "Transmit trace", MakeTraceSourceAccessor (&SimpleOfdmWimaxPhy::m_traceTx))
95 
96  .AddTraceSource ("PhyTxBegin",
97  "Trace source indicating a packet has begun transmitting over the channel medium",
99 
100  .AddTraceSource ("PhyTxEnd",
101  "Trace source indicating a packet has been completely transmitted over the channel",
103 
104  .AddTraceSource ("PhyTxDrop",
105  "Trace source indicating a packet has been dropped by the device during transmission",
107 
108  .AddTraceSource ("PhyRxBegin",
109  "Trace source indicating a packet has begun being received from the channel medium by the device",
111 
112  .AddTraceSource ("PhyRxEnd",
113  "Trace source indicating a packet has been completely received from the channel medium by the device",
115 
116  .AddTraceSource ("PhyRxDrop",
117  "Trace source indicating a packet has been dropped by the device during reception",
119  return tid;
120 }
121 
122 void
124 {
125  m_fecBlockSize = 0;
126  m_nrFecBlocksSent = 0;
127  m_dataRateBpsk12 = 0;
128  m_dataRateQpsk12 = 0;
129  m_dataRateQpsk34 = 0;
130  m_dataRateQam16_12 = 0;
131 
132  m_dataRateQam16_34 = 0;
133  m_dataRateQam64_23 = 0;
134  m_dataRateQam64_34 = 0;
135 
136  m_nrBlocks = 0;
137  m_blockSize = 0;
138  m_paddingBits = 0;
139  m_rxGain = 0;
140  m_txGain = 0;
141  m_nfft = 256;
142  m_g = (double) 1 / 4;
143  SetNrCarriers (192);
144  m_fecBlocks = new std::list<bvec>;
145  m_receivedFecBlocks = new std::list<bvec>;
146  m_currentBurstSize = 0;
147  m_noiseFigure = 5; // dB
148  m_txPower = 30; // dBm
149  SetBandwidth (10000000); // 10Mhz
150  m_nbErroneousBlock = 0;
153 }
154 
156 {
157  m_URNG = CreateObject<UniformRandomVariable> ();
158 
162 }
163 
165 {
169 }
170 
172 {
173 
174 }
175 
176 void
178 {
180 }
181 
182 void
184 {
187 }
188 
189 uint32_t
191 {
193 }
194 
195 void
197 {
199 }
200 
201 double
203 {
204  return m_txPower;
205 }
206 void
208 {
209  m_txPower = txPower;
210 }
211 
212 double
214 {
215  return m_noiseFigure;
216 }
217 void
219 {
220  m_noiseFigure = noiseFigure;
221 }
222 
223 void
225 {
226  delete m_receivedFecBlocks;
227  delete m_fecBlocks;
229  m_fecBlocks = 0;
232 }
233 
234 void
236 {
237  GetChannel ()->Attach (this);
238 }
239 
240 void
242 {
243  OfdmSendParams *o_params = dynamic_cast<OfdmSendParams*> (params);
244  NS_ASSERT (o_params !=0);
245  Send (o_params->GetBurst (),
247  o_params->GetDirection ());
248 
249 }
250 
253 {
255 }
256 
257 void
259  WimaxPhy::ModulationType modulationType,
260  uint8_t direction)
261 {
262 
263  if (GetState () != PHY_STATE_TX)
264  {
265  m_currentBurstSize = burst->GetSize ();
266  m_nrFecBlocksSent = 0;
267  m_currentBurst = burst;
268  SetBlockParameters (burst->GetSize (), modulationType);
270  StartSendDummyFecBlock (true, modulationType, direction);
271  m_traceTx (burst);
272  }
273 }
274 
275 void
277  WimaxPhy::ModulationType modulationType,
278  uint8_t direction)
279 {
281  bool isLastFecBlock = 0;
282  if (isFirstBlock)
283  {
284  m_blockTime = GetBlockTransmissionTime (modulationType);
285  }
286 
287  SimpleOfdmWimaxChannel *channel = dynamic_cast<SimpleOfdmWimaxChannel*> (PeekPointer (GetChannel ()));
288  NS_ASSERT (channel != 0);
289 
291  {
292  isLastFecBlock = true;
293  }
294  else
295  {
296  isLastFecBlock = false;
297  }
298  channel->Send (m_blockTime,
300  this,
301  isFirstBlock,
302  isLastFecBlock,
303  GetTxFrequency (),
304  modulationType,
305  direction,
306  m_txPower,
308 
310  Simulator::Schedule (m_blockTime, &SimpleOfdmWimaxPhy::EndSendFecBlock, this, modulationType, direction);
311 }
312 
313 
314 void
316  uint8_t direction)
317 {
320 
322  {
323  // this is the last FEC block of the burst
324  NS_ASSERT_MSG (m_nrRemainingBlocksToSend == 0, "Error while sending a burst");
326  }
327  else
328  {
329  StartSendDummyFecBlock (false,modulationType,direction);
330  }
331 }
332 
333 void
335 {
337 }
338 
339 void
341  bool isFirstBlock,
342  uint64_t frequency,
343  WimaxPhy::ModulationType modulationType,
344  uint8_t direction,
345  double rxPower,
346  Ptr<PacketBurst> burst)
347 {
348 
349  uint8_t drop = 0;
350  double Nwb = -114 + m_noiseFigure + 10 * std::log (GetBandwidth () / 1000000000.0) / 2.303;
351  double SNR = rxPower - Nwb;
352 
354  double I1 = record->GetI1 ();
355  double I2 = record->GetI2 ();
356 
357  double blockErrorRate = m_URNG->GetValue (I1, I2);
358 
359  double rand = m_URNG->GetValue (0.0, 1.0);
360 
361  if (rand < blockErrorRate)
362  {
363  drop = 1;
364  }
365  if (rand > blockErrorRate)
366  {
367  drop = 0;
368  }
369 
370  if (blockErrorRate == 1.0)
371  {
372  drop = 1;
373  }
374  if (blockErrorRate == 0.0)
375  {
376  drop = 0;
377  }
378  delete record;
379 
380  NS_LOG_INFO ("PHY: Receive rxPower=" << rxPower << ", Nwb=" << Nwb << ", SNR=" << SNR << ", Modulation="
381  << modulationType << ", BlocErrorRate=" << blockErrorRate << ", drop=" << (int) drop);
382 
383  switch (GetState ())
384  {
385  case PHY_STATE_SCANNING:
386  if (frequency == GetScanningFrequency ())
387  {
390  SetSimplex (frequency);
392  }
393  break;
394  case PHY_STATE_IDLE:
395  if (frequency == GetRxFrequency ())
396  {
397  if (isFirstBlock)
398  {
399  NotifyRxBegin (burst);
400  m_receivedFecBlocks->clear ();
402  SetBlockParameters (burstSize, modulationType);
403  m_blockTime = GetBlockTransmissionTime (modulationType);
404  }
405 
408  this,
409  burstSize,
410  modulationType,
411  direction,
412  drop,
413  burst);
414 
416  }
417  break;
418  case PHY_STATE_RX:
419  // drop
420  break;
421  case PHY_STATE_TX:
422  if (IsDuplex () && frequency == GetRxFrequency ())
423  {
424 
425  }
426  break;
427  }
428 }
429 
430 void
432  WimaxPhy::ModulationType modulationType,
433  uint8_t direction,
434  uint8_t drop,
435  Ptr<PacketBurst> burst)
436 {
439 
440  if (drop == true)
441  {
443  }
444 
445  if ((uint32_t) m_nrRecivedFecBlocks * m_blockSize == burstSize * 8 + m_paddingBits)
446  {
447  NotifyRxEnd (burst);
448  if (m_nbErroneousBlock == 0)
449  {
450  Simulator::Schedule (Seconds (0),
452  this,
453  burst);
454  }
455  else
456  {
457  NotifyRxDrop (burst);
458  }
459  m_nbErroneousBlock = 0;
461  }
462 }
463 
464 void
466 {
467  Ptr<PacketBurst> b = burst->Copy ();
468  GetReceiveCallback () (b);
469  m_traceRx (burst);
470 }
471 
472 bvec
474 {
475  bvec buffer (burst->GetSize () * 8, 0);
476 
477  std::list<Ptr<Packet> > packets = burst->GetPackets ();
478 
479  uint32_t j = 0;
480  for (std::list<Ptr<Packet> >::iterator iter = packets.begin (); iter != packets.end (); ++iter)
481  {
482  Ptr<Packet> packet = *iter;
483  uint8_t *pstart = (uint8_t*) std::malloc (packet->GetSize ());
484  std::memset (pstart, 0, packet->GetSize ());
485  packet->CopyData (pstart, packet->GetSize ());
486  bvec temp (8);
487  temp.resize (0, 0);
488  temp.resize (8, 0);
489  for (uint32_t i = 0; i < packet->GetSize (); i++)
490  {
491  for (uint8_t l = 0; l < 8; l++)
492  {
493  temp[l] = (bool)((((uint8_t) pstart[i]) >> (7 - l)) & 0x01);
494  buffer.at (j * 8 + l) = temp[l];
495  }
496  j++;
497  }
498  std::free (pstart);
499  }
500 
501  return buffer;
502 }
503 
504 /*
505  Converts back the bit buffer (bvec) to the actual burst.
506  Actually creates byte buffer from the bvec and resets the buffer
507  of each packet in the copy of the orifinal burst stored before transmitting.
508  By doing this it preserves the metadata and tags in the packet.
509  Function could also be named DeserializeBurst because actually it
510  copying to the burst's byte buffer.
511  */
514 {
515  uint8_t init[buffer.size () / 8];
516  uint8_t *pstart = init;
517  uint8_t temp;
518  int32_t j = 0;
519  // recreating byte buffer from bit buffer (bvec)
520  for (uint32_t i = 0; i < buffer.size (); i += 8)
521  {
522 
523  temp = 0;
524  for (int l = 0; l < 8; l++)
525  {
526  bool bin = buffer.at (i + l);
527  temp += (uint8_t)(bin * std::pow (2.0, (7 - l)));
528  }
529 
530  *(pstart + j) = temp;
531  j++;
532  }
533  uint16_t bufferSize = buffer.size () / 8;
534  uint16_t pos = 0;
535  Ptr<PacketBurst> RecvBurst = Create<PacketBurst> ();
536  while (pos < bufferSize)
537  {
538  uint16_t packetSize = 0;
539  // Get the header type: first bit
540  uint8_t ht = (pstart[pos] >> 7) & 0x01;
541  if (ht == 1)
542  {
543  // BW request header. Size is always 8 bytes
544  packetSize = 6;
545  }
546  else
547  {
548  // Read the size
549  uint8_t Len_MSB = pstart[pos + 1] & 0x07;
550  packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(pstart[pos + 2]));
551  if (packetSize == 0)
552  {
553  break; // padding
554  }
555  }
556 
557  Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize);
558  RecvBurst->AddPacket (p);
559  pos += packetSize;
560  }
561  return RecvBurst;
562 }
563 
564 void
566 {
567 
568  bvec fecBlock (m_blockSize);
569  for (uint32_t i = 0, j = m_nrBlocks; j > 0; i += m_blockSize, j--)
570  {
571 
572  if (j == 1 && m_paddingBits > 0) // last block can be smaller than block size
573  {
574  fecBlock = bvec (buffer.begin () + i, buffer.end ());
575  fecBlock.resize (m_blockSize, 0);
576  }
577  else
578  {
579  fecBlock = bvec (buffer.begin () + i, buffer.begin () + i + m_blockSize);
580  }
581 
582  m_fecBlocks->push_back (fecBlock);
583  }
584 }
585 
586 bvec
588 {
589 
590  bvec buffer (m_blockSize * (unsigned long)m_nrBlocks);
591  bvec block (m_blockSize);
592  uint32_t i = 0;
593  for (uint32_t j = 0; j < m_nrBlocks; j++)
594  {
595  bvec tmpRecFecBloc = m_receivedFecBlocks->front ();
596  buffer.insert (buffer.begin () + i, tmpRecFecBloc.begin (), tmpRecFecBloc.end ());
597  m_receivedFecBlocks->pop_front ();
598  i += m_blockSize;
599  }
600  return buffer;
601 }
602 
603 void
605 {
613 }
614 
615 void
617  uint8_t &bitsPerSymbol,
618  double &fecCode) const
619 {
620  switch (modulationType)
621  {
623  bitsPerSymbol = 1;
624  fecCode = (double) 1 / 2;
625  break;
627  bitsPerSymbol = 2;
628  fecCode = (double) 1 / 2;
629  break;
631  bitsPerSymbol = 2;
632  fecCode = (double) 3 / 4;
633  break;
635  bitsPerSymbol = 4;
636  fecCode = (double) 1 / 2;
637  break;
639  bitsPerSymbol = 4;
640  fecCode = (double) 3 / 4;
641  break;
643  bitsPerSymbol = 6;
644  fecCode = (double) 2 / 3;
645  break;
647  bitsPerSymbol = 6;
648  fecCode = 0.75;
649  break;
650  }
651 }
652 
653 uint32_t
655 {
656  uint8_t bitsPerSymbol = 0;
657  double fecCode = 0;
658  GetModulationFecParams (modulationType, bitsPerSymbol, fecCode);
659  double symbolsPerSecond = 1 / GetSymbolDuration ().GetSeconds ();
660  uint16_t bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol * GetNrCarriers () * fecCode);
661  // 96, 192, 288, 384, 576, 767 and 864 bits per symbol for the seven modulations, respectively
662 
663  return (uint32_t) symbolsPerSecond * bitsTransmittedPerSymbol;
664 }
665 
666 uint32_t
668 {
669  switch (modulationType)
670  {
672  return m_dataRateBpsk12;
673  break;
675  return m_dataRateQpsk12;
676  break;
678  return m_dataRateQpsk34;
679  break;
681  return m_dataRateQam16_12;
682  break;
684  return m_dataRateQam16_34;
685  break;
687  return m_dataRateQam64_23;
688  break;
690  return m_dataRateQam64_34;
691  break;
692  }
693  NS_FATAL_ERROR ("Invalid modulation type");
694  return 0;
695 }
696 
697 Time
699 {
700  return Seconds ((double) GetFecBlockSize (modulationType) / DoGetDataRate (modulationType));
701 }
702 
703 Time
705 {
706  /*adding 3 extra nano second to cope with the loss of precision problem.
707  the time is internally stored in a 64 bit hence a floating-point time would loss
708  precision, e.g., 0.00001388888888888889 seconds will become 13888888888 femtoseconds.*/
709  return Seconds (DoGetNrSymbols (size, modulationType) * GetSymbolDuration ().GetSeconds ()) + NanoSeconds (3);
710 }
711 
712 uint64_t
714 {
715  Time transmissionTime = Seconds ((double)(GetNrBlocks (size, modulationType) * GetFecBlockSize (modulationType))
716  / DoGetDataRate (modulationType));
717  return (uint64_t) std::ceil (transmissionTime.GetSeconds () / GetSymbolDuration ().GetSeconds ());
718 }
719 
720 uint64_t
721 SimpleOfdmWimaxPhy::DoGetNrBytes (uint32_t symbols, WimaxPhy::ModulationType modulationType) const
722 {
723  Time transmissionTime = Seconds (symbols * GetSymbolDuration ().GetSeconds ());
724  return (uint64_t) std::floor ((transmissionTime.GetSeconds () * DoGetDataRate (modulationType)) / 8);
725 }
726 
727 uint32_t
729 {
730  uint32_t blockSize = 0;
731  switch (modulationType)
732  {
734  blockSize = 12;
735  break;
737  blockSize = 24;
738  break;
740  blockSize = 36;
741  break;
743  blockSize = 48;
744  break;
746  blockSize = 72;
747  break;
749  blockSize = 96;
750  break;
752  blockSize = 108;
753  break;
754  default:
755  NS_FATAL_ERROR ("Invalid modulation type");
756  break;
757  }
758  return blockSize * 8; // in bits
759 }
760 
761 // Channel coding block size, Table 215, page 434
762 uint32_t
764 {
765  uint32_t blockSize = 0;
766  switch (modulationType)
767  {
769  blockSize = 24;
770  break;
772  blockSize = 48;
773  break;
775  blockSize = 48;
776  break;
778  blockSize = 96;
779  break;
781  blockSize = 96;
782  break;
784  blockSize = 144;
785  break;
787  blockSize = 144;
788  break;
789  default:
790  NS_FATAL_ERROR ("Invalid modulation type");
791  break;
792  }
793  return blockSize * 8; // in bits
794 }
795 
796 void
798 {
799  m_blockSize = GetFecBlockSize (modulationType);
800  m_nrBlocks = GetNrBlocks (burstSize, modulationType);
801  m_paddingBits = (m_nrBlocks * m_blockSize) - (burstSize * 8);
803  NS_ASSERT_MSG (static_cast<uint32_t> (m_nrBlocks * m_blockSize) >= (burstSize * 8), "Size of padding bytes < 0");
804 }
805 
806 uint16_t
808 {
809  // assumed equal to 2 symbols
810  return 2 * GetPsPerSymbol ();
811 }
812 
813 uint16_t
815 {
816  // assumed equal to 2 symbols
817  return 2 * GetPsPerSymbol ();
818 }
819 
820 uint8_t
822 {
823  uint16_t duration = 0;
824  duration = (uint16_t)(GetFrameDuration ().GetSeconds () * 10000);
825  uint8_t retval = 0;
826  switch (duration)
827  {
828  case 25:
829  {
831  break;
832  }
833  case 40:
834  {
835  retval = FRAME_DURATION_4_MS;
836  break;
837  }
838  case 50:
839  {
840  retval = FRAME_DURATION_5_MS;
841  break;
842  }
843  case 80:
844  {
845  retval = FRAME_DURATION_8_MS;
846  break;
847  }
848  case 100:
849  {
850  retval = FRAME_DURATION_10_MS;
851  break;
852  }
853  case 125:
854  {
856  break;
857  }
858  case 200:
859  {
860  retval = FRAME_DURATION_20_MS;
861  break;
862  }
863  default:
864  {
865  NS_FATAL_ERROR ("Invalid frame duration = " << duration);
866  retval = 0;
867  }
868  }
869  return retval;
870 }
871 
872 Time
873 SimpleOfdmWimaxPhy::DoGetFrameDuration (uint8_t frameDurationCode) const
874 {
875  switch (frameDurationCode)
876  {
878  return Seconds (2.5);
879  break;
880  case FRAME_DURATION_4_MS:
881  return Seconds (4);
882  break;
883  case FRAME_DURATION_5_MS:
884  return Seconds (5);
885  break;
886  case FRAME_DURATION_8_MS:
887  return Seconds (8);
888  break;
890  return Seconds (10);
891  break;
893  return Seconds (12.5);
894  break;
896  return Seconds (20);
897  break;
898  default:
899  NS_FATAL_ERROR ("Invalid modulation type");
900  }
901  return Seconds (0);
902 }
903 
904 /*
905  Retruns number of blocks (FEC blocks) the burst will be splitted in.
906  The size of the block is specific for each modulation type.
907  */
908 uint16_t
909 SimpleOfdmWimaxPhy::GetNrBlocks (uint32_t burstSize, WimaxPhy::ModulationType modulationType) const
910 {
911  uint32_t blockSize = GetFecBlockSize (modulationType);
912  uint16_t nrBlocks = (burstSize * 8) / blockSize;
913 
914  if ((burstSize * 8) % blockSize > 0)
915  {
916  nrBlocks += 1;
917  }
918 
919  return nrBlocks;
920 }
921 /*---------------------PHY parameters functions-----------------------*/
922 
923 void
925 {
926  /*Calculations as per section 8.3.2.
927  Currently assuming license-exempt 5 GHz band. For channel bandwidth 20 MHz (Table B.28, page 812) and frame duration 10 ms
928  (Table 232, page 460) i.e, 100 frames per second, sampling frequency is 23040000, symbol (OFDM symbol) duration is
929  1.388888888888889e-05 seconds, PS duration is 1.7361111111111112e-07 seconds. Hence PSs per frame is 57600, symbols per frame
930  is 720 and PSs per symbol is 80. Note that defining these parameters (symbol and PS duration) as Time may not result in exaclty
931  these values therefore lrint has been used (otherwise should be defined as double).
932  For licensed bands set channel bandwidth according to Table B.26, page 810.*/
933 
934  double samplingFrequency = DoGetSamplingFrequency ();
935  Time psDuration = Seconds ((double) 4 / samplingFrequency);
936 
937  SetPsDuration (psDuration);
938  uint16_t psPerFrame = (uint16_t)(GetFrameDuration ().GetSeconds () / psDuration.GetSeconds ());
939  SetPsPerFrame (psPerFrame);
940  double subcarrierSpacing = samplingFrequency / DoGetNfft ();
941  double tb = (double) 1 / subcarrierSpacing; // Tb (useful symbol time)
942  double tg = DoGetGValue () * tb; // Tg (cyclic prefix time)
943  Time symbolDuration = Seconds (tb + tg); // OFDM Symbol Time
944  SetSymbolDuration (symbolDuration);
945  uint16_t psPerSymbol = lrint (symbolDuration.GetSeconds () / psDuration.GetSeconds ());
946  SetPsPerSymbol (psPerSymbol);
947  uint32_t symbolsPerFrame = lrint (GetFrameDuration ().GetSeconds () / symbolDuration.GetSeconds ());
948  SetSymbolsPerFrame (symbolsPerFrame);
949 }
950 
951 void
953 {
954  m_nfft = nfft;
955 
956 }
957 
958 uint16_t
960 {
961  return m_nfft;
962 
963 }
964 
965 double
967 {
968  // sampling factor (n), see Table 213, page 429
969 
970  uint32_t channelBandwidth = GetChannelBandwidth ();
971 
972  if (channelBandwidth % 1750000 == 0)
973  {
974  return (double) 8 / 7;
975  }
976  else if (channelBandwidth % 1500000 == 0)
977  {
978  return (double) 86 / 75;
979  }
980  else if (channelBandwidth % 1250000 == 0)
981  {
982  return (double) 144 / 125;
983  }
984  else if (channelBandwidth % 2750000 == 0)
985  {
986  return (double) 316 / 275;
987  }
988  else if (channelBandwidth % 2000000 == 0)
989  {
990  return (double) 57 / 50;
991  }
992  else
993  {
994  NS_LOG_DEBUG ("Oops may be wrong channel bandwidth for OFDM PHY!");
995  NS_FATAL_ERROR ("wrong channel bandwidth for OFDM PHY");
996  }
997 
998  return (double) 8 / 7;
999 }
1000 
1001 double
1003 {
1004  // sampling frequency (Fs), see 8.3.2.2
1005 
1006  return (DoGetSamplingFactor () * GetChannelBandwidth () / 8000) * 8000;
1007 }
1008 
1009 double
1011 {
1012 
1013  return m_g;
1014 }
1015 
1016 void
1018 {
1019  m_g = g;
1020 
1021 }
1022 
1023 void
1025 {
1026  m_txGain = txGain;
1027 }
1028 
1029 void
1031 {
1032  m_rxGain = txRain;
1033 }
1034 
1035 double
1037 {
1038  return m_txGain;
1039 }
1040 
1041 double
1043 {
1044  return m_rxGain;
1045 }
1046 
1047 std::string
1049 {
1051 }
1052 
1053 void
1055 {
1056 
1057  m_snrToBlockErrorRateManager->SetTraceFilePath ((char*) path.c_str ());
1059 }
1060 
1061 void
1063 {
1064  m_phyTxBeginTrace (burst);
1065 }
1066 
1067 void
1069 {
1070  m_phyTxEndTrace (burst);
1071 }
1072 
1073 void
1075 {
1076  m_phyTxDropTrace (burst);
1077 }
1078 
1079 void
1081 {
1082  m_phyRxBeginTrace (burst);
1083 }
1084 
1085 void
1087 {
1088  m_phyRxEndTrace (burst);
1089 }
1090 
1091 void
1093 {
1094  m_phyRxDropTrace (burst);
1095 }
1096 
1097 int64_t
1099 {
1100  NS_LOG_FUNCTION (this << stream);
1101  m_URNG->SetStream (stream);
1102  return 1;
1103 }
1104 
1105 } // 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
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
Callback< void, Ptr< const PacketBurst > > GetReceiveCallback(void) const
Definition: wimax-phy.cc:151
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#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 the class in the ns-3 factory.
Definition: object-base.h:38
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:18
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: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:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
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:744
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:223
Time DoGetTransmissionTime(uint32_t size, WimaxPhy::ModulationType modulationType) const
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:95
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:268
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:825
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.
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:272
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:212
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:280
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.
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
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: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:84
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:213
Ptr< PacketBurst > ConvertBitsToBurst(bvec buffer)
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: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:177
This class handles the SNR to BlcER traces.
EventId GetChnlSrchTimeoutEvent(void) const
Definition: wimax-phy.cc:206
void SetPsPerFrame(uint16_t psPerFrame)
set the number of physical slot per frame
Definition: wimax-phy.cc:394
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:610
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