LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2007,2008, 2009 INRIA, UDcast | 3 * Copyright (c) 2007,2008, 2009 INRIA, UDcast |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 WimaxPhy::ModulationType modulationType, | 355 WimaxPhy::ModulationType modulationType, |
356 uint8_t direction, | 356 uint8_t direction, |
357 double rxPower, | 357 double rxPower, |
358 Ptr<PacketBurst> burst) | 358 Ptr<PacketBurst> burst) |
359 { | 359 { |
360 | 360 |
361 uint8_t drop = 0; | 361 uint8_t drop = 0; |
362 double Nwb = -114 + m_noiseFigure + 10 * std::log (GetBandwidth () / 100000000
0.0) / 2.303; | 362 double Nwb = -114 + m_noiseFigure + 10 * std::log (GetBandwidth () / 100000000
0.0) / 2.303; |
363 double SNR = rxPower - Nwb; | 363 double SNR = rxPower - Nwb; |
364 | 364 |
365 SNRToBlockErrorRateRecord * record = m_snrToBlockErrorRateManager->GetSNRToBlo
ckErrorRateRecord (SNR, static_cast<uint8_t>(modulationType)); | 365 SNRToBlockErrorRateRecord * record = m_snrToBlockErrorRateManager->GetSNRToBlo
ckErrorRateRecord (SNR, static_cast<uint8_t> (modulationType)); |
366 double I1 = record->GetI1 (); | 366 double I1 = record->GetI1 (); |
367 double I2 = record->GetI2 (); | 367 double I2 = record->GetI2 (); |
368 | 368 |
369 double blockErrorRate = m_URNG->GetValue (I1, I2); | 369 double blockErrorRate = m_URNG->GetValue (I1, I2); |
370 | 370 |
371 double rand = m_URNG->GetValue (0.0, 1.0); | 371 double rand = m_URNG->GetValue (0.0, 1.0); |
372 | 372 |
373 if (rand < blockErrorRate) | 373 if (rand < blockErrorRate) |
374 { | 374 { |
375 drop = 1; | 375 drop = 1; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 439 } |
440 } | 440 } |
441 | 441 |
442 void | 442 void |
443 SimpleOfdmWimaxPhy::EndReceiveFecBlock (uint32_t burstSize, | 443 SimpleOfdmWimaxPhy::EndReceiveFecBlock (uint32_t burstSize, |
444 WimaxPhy::ModulationType modulationType, | 444 WimaxPhy::ModulationType modulationType, |
445 uint8_t direction, | 445 uint8_t direction, |
446 uint8_t drop, | 446 uint8_t drop, |
447 Ptr<PacketBurst> burst) | 447 Ptr<PacketBurst> burst) |
448 { | 448 { |
449 NS_UNUSED(modulationType); | 449 NS_UNUSED (modulationType); |
450 NS_UNUSED(direction); | 450 NS_UNUSED (direction); |
451 SetState (PHY_STATE_IDLE); | 451 SetState (PHY_STATE_IDLE); |
452 m_nrRecivedFecBlocks++; | 452 m_nrRecivedFecBlocks++; |
453 | 453 |
454 if (drop != 0) | 454 if (drop != 0) |
455 { | 455 { |
456 m_nbErroneousBlock++; | 456 m_nbErroneousBlock++; |
457 } | 457 } |
458 | 458 |
459 if ((uint32_t) m_nrRecivedFecBlocks * m_blockSize == burstSize * 8 + m_padding
Bits) | 459 if ((uint32_t) m_nrRecivedFecBlocks * m_blockSize == burstSize * 8 + m_padding
Bits) |
460 { | 460 { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 temp = 0; | 537 temp = 0; |
538 for (int l = 0; l < 8; l++) | 538 for (int l = 0; l < 8; l++) |
539 { | 539 { |
540 bool bin = buffer.at (i + l); | 540 bool bin = buffer.at (i + l); |
541 temp += (uint8_t)(bin * std::pow (2.0, (7 - l))); | 541 temp += (uint8_t)(bin * std::pow (2.0, (7 - l))); |
542 } | 542 } |
543 | 543 |
544 *(pstart + j) = temp; | 544 *(pstart + j) = temp; |
545 j++; | 545 j++; |
546 } | 546 } |
547 uint16_t bufferSize = static_cast<uint16_t>(buffer.size () / 8); | 547 uint16_t bufferSize = static_cast<uint16_t> (buffer.size () / 8); |
548 uint16_t pos = 0; | 548 uint16_t pos = 0; |
549 Ptr<PacketBurst> RecvBurst = Create<PacketBurst> (); | 549 Ptr<PacketBurst> RecvBurst = Create<PacketBurst> (); |
550 while (pos < bufferSize) | 550 while (pos < bufferSize) |
551 { | 551 { |
552 uint16_t packetSize = 0; | 552 uint16_t packetSize = 0; |
553 // Get the header type: first bit | 553 // Get the header type: first bit |
554 uint8_t ht = (pstart[pos] >> 7) & 0x01; | 554 uint8_t ht = (pstart[pos] >> 7) & 0x01; |
555 if (ht == 1) | 555 if (ht == 1) |
556 { | 556 { |
557 // BW request header. Size is always 8 bytes | 557 // BW request header. Size is always 8 bytes |
(...skipping 13 matching lines...) Expand all Loading... |
571 Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize); | 571 Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize); |
572 RecvBurst->AddPacket (p); | 572 RecvBurst->AddPacket (p); |
573 pos += packetSize; | 573 pos += packetSize; |
574 } | 574 } |
575 return RecvBurst; | 575 return RecvBurst; |
576 } | 576 } |
577 | 577 |
578 void | 578 void |
579 SimpleOfdmWimaxPhy::CreateFecBlocks (const bvec &buffer, WimaxPhy::ModulationTyp
e modulationType) | 579 SimpleOfdmWimaxPhy::CreateFecBlocks (const bvec &buffer, WimaxPhy::ModulationTyp
e modulationType) |
580 { | 580 { |
581 NS_UNUSED(modulationType); | 581 NS_UNUSED (modulationType); |
582 bvec fecBlock (m_blockSize); | 582 bvec fecBlock (m_blockSize); |
583 for (uint32_t i = 0, j = m_nrBlocks; j > 0; i += m_blockSize, j--) | 583 for (uint32_t i = 0, j = m_nrBlocks; j > 0; i += m_blockSize, j--) |
584 { | 584 { |
585 | 585 |
586 if (j == 1 && m_paddingBits > 0) // last block can be smaller than block s
ize | 586 if (j == 1 && m_paddingBits > 0) // last block can be smaller than block s
ize |
587 { | 587 { |
588 fecBlock = bvec (buffer.begin () + i, buffer.end ()); | 588 fecBlock = bvec (buffer.begin () + i, buffer.end ()); |
589 fecBlock.resize (m_blockSize, 0); | 589 fecBlock.resize (m_blockSize, 0); |
590 } | 590 } |
591 else | 591 else |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 default: | 803 default: |
804 NS_FATAL_ERROR ("Invalid modulation type"); | 804 NS_FATAL_ERROR ("Invalid modulation type"); |
805 break; | 805 break; |
806 } | 806 } |
807 return blockSize * 8; // in bits | 807 return blockSize * 8; // in bits |
808 } | 808 } |
809 | 809 |
810 void | 810 void |
811 SimpleOfdmWimaxPhy::SetBlockParameters (uint32_t burstSize, WimaxPhy::Modulation
Type modulationType) | 811 SimpleOfdmWimaxPhy::SetBlockParameters (uint32_t burstSize, WimaxPhy::Modulation
Type modulationType) |
812 { | 812 { |
813 m_blockSize = static_cast<uint16_t>(GetFecBlockSize (modulationType)); | 813 m_blockSize = static_cast<uint16_t> (GetFecBlockSize (modulationType)); |
814 m_nrBlocks = GetNrBlocks (burstSize, modulationType); | 814 m_nrBlocks = GetNrBlocks (burstSize, modulationType); |
815 m_paddingBits = (m_nrBlocks * m_blockSize) - (burstSize * 8); | 815 m_paddingBits = (m_nrBlocks * m_blockSize) - (burstSize * 8); |
816 m_nrRemainingBlocksToSend = m_nrBlocks; | 816 m_nrRemainingBlocksToSend = m_nrBlocks; |
817 NS_ASSERT_MSG (static_cast<uint32_t> (m_nrBlocks * m_blockSize) >= (burstSize
* 8), "Size of padding bytes < 0"); | 817 NS_ASSERT_MSG (static_cast<uint32_t> (m_nrBlocks * m_blockSize) >= (burstSize
* 8), "Size of padding bytes < 0"); |
818 } | 818 } |
819 | 819 |
820 uint16_t | 820 uint16_t |
821 SimpleOfdmWimaxPhy::DoGetTtg (void) const | 821 SimpleOfdmWimaxPhy::DoGetTtg (void) const |
822 { | 822 { |
823 // assumed equal to 2 symbols | 823 // assumed equal to 2 symbols |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 } | 916 } |
917 | 917 |
918 /* | 918 /* |
919 Retruns number of blocks (FEC blocks) the burst will be splitted in. | 919 Retruns number of blocks (FEC blocks) the burst will be splitted in. |
920 The size of the block is specific for each modulation type. | 920 The size of the block is specific for each modulation type. |
921 */ | 921 */ |
922 uint16_t | 922 uint16_t |
923 SimpleOfdmWimaxPhy::GetNrBlocks (uint32_t burstSize, WimaxPhy::ModulationType mo
dulationType) const | 923 SimpleOfdmWimaxPhy::GetNrBlocks (uint32_t burstSize, WimaxPhy::ModulationType mo
dulationType) const |
924 { | 924 { |
925 uint32_t blockSize = GetFecBlockSize (modulationType); | 925 uint32_t blockSize = GetFecBlockSize (modulationType); |
926 uint16_t nrBlocks = static_cast<uint16_t>((burstSize * 8) / blockSize); | 926 uint16_t nrBlocks = static_cast<uint16_t> ((burstSize * 8) / blockSize); |
927 | 927 |
928 if ((burstSize * 8) % blockSize > 0) | 928 if ((burstSize * 8) % blockSize > 0) |
929 { | 929 { |
930 nrBlocks += 1; | 930 nrBlocks += 1; |
931 } | 931 } |
932 | 932 |
933 return nrBlocks; | 933 return nrBlocks; |
934 } | 934 } |
935 /*---------------------PHY parameters functions-----------------------*/ | 935 /*---------------------PHY parameters functions-----------------------*/ |
936 | 936 |
(...skipping 12 matching lines...) Expand all Loading... |
949 Time psDuration = Seconds ((double) 4 / samplingFrequency); | 949 Time psDuration = Seconds ((double) 4 / samplingFrequency); |
950 | 950 |
951 SetPsDuration (psDuration); | 951 SetPsDuration (psDuration); |
952 uint16_t psPerFrame = (uint16_t)(GetFrameDuration ().GetSeconds () / psDuratio
n.GetSeconds ()); | 952 uint16_t psPerFrame = (uint16_t)(GetFrameDuration ().GetSeconds () / psDuratio
n.GetSeconds ()); |
953 SetPsPerFrame (psPerFrame); | 953 SetPsPerFrame (psPerFrame); |
954 double subcarrierSpacing = samplingFrequency / DoGetNfft (); | 954 double subcarrierSpacing = samplingFrequency / DoGetNfft (); |
955 double tb = (double) 1 / subcarrierSpacing; // Tb (useful symbol time) | 955 double tb = (double) 1 / subcarrierSpacing; // Tb (useful symbol time) |
956 double tg = DoGetGValue () * tb; // Tg (cyclic prefix time) | 956 double tg = DoGetGValue () * tb; // Tg (cyclic prefix time) |
957 Time symbolDuration = Seconds (tb + tg); // OFDM Symbol Time | 957 Time symbolDuration = Seconds (tb + tg); // OFDM Symbol Time |
958 SetSymbolDuration (symbolDuration); | 958 SetSymbolDuration (symbolDuration); |
959 uint16_t psPerSymbol = static_cast<uint16_t>(lrint (symbolDuration.GetSeconds
() / psDuration.GetSeconds ())); | 959 uint16_t psPerSymbol = static_cast<uint16_t> (lrint (symbolDuration.GetSeconds
() / psDuration.GetSeconds ())); |
960 SetPsPerSymbol (psPerSymbol); | 960 SetPsPerSymbol (psPerSymbol); |
961 uint32_t symbolsPerFrame = lrint (GetFrameDuration ().GetSeconds () / symbolDu
ration.GetSeconds ()); | 961 uint32_t symbolsPerFrame = lrint (GetFrameDuration ().GetSeconds () / symbolDu
ration.GetSeconds ()); |
962 SetSymbolsPerFrame (symbolsPerFrame); | 962 SetSymbolsPerFrame (symbolsPerFrame); |
963 } | 963 } |
964 | 964 |
965 void | 965 void |
966 SimpleOfdmWimaxPhy::DoSetNfft (uint16_t nfft) | 966 SimpleOfdmWimaxPhy::DoSetNfft (uint16_t nfft) |
967 { | 967 { |
968 m_nfft = nfft; | 968 m_nfft = nfft; |
969 | 969 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 | 1110 |
1111 int64_t | 1111 int64_t |
1112 SimpleOfdmWimaxPhy::AssignStreams (int64_t stream) | 1112 SimpleOfdmWimaxPhy::AssignStreams (int64_t stream) |
1113 { | 1113 { |
1114 NS_LOG_FUNCTION (this << stream); | 1114 NS_LOG_FUNCTION (this << stream); |
1115 m_URNG->SetStream (stream); | 1115 m_URNG->SetStream (stream); |
1116 return 1; | 1116 return 1; |
1117 } | 1117 } |
1118 | 1118 |
1119 } // namespace ns3 | 1119 } // namespace ns3 |
LEFT | RIGHT |