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 tid = TypeId ("ns3::SimpleOfdmWimaxPhy")
47  .SetParent<WimaxPhy> ()
48  .SetGroupName ("Wimax")
49 
50  .AddConstructor<SimpleOfdmWimaxPhy> ()
51 
52  .AddAttribute ("NoiseFigure",
53  "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.",
54  DoubleValue (5),
56  MakeDoubleChecker<double> ())
57 
58  .AddAttribute ("TxPower",
59  "Transmission power (dB).",
60  DoubleValue (30),
62  MakeDoubleChecker<double> ())
63 
64  .AddAttribute ("G",
65  "This is the ratio of CP time to useful time.",
66  DoubleValue (0.25),
68  MakeDoubleChecker<double> ())
69 
70  .AddAttribute ("TxGain",
71  "Transmission gain (dB).",
72  DoubleValue (0),
74  MakeDoubleChecker<double> ())
75 
76  .AddAttribute ("RxGain",
77  "Reception gain (dB).",
78  DoubleValue (0),
80  MakeDoubleChecker<double> ())
81 
82  .AddAttribute ("Nfft",
83  "FFT size",
84  UintegerValue (256),
86  MakeUintegerChecker<uint16_t> (256, 1024))
87 
88  .AddAttribute ("TraceFilePath",
89  "Path to the directory containing SNR to block error rate files",
90  StringValue (""),
94 
95  .AddTraceSource ("Rx", "Receive trace",
97  "ns3::PacketBurst::TracedCallback")
98  .AddTraceSource ("Tx", "Transmit trace",
100  "ns3::PacketBurst::TracedCallback")
101 
102  .AddTraceSource ("PhyTxBegin",
103  "Trace source indicating a packet has begun transmitting over the channel medium",
105  "ns3::PacketBurst::TracedCallback")
106 
107  .AddTraceSource ("PhyTxEnd",
108  "Trace source indicating a packet has been completely transmitted over the channel",
110  "ns3::PacketBurst::TracedCallback")
111 
112  .AddTraceSource ("PhyTxDrop",
113  "Trace source indicating a packet has been dropped by the device during transmission",
115  "ns3::PacketBurst::TracedCallback")
116 
117  .AddTraceSource ("PhyRxBegin",
118  "Trace source indicating a packet has begun being received from the channel medium by the device",
120  "ns3::PacketBurst::TracedCallback")
121 
122  .AddTraceSource ("PhyRxEnd",
123  "Trace source indicating a packet has been completely received from the channel medium by the device",
125  "ns3::PacketBurst::TracedCallback")
126 
127  .AddTraceSource ("PhyRxDrop",
128  "Trace source indicating a packet has been dropped by the device during reception",
130  "ns3::PacketBurst::TracedCallback");
131  return tid;
132 }
133 
134 void
136 {
137  m_fecBlockSize = 0;
138  m_nrFecBlocksSent = 0;
139  m_dataRateBpsk12 = 0;
140  m_dataRateQpsk12 = 0;
141  m_dataRateQpsk34 = 0;
142  m_dataRateQam16_12 = 0;
143 
144  m_dataRateQam16_34 = 0;
145  m_dataRateQam64_23 = 0;
146  m_dataRateQam64_34 = 0;
147 
148  m_nrBlocks = 0;
149  m_blockSize = 0;
150  m_paddingBits = 0;
151  m_rxGain = 0;
152  m_txGain = 0;
153  m_nfft = 256;
154  m_g = (double) 1 / 4;
155  SetNrCarriers (192);
156  m_fecBlocks = new std::list<bvec>;
157  m_receivedFecBlocks = new std::list<bvec>;
158  m_currentBurstSize = 0;
159  m_noiseFigure = 5; // dB
160  m_txPower = 30; // dBm
161  SetBandwidth (10000000); // 10Mhz
162  m_nbErroneousBlock = 0;
165 }
166 
168 {
169  m_URNG = CreateObject<UniformRandomVariable> ();
170 
174 }
175 
177 {
181 }
182 
184 {
185 
186 }
187 
188 void
190 {
192 }
193 
194 void
196 {
199 }
200 
201 uint32_t
203 {
205 }
206 
207 void
209 {
211 }
212 
213 double
215 {
216  return m_txPower;
217 }
218 void
220 {
221  m_txPower = txPower;
222 }
223 
224 double
226 {
227  return m_noiseFigure;
228 }
229 void
231 {
232  m_noiseFigure = noiseFigure;
233 }
234 
235 void
237 {
238  delete m_receivedFecBlocks;
239  delete m_fecBlocks;
241  m_fecBlocks = 0;
244 }
245 
246 void
248 {
249  GetChannel ()->Attach (this);
250 }
251 
252 void
254 {
255  OfdmSendParams *o_params = dynamic_cast<OfdmSendParams*> (params);
256  NS_ASSERT (o_params !=0);
257  Send (o_params->GetBurst (),
259  o_params->GetDirection ());
260 
261 }
262 
265 {
267 }
268 
269 void
271  WimaxPhy::ModulationType modulationType,
272  uint8_t direction)
273 {
274 
275  if (GetState () != PHY_STATE_TX)
276  {
277  m_currentBurstSize = burst->GetSize ();
278  m_nrFecBlocksSent = 0;
279  m_currentBurst = burst;
280  SetBlockParameters (burst->GetSize (), modulationType);
282  StartSendDummyFecBlock (true, modulationType, direction);
283  m_traceTx (burst);
284  }
285 }
286 
287 void
289  WimaxPhy::ModulationType modulationType,
290  uint8_t direction)
291 {
293  bool isLastFecBlock = 0;
294  if (isFirstBlock)
295  {
296  m_blockTime = GetBlockTransmissionTime (modulationType);
297  }
298 
300  NS_ASSERT (channel != 0);
301 
303  {
304  isLastFecBlock = true;
305  }
306  else
307  {
308  isLastFecBlock = false;
309  }
310  channel->Send (m_blockTime,
312  this,
313  isFirstBlock,
314  isLastFecBlock,
315  GetTxFrequency (),
316  modulationType,
317  direction,
318  m_txPower,
320 
322  Simulator::Schedule (m_blockTime, &SimpleOfdmWimaxPhy::EndSendFecBlock, this, modulationType, direction);
323 }
324 
325 
326 void
328  uint8_t direction)
329 {
332 
334  {
335  // this is the last FEC block of the burst
336  NS_ASSERT_MSG (m_nrRemainingBlocksToSend == 0, "Error while sending a burst");
338  }
339  else
340  {
341  StartSendDummyFecBlock (false,modulationType,direction);
342  }
343 }
344 
345 void
347 {
349 }
350 
351 void
353  bool isFirstBlock,
354  uint64_t frequency,
355  WimaxPhy::ModulationType modulationType,
356  uint8_t direction,
357  double rxPower,
358  Ptr<PacketBurst> burst)
359 {
360 
361  uint8_t drop = 0;
362  double Nwb = -114 + m_noiseFigure + 10 * std::log (GetBandwidth () / 1000000000.0) / 2.303;
363  double SNR = rxPower - Nwb;
364 
366  double I1 = record->GetI1 ();
367  double I2 = record->GetI2 ();
368 
369  double blockErrorRate = m_URNG->GetValue (I1, I2);
370 
371  double rand = m_URNG->GetValue (0.0, 1.0);
372 
373  if (rand < blockErrorRate)
374  {
375  drop = 1;
376  }
377  if (rand > blockErrorRate)
378  {
379  drop = 0;
380  }
381 
382  if (blockErrorRate == 1.0)
383  {
384  drop = 1;
385  }
386  if (blockErrorRate == 0.0)
387  {
388  drop = 0;
389  }
390  delete record;
391 
392  NS_LOG_INFO ("PHY: Receive rxPower=" << rxPower << ", Nwb=" << Nwb << ", SNR=" << SNR << ", Modulation="
393  << modulationType << ", BlocErrorRate=" << blockErrorRate << ", drop=" << (int) drop);
394 
395  switch (GetState ())
396  {
397  case PHY_STATE_SCANNING:
398  if (frequency == GetScanningFrequency ())
399  {
402  SetSimplex (frequency);
404  }
405  break;
406  case PHY_STATE_IDLE:
407  if (frequency == GetRxFrequency ())
408  {
409  if (isFirstBlock)
410  {
411  NotifyRxBegin (burst);
412  m_receivedFecBlocks->clear ();
414  SetBlockParameters (burstSize, modulationType);
415  m_blockTime = GetBlockTransmissionTime (modulationType);
416  }
417 
420  this,
421  burstSize,
422  modulationType,
423  direction,
424  drop,
425  burst);
426 
428  }
429  break;
430  case PHY_STATE_RX:
431  // drop
432  break;
433  case PHY_STATE_TX:
434  if (IsDuplex () && frequency == GetRxFrequency ())
435  {
436 
437  }
438  break;
439  }
440 }
441 
442 void
444  WimaxPhy::ModulationType modulationType,
445  uint8_t direction,
446  uint8_t drop,
447  Ptr<PacketBurst> burst)
448 {
451 
452  if (drop == true)
453  {
455  }
456 
457  if ((uint32_t) m_nrRecivedFecBlocks * m_blockSize == burstSize * 8 + m_paddingBits)
458  {
459  NotifyRxEnd (burst);
460  if (m_nbErroneousBlock == 0)
461  {
464  this,
465  burst);
466  }
467  else
468  {
469  NotifyRxDrop (burst);
470  }
471  m_nbErroneousBlock = 0;
473  }
474 }
475 
476 void
478 {
479  Ptr<PacketBurst> b = burst->Copy ();
480  GetReceiveCallback () (b);
481  m_traceRx (burst);
482 }
483 
484 bvec
486 {
487  bvec buffer (burst->GetSize () * 8, 0);
488 
489  std::list<Ptr<Packet> > packets = burst->GetPackets ();
490 
491  uint32_t j = 0;
492  for (std::list<Ptr<Packet> >::iterator iter = packets.begin (); iter != packets.end (); ++iter)
493  {
494  Ptr<Packet> packet = *iter;
495  uint8_t *pstart = (uint8_t*) std::malloc (packet->GetSize ());
496  std::memset (pstart, 0, packet->GetSize ());
497  packet->CopyData (pstart, packet->GetSize ());
498  bvec temp (8);
499  temp.resize (0, 0);
500  temp.resize (8, 0);
501  for (uint32_t i = 0; i < packet->GetSize (); i++)
502  {
503  for (uint8_t l = 0; l < 8; l++)
504  {
505  temp[l] = (bool)((((uint8_t) pstart[i]) >> (7 - l)) & 0x01);
506  buffer.at (j * 8 + l) = temp[l];
507  }
508  j++;
509  }
510  std::free (pstart);
511  }
512 
513  return buffer;
514 }
515 
516 /*
517  Converts back the bit buffer (bvec) to the actual burst.
518  Actually creates byte buffer from the bvec and resets the buffer
519  of each packet in the copy of the orifinal burst stored before transmitting.
520  By doing this it preserves the metadata and tags in the packet.
521  Function could also be named DeserializeBurst because actually it
522  copying to the burst's byte buffer.
523  */
526 {
527  uint8_t init[buffer.size () / 8];
528  uint8_t *pstart = init;
529  uint8_t temp;
530  int32_t j = 0;
531  // recreating byte buffer from bit buffer (bvec)
532  for (uint32_t i = 0; i < buffer.size (); i += 8)
533  {
534 
535  temp = 0;
536  for (int l = 0; l < 8; l++)
537  {
538  bool bin = buffer.at (i + l);
539  temp += (uint8_t)(bin * std::pow (2.0, (7 - l)));
540  }
541 
542  *(pstart + j) = temp;
543  j++;
544  }
545  uint16_t bufferSize = buffer.size () / 8;
546  uint16_t pos = 0;
547  Ptr<PacketBurst> RecvBurst = Create<PacketBurst> ();
548  while (pos < bufferSize)
549  {
550  uint16_t packetSize = 0;
551  // Get the header type: first bit
552  uint8_t ht = (pstart[pos] >> 7) & 0x01;
553  if (ht == 1)
554  {
555  // BW request header. Size is always 8 bytes
556  packetSize = 6;
557  }
558  else
559  {
560  // Read the size
561  uint8_t Len_MSB = pstart[pos + 1] & 0x07;
562  packetSize = (uint16_t)((uint16_t)(Len_MSB << 8) | (uint16_t)(pstart[pos + 2]));
563  if (packetSize == 0)
564  {
565  break; // padding
566  }
567  }
568 
569  Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize);
570  RecvBurst->AddPacket (p);
571  pos += packetSize;
572  }
573  return RecvBurst;
574 }
575 
576 void
578 {
579 
580  bvec fecBlock (m_blockSize);
581  for (uint32_t i = 0, j = m_nrBlocks; j > 0; i += m_blockSize, j--)
582  {
583 
584  if (j == 1 && m_paddingBits > 0) // last block can be smaller than block size
585  {
586  fecBlock = bvec (buffer.begin () + i, buffer.end ());
587  fecBlock.resize (m_blockSize, 0);
588  }
589  else
590  {
591  fecBlock = bvec (buffer.begin () + i, buffer.begin () + i + m_blockSize);
592  }
593 
594  m_fecBlocks->push_back (fecBlock);
595  }
596 }
597 
598 bvec
600 {
601 
602  bvec buffer (m_blockSize * (unsigned long)m_nrBlocks);
603  bvec block (m_blockSize);
604  uint32_t i = 0;
605  for (uint32_t j = 0; j < m_nrBlocks; j++)
606  {
607  bvec tmpRecFecBloc = m_receivedFecBlocks->front ();
608  buffer.insert (buffer.begin () + i, tmpRecFecBloc.begin (), tmpRecFecBloc.end ());
609  m_receivedFecBlocks->pop_front ();
610  i += m_blockSize;
611  }
612  return buffer;
613 }
614 
615 void
617 {
625 }
626 
627 void
629  uint8_t &bitsPerSymbol,
630  double &fecCode) const
631 {
632  switch (modulationType)
633  {
635  bitsPerSymbol = 1;
636  fecCode = (double) 1 / 2;
637  break;
639  bitsPerSymbol = 2;
640  fecCode = (double) 1 / 2;
641  break;
643  bitsPerSymbol = 2;
644  fecCode = (double) 3 / 4;
645  break;
647  bitsPerSymbol = 4;
648  fecCode = (double) 1 / 2;
649  break;
651  bitsPerSymbol = 4;
652  fecCode = (double) 3 / 4;
653  break;
655  bitsPerSymbol = 6;
656  fecCode = (double) 2 / 3;
657  break;
659  bitsPerSymbol = 6;
660  fecCode = 0.75;
661  break;
662  }
663 }
664 
665 uint32_t
667 {
668  uint8_t bitsPerSymbol = 0;
669  double fecCode = 0;
670  GetModulationFecParams (modulationType, bitsPerSymbol, fecCode);
671  double symbolsPerSecond = 1 / GetSymbolDuration ().GetSeconds ();
672  uint16_t bitsTransmittedPerSymbol = (uint16_t)(bitsPerSymbol * GetNrCarriers () * fecCode);
673  // 96, 192, 288, 384, 576, 767 and 864 bits per symbol for the seven modulations, respectively
674 
675  return (uint32_t) symbolsPerSecond * bitsTransmittedPerSymbol;
676 }
677 
678 uint32_t
680 {
681  switch (modulationType)
682  {
684  return m_dataRateBpsk12;
685  break;
687  return m_dataRateQpsk12;
688  break;
690  return m_dataRateQpsk34;
691  break;
693  return m_dataRateQam16_12;
694  break;
696  return m_dataRateQam16_34;
697  break;
699  return m_dataRateQam64_23;
700  break;
702  return m_dataRateQam64_34;
703  break;
704  }
705  NS_FATAL_ERROR ("Invalid modulation type");
706  return 0;
707 }
708 
709 Time
711 {
712  return Seconds ((double) GetFecBlockSize (modulationType) / DoGetDataRate (modulationType));
713 }
714 
715 Time
717 {
718  /*adding 3 extra nano second to cope with the loss of precision problem.
719  the time is internally stored in a 64 bit hence a floating-point time would loss
720  precision, e.g., 0.00001388888888888889 seconds will become 13888888888 femtoseconds.*/
721  return Seconds (DoGetNrSymbols (size, modulationType) * GetSymbolDuration ().GetSeconds ()) + NanoSeconds (3);
722 }
723 
724 uint64_t
726 {
727  Time transmissionTime = Seconds ((double)(GetNrBlocks (size, modulationType) * GetFecBlockSize (modulationType))
728  / DoGetDataRate (modulationType));
729  return (uint64_t) std::ceil (transmissionTime.GetSeconds () / GetSymbolDuration ().GetSeconds ());
730 }
731 
732 uint64_t
733 SimpleOfdmWimaxPhy::DoGetNrBytes (uint32_t symbols, WimaxPhy::ModulationType modulationType) const
734 {
735  Time transmissionTime = Seconds (symbols * GetSymbolDuration ().GetSeconds ());
736  return (uint64_t) std::floor ((transmissionTime.GetSeconds () * DoGetDataRate (modulationType)) / 8);
737 }
738 
739 uint32_t
741 {
742  uint32_t blockSize = 0;
743  switch (modulationType)
744  {
746  blockSize = 12;
747  break;
749  blockSize = 24;
750  break;
752  blockSize = 36;
753  break;
755  blockSize = 48;
756  break;
758  blockSize = 72;
759  break;
761  blockSize = 96;
762  break;
764  blockSize = 108;
765  break;
766  default:
767  NS_FATAL_ERROR ("Invalid modulation type");
768  break;
769  }
770  return blockSize * 8; // in bits
771 }
772 
773 // Channel coding block size, Table 215, page 434
774 uint32_t
776 {
777  uint32_t blockSize = 0;
778  switch (modulationType)
779  {
781  blockSize = 24;
782  break;
784  blockSize = 48;
785  break;
787  blockSize = 48;
788  break;
790  blockSize = 96;
791  break;
793  blockSize = 96;
794  break;
796  blockSize = 144;
797  break;
799  blockSize = 144;
800  break;
801  default:
802  NS_FATAL_ERROR ("Invalid modulation type");
803  break;
804  }
805  return blockSize * 8; // in bits
806 }
807 
808 void
810 {
811  m_blockSize = GetFecBlockSize (modulationType);
812  m_nrBlocks = GetNrBlocks (burstSize, modulationType);
813  m_paddingBits = (m_nrBlocks * m_blockSize) - (burstSize * 8);
815  NS_ASSERT_MSG (static_cast<uint32_t> (m_nrBlocks * m_blockSize) >= (burstSize * 8), "Size of padding bytes < 0");
816 }
817 
818 uint16_t
820 {
821  // assumed equal to 2 symbols
822  return 2 * GetPsPerSymbol ();
823 }
824 
825 uint16_t
827 {
828  // assumed equal to 2 symbols
829  return 2 * GetPsPerSymbol ();
830 }
831 
832 uint8_t
834 {
835  uint16_t duration = 0;
836  duration = (uint16_t)(GetFrameDuration ().GetSeconds () * 10000);
837  uint8_t retval = 0;
838  switch (duration)
839  {
840  case 25:
841  {
843  break;
844  }
845  case 40:
846  {
847  retval = FRAME_DURATION_4_MS;
848  break;
849  }
850  case 50:
851  {
852  retval = FRAME_DURATION_5_MS;
853  break;
854  }
855  case 80:
856  {
857  retval = FRAME_DURATION_8_MS;
858  break;
859  }
860  case 100:
861  {
862  retval = FRAME_DURATION_10_MS;
863  break;
864  }
865  case 125:
866  {
868  break;
869  }
870  case 200:
871  {
872  retval = FRAME_DURATION_20_MS;
873  break;
874  }
875  default:
876  {
877  NS_FATAL_ERROR ("Invalid frame duration = " << duration);
878  retval = 0;
879  }
880  }
881  return retval;
882 }
883 
884 Time
885 SimpleOfdmWimaxPhy::DoGetFrameDuration (uint8_t frameDurationCode) const
886 {
887  switch (frameDurationCode)
888  {
890  return Seconds (2.5);
891  break;
892  case FRAME_DURATION_4_MS:
893  return Seconds (4);
894  break;
895  case FRAME_DURATION_5_MS:
896  return Seconds (5);
897  break;
898  case FRAME_DURATION_8_MS:
899  return Seconds (8);
900  break;
902  return Seconds (10);
903  break;
905  return Seconds (12.5);
906  break;
908  return Seconds (20);
909  break;
910  default:
911  NS_FATAL_ERROR ("Invalid modulation type");
912  }
913  return Seconds (0);
914 }
915 
916 /*
917  Retruns number of blocks (FEC blocks) the burst will be split in.
918  The size of the block is specific for each modulation type.
919  */
920 uint16_t
921 SimpleOfdmWimaxPhy::GetNrBlocks (uint32_t burstSize, WimaxPhy::ModulationType modulationType) const
922 {
923  uint32_t blockSize = GetFecBlockSize (modulationType);
924  uint16_t nrBlocks = (burstSize * 8) / blockSize;
925 
926  if ((burstSize * 8) % blockSize > 0)
927  {
928  nrBlocks += 1;
929  }
930 
931  return nrBlocks;
932 }
933 /*---------------------PHY parameters functions-----------------------*/
934 
935 void
937 {
938  /*Calculations as per section 8.3.2.
939  Currently assuming license-exempt 5 GHz band. For channel bandwidth 20 MHz (Table B.28, page 812) and frame duration 10 ms
940  (Table 232, page 460) i.e, 100 frames per second, sampling frequency is 23040000, symbol (OFDM symbol) duration is
941  1.388888888888889e-05 seconds, PS duration is 1.7361111111111112e-07 seconds. Hence PSs per frame is 57600, symbols per frame
942  is 720 and PSs per symbol is 80. Note that defining these parameters (symbol and PS duration) as Time may not result in exaclty
943  these values therefore lrint has been used (otherwise should be defined as double).
944  For licensed bands set channel bandwidth according to Table B.26, page 810.*/
945 
946  double samplingFrequency = DoGetSamplingFrequency ();
947  Time psDuration = Seconds ((double) 4 / samplingFrequency);
948 
949  SetPsDuration (psDuration);
950  uint16_t psPerFrame = (uint16_t)(GetFrameDuration ().GetSeconds () / psDuration.GetSeconds ());
951  SetPsPerFrame (psPerFrame);
952  double subcarrierSpacing = samplingFrequency / DoGetNfft ();
953  double tb = (double) 1 / subcarrierSpacing; // Tb (useful symbol time)
954  double tg = DoGetGValue () * tb; // Tg (cyclic prefix time)
955  Time symbolDuration = Seconds (tb + tg); // OFDM Symbol Time
956  SetSymbolDuration (symbolDuration);
957  uint16_t psPerSymbol = lrint (symbolDuration.GetSeconds () / psDuration.GetSeconds ());
958  SetPsPerSymbol (psPerSymbol);
959  uint32_t symbolsPerFrame = lrint (GetFrameDuration ().GetSeconds () / symbolDuration.GetSeconds ());
960  SetSymbolsPerFrame (symbolsPerFrame);
961 }
962 
963 void
965 {
966  m_nfft = nfft;
967 
968 }
969 
970 uint16_t
972 {
973  return m_nfft;
974 
975 }
976 
977 double
979 {
980  // sampling factor (n), see Table 213, page 429
981 
982  uint32_t channelBandwidth = GetChannelBandwidth ();
983 
984  if (channelBandwidth % 1750000 == 0)
985  {
986  return (double) 8 / 7;
987  }
988  else if (channelBandwidth % 1500000 == 0)
989  {
990  return (double) 86 / 75;
991  }
992  else if (channelBandwidth % 1250000 == 0)
993  {
994  return (double) 144 / 125;
995  }
996  else if (channelBandwidth % 2750000 == 0)
997  {
998  return (double) 316 / 275;
999  }
1000  else if (channelBandwidth % 2000000 == 0)
1001  {
1002  return (double) 57 / 50;
1003  }
1004  else
1005  {
1006  NS_LOG_DEBUG ("Oops may be wrong channel bandwidth for OFDM PHY!");
1007  NS_FATAL_ERROR ("wrong channel bandwidth for OFDM PHY");
1008  }
1009 
1010  return (double) 8 / 7;
1011 }
1012 
1013 double
1015 {
1016  // sampling frequency (Fs), see 8.3.2.2
1017 
1018  return (DoGetSamplingFactor () * GetChannelBandwidth () / 8000) * 8000;
1019 }
1020 
1021 double
1023 {
1024 
1025  return m_g;
1026 }
1027 
1028 void
1030 {
1031  m_g = g;
1032 
1033 }
1034 
1035 void
1037 {
1038  m_txGain = txGain;
1039 }
1040 
1041 void
1043 {
1044  m_rxGain = txRain;
1045 }
1046 
1047 double
1049 {
1050  return m_txGain;
1051 }
1052 
1053 double
1055 {
1056  return m_rxGain;
1057 }
1058 
1059 std::string
1061 {
1063 }
1064 
1065 void
1067 {
1068 
1069  m_snrToBlockErrorRateManager->SetTraceFilePath ((char*) path.c_str ());
1071 }
1072 
1073 void
1075 {
1076  m_phyTxBeginTrace (burst);
1077 }
1078 
1079 void
1081 {
1082  m_phyTxEndTrace (burst);
1083 }
1084 
1085 void
1087 {
1088  m_phyTxDropTrace (burst);
1089 }
1090 
1091 void
1093 {
1094  m_phyRxBeginTrace (burst);
1095 }
1096 
1097 void
1099 {
1100  m_phyRxEndTrace (burst);
1101 }
1102 
1103 void
1105 {
1106  m_phyRxDropTrace (burst);
1107 }
1108 
1109 int64_t
1111 {
1112  NS_LOG_FUNCTION (this << stream);
1113  m_URNG->SetStream (stream);
1114  return 1;
1115 }
1116 
1117 } // namespace ns3
void SetNoiseFigure(double nf)
set the noise figure of the device
double GetRxGain(void) const
Get receive gain.
WimaxPhy::PhyType GetPhyType(void) const
returns the type this physical layer
Ptr< const AttributeChecker > MakeStringChecker(void)
Definition: string.cc:30
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
uint16_t m_blockSize
block size
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 the RngStream.
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.
Callback< void, Ptr< const PacketBurst > > GetReceiveCallback(void) const
Definition: wimax-phy.cc:155
uint32_t m_paddingBits
padding bits
uint32_t GetFecBlockSize(WimaxPhy::ModulationType type) const
Get FEC block size.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
void EndReceiveFecBlock(uint32_t burstSize, WimaxPhy::ModulationType modulationType, uint8_t direction, uint8_t drop, Ptr< PacketBurst > burst)
End receive FEC block.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
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.
void NotifyRxDrop(Ptr< PacketBurst > burst)
Public method used to fire a PhyRxDrop trace.
virtual void DoDispose(void)
Destructor implementation.
Definition: wimax-phy.cc:99
void NotifyRxBegin(Ptr< PacketBurst > burst)
Public method used to fire a PhyRxBegin trace.
Ptr< PacketBurst > GetBurst() const
Definition: send-params.h:82
TracedCallback< Ptr< const PacketBurst > > m_traceRx
trace receive callback
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
uint32_t m_dataRateQam64_23
data rate
SimpleOfdmWimaxPhy class.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
SimpleOfdmWimaxChannel class.
uint16_t GetNrBlocks(uint32_t burstSize, WimaxPhy::ModulationType modulationType) const
Get number of blocks.
void InitSimpleOfdmWimaxPhy(void)
Initialize simple OFDM WIMAX Phy.
uint16_t DoGetNfft(void) const
Get NFFT.
EventId GetChnlSrchTimeoutEvent(void) const
Get channel search timeout event.
Definition: wimax-phy.cc:210
#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:564
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
std::list< bvec > * m_receivedFecBlocks
a list of received FEC blocks until they are combined to recreate the full burst buffer ...
double GetTxGain(void) const
Get transmit gain.
SNRToBlockErrorRateManager * m_snrToBlockErrorRateManager
SNR to block error rate manager.
void SetSimplex(uint64_t frequency)
configure the physical layer in simplex mode
Definition: wimax-phy.cc:168
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:278
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
uint16_t m_fecBlockSize
in bits, size of FEC block transmitted after PHY operations
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event&#39;s associated function will not be invoked when it expires...
Definition: simulator.cc:346
uint32_t CalculateDataRate(WimaxPhy::ModulationType modulationType) const
Calculate data rate.
void NotifyTxBegin(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxBegin trace.
void EndSend(void)
End send.
void SetScanningCallback(void) const
calls the scanning call back function
Definition: wimax-phy.cc:216
Time DoGetTransmissionTime(uint32_t size, WimaxPhy::ModulationType modulationType) const
Get transmission time.
void SetTraceFilePath(std::string path)
Set trace file path.
void SetSymbolsPerFrame(uint32_t symbolsPerFrame)
set the number of symbols per frame
Definition: wimax-phy.cc:410
TracedCallback< Ptr< PacketBurst > > m_phyTxDropTrace
The trace source fired when the phy layer drops a packet as it tries to transmit it.
uint32_t GetBandwidth(void) const
void SetPsDuration(Time psDuration)
set the physical slot duration
Definition: wimax-phy.cc:356
void DoSetNfft(uint16_t nfft)
Set NFFT.
void SetBandwidth(uint32_t BW)
Set the bandwidth.
uint64_t GetTxFrequency(void) const
Get the transmission frequency.
Definition: wimax-phy.cc:181
channel
Definition: third.py:85
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
bvec RecreateBuffer()
Recreate buffer.
uint16_t DoGetRtg(void) const
Get RTG.
This class represents a record (handled by SnrToBlockErrorRate manager) that keeps a mapping between ...
void CreateFecBlocks(const bvec &buffer, WimaxPhy::ModulationType modulationType)
Create FEC blocks.
void EndSendFecBlock(WimaxPhy::ModulationType modulationType, uint8_t direction)
End send FEC block.
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 m_noiseFigure
noise figure
bvec ConvertBurstToBits(Ptr< const PacketBurst > burst)
Convert burst to bits.
void DoSetDataRates(void)
Set data rates.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
uint16_t m_nrRecivedFecBlocks
number received FEC blocks
uint32_t m_nrFecBlocksSent
counting the number of FEC blocks sent (within a burst)
The SendParams class defines the parameters with which Send() function of a particular PHY is called...
Definition: send-params.h:43
void GetModulationFecParams(WimaxPhy::ModulationType modulationType, uint8_t &bitsPerSymbol, double &fecCode) const
Get moduleation FEC parameters.
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1038
Hold an unsigned integer type.
Definition: uinteger.h:44
OfdmSendParams class.
Definition: send-params.h:67
double GetNoiseFigure(void) const
uint32_t m_dataRateQpsk12
data rate
void EndReceive(Ptr< const PacketBurst > burst)
End receive.
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:386
bool IsDuplex(void) const
Check if configured in duplex mode.
Definition: wimax-phy.cc:204
Ptr< WimaxChannel > GetChannel(void) const
Definition: wimax-phy.cc:113
void DoSetGValue(double g)
Set G value.
void SetTraceFilePath(char *traceFilePath)
Set the path of the repository containing the traces.
uint8_t DoGetFrameDurationCode(void) const
Get frame duration code.
#define list
void SetRxGain(double rxgain)
Set receive gsain.
Time DoGetFrameDuration(uint8_t frameDurationCode) const
Get frame duration.
uint32_t m_dataRateQpsk34
data rate
Ptr< PacketBurst > m_currentBurst
current burst
void LoadTraces(void)
Loads the traces form the repository specified in the constructor or set by SetTraceFilePath function...
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.
uint64_t DoGetNrBytes(uint32_t symbols, WimaxPhy::ModulationType modulationType) const
Get number of bytes.
void StartSendDummyFecBlock(bool isFirstBlock, WimaxPhy::ModulationType modulationType, uint8_t direction)
Start end dummy FEC block.
uint64_t GetScanningFrequency(void) const
Get the scanning frequency.
Definition: wimax-phy.cc:187
std::string GetTraceFilePath(void) const
Get trace file path.
static TypeId GetTypeId(void)
Get the type ID.
void SetChannelBandwidth(uint32_t channelBandwidth)
Set the channel bandwidth.
Definition: wimax-phy.cc:326
Time GetFrameDuration(void) const
Get the frame duration.
Definition: wimax-phy.cc:302
double DoGetSamplingFrequency(void) const
Get sampling frequency.
void DoDispose(void)
Destructor implementation.
uint32_t m_currentBurstSize
current burst size
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
uint32_t DoGetDataRate(WimaxPhy::ModulationType modulationType) const
Get data rate.
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
Time GetSymbolDuration(void) const
Get the OFDM symbol duration.
Definition: wimax-phy.cc:374
uint8_t GetDirection() const
Definition: send-params.h:98
void SetTxGain(double txgain)
Set transmit gain.
void NotifyTxEnd(Ptr< PacketBurst > burst)
Public method used to fire a PhyTxEnd trace.
uint32_t m_dataRateQam64_34
data rate
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.
void SetTxPower(double txPower)
set the transmission power
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:49
TracedCallback< Ptr< PacketBurst > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium. ...
uint32_t GetChannelBandwidth(void) const
Get the channel bandwidth.
Definition: wimax-phy.cc:332
void SetSymbolDuration(Time symbolDuration)
set the OFDM symbol duration
Definition: wimax-phy.cc:368
double m_txPower
transmit power
uint16_t GetPsPerSymbol(void) const
Get the number of physical slots per symbol.
Definition: wimax-phy.cc:392
uint32_t m_dataRateBpsk12
data rate
PhyType
PhyType enumeration.
Definition: wimax-phy.h:70
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
std::vector< bool > bvec
boolean vector typedef
Definition: bvec.h:29
uint16_t m_nbErroneousBlock
erroneous blocks
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Ptr< PacketBurst > ConvertBitsToBurst(bvec buffer)
Convert bits to burst.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
uint16_t m_nrBlocks
number of blocks
uint32_t GetCodedFecBlockSize(WimaxPhy::ModulationType modulationType) const
Get coded FEC block size.
uint64_t DoGetNrSymbols(uint32_t size, WimaxPhy::ModulationType modulationType) const
Get number of symbols.
Time GetBlockTransmissionTime(WimaxPhy::ModulationType modulationType) const
Get block transmission time.
void SetState(PhyState state)
set the state of the device
Definition: wimax-phy.cc:193
uint32_t m_dataRateQam16_34
data rate
void SetBlockParameters(uint32_t burstSize, WimaxPhy::ModulationType modulationType)
Set block parameters.
uint64_t GetRxFrequency(void) const
Get the reception frequency.
Definition: wimax-phy.cc:175
void SetNrCarriers(uint8_t nrCarriers)
Set the number of carriers in the physical frame.
Definition: wimax-phy.cc:284
double DoGetGValue(void) const
Get G value.
uint16_t DoGetTtg(void) const
Get TTG.
static const uint32_t packetSize
This class handles the SNR to BlcER traces.
void DoSetPhyParameters(void)
Set Phy parameters.
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
uint32_t m_dataRateQam16_12
data rate
void SetPsPerFrame(uint16_t psPerFrame)
set the number of physical slots per frame
Definition: wimax-phy.cc:398
PhyState GetState(void) const
Get the state of the device.
Definition: wimax-phy.cc:198
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
uint16_t m_nrRemainingBlocksToSend
number of remaining blocks to send
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
uint8_t GetModulationType() const
Definition: send-params.h:90
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
double m_rxGain
receive gain
uint8_t GetNrCarriers(void) const
Get the number of carriers in the physical frame.
Definition: wimax-phy.cc:290
double m_txGain
transmit gain
double DoGetSamplingFactor(void) const
Get sampling factor.
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
trace transmit callback
std::list< bvec > * m_fecBlocks
the FEC blocks