OLD | NEW |
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, 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); |
| 450 NS_UNUSED (direction); |
449 SetState (PHY_STATE_IDLE); | 451 SetState (PHY_STATE_IDLE); |
450 m_nrRecivedFecBlocks++; | 452 m_nrRecivedFecBlocks++; |
451 | 453 |
452 if (drop == true) | 454 if (drop != 0) |
453 { | 455 { |
454 m_nbErroneousBlock++; | 456 m_nbErroneousBlock++; |
455 } | 457 } |
456 | 458 |
457 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) |
458 { | 460 { |
459 NotifyRxEnd (burst); | 461 NotifyRxEnd (burst); |
460 if (m_nbErroneousBlock == 0) | 462 if (m_nbErroneousBlock == 0) |
461 { | 463 { |
462 Simulator::Schedule (Seconds (0), | 464 Simulator::Schedule (Seconds (0), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 Converts back the bit buffer (bvec) to the actual burst. | 519 Converts back the bit buffer (bvec) to the actual burst. |
518 Actually creates byte buffer from the bvec and resets the buffer | 520 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. | 521 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. | 522 By doing this it preserves the metadata and tags in the packet. |
521 Function could also be named DeserializeBurst because actually it | 523 Function could also be named DeserializeBurst because actually it |
522 copying to the burst's byte buffer. | 524 copying to the burst's byte buffer. |
523 */ | 525 */ |
524 Ptr<PacketBurst> | 526 Ptr<PacketBurst> |
525 SimpleOfdmWimaxPhy::ConvertBitsToBurst (bvec buffer) | 527 SimpleOfdmWimaxPhy::ConvertBitsToBurst (bvec buffer) |
526 { | 528 { |
527 uint8_t init[buffer.size () / 8]; | 529 uint8_t* init = new uint8_t[(uint16_t)buffer.size () / 8]; |
528 uint8_t *pstart = init; | 530 uint8_t *pstart = init; |
529 uint8_t temp; | 531 uint8_t temp; |
530 int32_t j = 0; | 532 int32_t j = 0; |
531 // recreating byte buffer from bit buffer (bvec) | 533 // recreating byte buffer from bit buffer (bvec) |
532 for (uint32_t i = 0; i < buffer.size (); i += 8) | 534 for (uint32_t i = 0; i < buffer.size (); i += 8) |
533 { | 535 { |
534 | 536 |
535 temp = 0; | 537 temp = 0; |
536 for (int l = 0; l < 8; l++) | 538 for (int l = 0; l < 8; l++) |
537 { | 539 { |
538 bool bin = buffer.at (i + l); | 540 bool bin = buffer.at (i + l); |
539 temp += (uint8_t)(bin * std::pow (2.0, (7 - l))); | 541 temp += (uint8_t)(bin * std::pow (2.0, (7 - l))); |
540 } | 542 } |
541 | 543 |
542 *(pstart + j) = temp; | 544 *(pstart + j) = temp; |
543 j++; | 545 j++; |
544 } | 546 } |
545 uint16_t bufferSize = buffer.size () / 8; | 547 uint16_t bufferSize = static_cast<uint16_t> (buffer.size () / 8); |
546 uint16_t pos = 0; | 548 uint16_t pos = 0; |
547 Ptr<PacketBurst> RecvBurst = Create<PacketBurst> (); | 549 Ptr<PacketBurst> RecvBurst = Create<PacketBurst> (); |
548 while (pos < bufferSize) | 550 while (pos < bufferSize) |
549 { | 551 { |
550 uint16_t packetSize = 0; | 552 uint16_t packetSize = 0; |
551 // Get the header type: first bit | 553 // Get the header type: first bit |
552 uint8_t ht = (pstart[pos] >> 7) & 0x01; | 554 uint8_t ht = (pstart[pos] >> 7) & 0x01; |
553 if (ht == 1) | 555 if (ht == 1) |
554 { | 556 { |
555 // BW request header. Size is always 8 bytes | 557 // BW request header. Size is always 8 bytes |
(...skipping 13 matching lines...) Expand all Loading... |
569 Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize); | 571 Ptr<Packet> p = Create<Packet> (&(pstart[pos]), packetSize); |
570 RecvBurst->AddPacket (p); | 572 RecvBurst->AddPacket (p); |
571 pos += packetSize; | 573 pos += packetSize; |
572 } | 574 } |
573 return RecvBurst; | 575 return RecvBurst; |
574 } | 576 } |
575 | 577 |
576 void | 578 void |
577 SimpleOfdmWimaxPhy::CreateFecBlocks (const bvec &buffer, WimaxPhy::ModulationTyp
e modulationType) | 579 SimpleOfdmWimaxPhy::CreateFecBlocks (const bvec &buffer, WimaxPhy::ModulationTyp
e modulationType) |
578 { | 580 { |
579 | 581 NS_UNUSED (modulationType); |
580 bvec fecBlock (m_blockSize); | 582 bvec fecBlock (m_blockSize); |
581 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--) |
582 { | 584 { |
583 | 585 |
584 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 |
585 { | 587 { |
586 fecBlock = bvec (buffer.begin () + i, buffer.end ()); | 588 fecBlock = bvec (buffer.begin () + i, buffer.end ()); |
587 fecBlock.resize (m_blockSize, 0); | 589 fecBlock.resize (m_blockSize, 0); |
588 } | 590 } |
589 else | 591 else |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 default: | 803 default: |
802 NS_FATAL_ERROR ("Invalid modulation type"); | 804 NS_FATAL_ERROR ("Invalid modulation type"); |
803 break; | 805 break; |
804 } | 806 } |
805 return blockSize * 8; // in bits | 807 return blockSize * 8; // in bits |
806 } | 808 } |
807 | 809 |
808 void | 810 void |
809 SimpleOfdmWimaxPhy::SetBlockParameters (uint32_t burstSize, WimaxPhy::Modulation
Type modulationType) | 811 SimpleOfdmWimaxPhy::SetBlockParameters (uint32_t burstSize, WimaxPhy::Modulation
Type modulationType) |
810 { | 812 { |
811 m_blockSize = GetFecBlockSize (modulationType); | 813 m_blockSize = static_cast<uint16_t> (GetFecBlockSize (modulationType)); |
812 m_nrBlocks = GetNrBlocks (burstSize, modulationType); | 814 m_nrBlocks = GetNrBlocks (burstSize, modulationType); |
813 m_paddingBits = (m_nrBlocks * m_blockSize) - (burstSize * 8); | 815 m_paddingBits = (m_nrBlocks * m_blockSize) - (burstSize * 8); |
814 m_nrRemainingBlocksToSend = m_nrBlocks; | 816 m_nrRemainingBlocksToSend = m_nrBlocks; |
815 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"); |
816 } | 818 } |
817 | 819 |
818 uint16_t | 820 uint16_t |
819 SimpleOfdmWimaxPhy::DoGetTtg (void) const | 821 SimpleOfdmWimaxPhy::DoGetTtg (void) const |
820 { | 822 { |
821 // assumed equal to 2 symbols | 823 // assumed equal to 2 symbols |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 } | 916 } |
915 | 917 |
916 /* | 918 /* |
917 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. |
918 The size of the block is specific for each modulation type. | 920 The size of the block is specific for each modulation type. |
919 */ | 921 */ |
920 uint16_t | 922 uint16_t |
921 SimpleOfdmWimaxPhy::GetNrBlocks (uint32_t burstSize, WimaxPhy::ModulationType mo
dulationType) const | 923 SimpleOfdmWimaxPhy::GetNrBlocks (uint32_t burstSize, WimaxPhy::ModulationType mo
dulationType) const |
922 { | 924 { |
923 uint32_t blockSize = GetFecBlockSize (modulationType); | 925 uint32_t blockSize = GetFecBlockSize (modulationType); |
924 uint16_t nrBlocks = (burstSize * 8) / blockSize; | 926 uint16_t nrBlocks = static_cast<uint16_t> ((burstSize * 8) / blockSize); |
925 | 927 |
926 if ((burstSize * 8) % blockSize > 0) | 928 if ((burstSize * 8) % blockSize > 0) |
927 { | 929 { |
928 nrBlocks += 1; | 930 nrBlocks += 1; |
929 } | 931 } |
930 | 932 |
931 return nrBlocks; | 933 return nrBlocks; |
932 } | 934 } |
933 /*---------------------PHY parameters functions-----------------------*/ | 935 /*---------------------PHY parameters functions-----------------------*/ |
934 | 936 |
(...skipping 12 matching lines...) Expand all Loading... |
947 Time psDuration = Seconds ((double) 4 / samplingFrequency); | 949 Time psDuration = Seconds ((double) 4 / samplingFrequency); |
948 | 950 |
949 SetPsDuration (psDuration); | 951 SetPsDuration (psDuration); |
950 uint16_t psPerFrame = (uint16_t)(GetFrameDuration ().GetSeconds () / psDuratio
n.GetSeconds ()); | 952 uint16_t psPerFrame = (uint16_t)(GetFrameDuration ().GetSeconds () / psDuratio
n.GetSeconds ()); |
951 SetPsPerFrame (psPerFrame); | 953 SetPsPerFrame (psPerFrame); |
952 double subcarrierSpacing = samplingFrequency / DoGetNfft (); | 954 double subcarrierSpacing = samplingFrequency / DoGetNfft (); |
953 double tb = (double) 1 / subcarrierSpacing; // Tb (useful symbol time) | 955 double tb = (double) 1 / subcarrierSpacing; // Tb (useful symbol time) |
954 double tg = DoGetGValue () * tb; // Tg (cyclic prefix time) | 956 double tg = DoGetGValue () * tb; // Tg (cyclic prefix time) |
955 Time symbolDuration = Seconds (tb + tg); // OFDM Symbol Time | 957 Time symbolDuration = Seconds (tb + tg); // OFDM Symbol Time |
956 SetSymbolDuration (symbolDuration); | 958 SetSymbolDuration (symbolDuration); |
957 uint16_t psPerSymbol = lrint (symbolDuration.GetSeconds () / psDuration.GetSec
onds ()); | 959 uint16_t psPerSymbol = static_cast<uint16_t> (lrint (symbolDuration.GetSeconds
() / psDuration.GetSeconds ())); |
958 SetPsPerSymbol (psPerSymbol); | 960 SetPsPerSymbol (psPerSymbol); |
959 uint32_t symbolsPerFrame = lrint (GetFrameDuration ().GetSeconds () / symbolDu
ration.GetSeconds ()); | 961 uint32_t symbolsPerFrame = lrint (GetFrameDuration ().GetSeconds () / symbolDu
ration.GetSeconds ()); |
960 SetSymbolsPerFrame (symbolsPerFrame); | 962 SetSymbolsPerFrame (symbolsPerFrame); |
961 } | 963 } |
962 | 964 |
963 void | 965 void |
964 SimpleOfdmWimaxPhy::DoSetNfft (uint16_t nfft) | 966 SimpleOfdmWimaxPhy::DoSetNfft (uint16_t nfft) |
965 { | 967 { |
966 m_nfft = nfft; | 968 m_nfft = nfft; |
967 | 969 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 | 1110 |
1109 int64_t | 1111 int64_t |
1110 SimpleOfdmWimaxPhy::AssignStreams (int64_t stream) | 1112 SimpleOfdmWimaxPhy::AssignStreams (int64_t stream) |
1111 { | 1113 { |
1112 NS_LOG_FUNCTION (this << stream); | 1114 NS_LOG_FUNCTION (this << stream); |
1113 m_URNG->SetStream (stream); | 1115 m_URNG->SetStream (stream); |
1114 return 1; | 1116 return 1; |
1115 } | 1117 } |
1116 | 1118 |
1117 } // namespace ns3 | 1119 } // namespace ns3 |
OLD | NEW |