29 #include "../model/satellite-superframe-allocator.h"
30 #include "../model/satellite-utils.h"
31 #include "../utils/satellite-env-variables.h"
33 #include "ns3/boolean.h"
34 #include "ns3/config.h"
36 #include "ns3/simulator.h"
37 #include "ns3/singleton.h"
39 #include "ns3/uinteger.h"
77 typedef std::map<Address, std::pair<SatFrameAllocator::SatFrameAllocReq, uint32_t>>
ReqInfo_t;
79 static const uint32_t m_ccLevelCount = 4;
80 static const uint32_t m_cnoValueCount = 10;
83 double m_cnoValues[m_cnoValueCount];
89 virtual void DoRun(
void);
95 void RunMultiUtTest();
99 uint32_t minRbdcBytes,
105 void CheckSingleUtTestResults(uint32_t bytesReq,
111 bool rcBasedAllocation,
120 : TestCase(
"Test satellite frame allocator, configuration 0.")
122 m_ccLevels[0] = SatFrameAllocator::CC_LEVEL_CRA;
123 m_ccLevels[1] = SatFrameAllocator::CC_LEVEL_CRA_MIN_RBDC;
124 m_ccLevels[2] = SatFrameAllocator::CC_LEVEL_CRA_RBDC;
125 m_ccLevels[3] = SatFrameAllocator::CC_LEVEL_CRA_RBDC_VBDC;
132 m_cnoValues[3] = std::numeric_limits<double>::quiet_NaN();
137 m_cnoValues[8] = std::numeric_limits<double>::quiet_NaN();
140 std::string dataPath = Singleton<SatEnvVariables>::Get()->GetDataPath();
141 std::string folderNameWithPath = dataPath +
"/scenarios/geo-33E/waveforms";
142 m_waveFormConf = CreateObject<SatWaveformConf>(folderNameWithPath);
153 Ptr<SatBtuConf> btu = Create<SatBtuConf>(10e4, 0.4, 0.1, 1);
155 bool defaultWaveformInUse =
false;
156 bool checkSlotLimit =
true;
158 if (configType == SatSuperframeConf::CONFIG_TYPE_0)
160 defaultWaveformInUse =
true;
163 if (configType == SatSuperframeConf::CONFIG_TYPE_2)
165 checkSlotLimit =
false;
178 m_frameConf = Create<SatFrameConf>(frameConfParameters);
187 m_waveFormConf->SetAttribute(
"AcmEnabled", BooleanValue(acmEnabled));
191 double cnoThreshold = std::numeric_limits<double>::quiet_NaN();
194 for (uint32_t i = 0; i < 11; i += 2)
196 for (uint32_t j = 0; j < 15; j += 2)
198 for (uint32_t k = 0; k < 15; k += 2)
200 for (uint32_t l = 0; l < 15; l += 2)
202 uint32_t bytesReq = 0;
217 bool allocationResult =
225 Ptr<SatTbtpMessage> tptp = CreateObject<SatTbtpMessage>();
227 tbtpContainer.push_back(tptp);
234 TracedCallback<uint32_t>(),
235 TracedCallback<uint32_t, uint32_t>(),
236 TracedCallback<uint32_t, double>());
251 tbtpContainer.clear();
252 tptp = CreateObject<SatTbtpMessage>();
253 tbtpContainer.push_back(tptp);
254 utAllocContainer.clear();
260 TracedCallback<uint32_t>(),
261 TracedCallback<uint32_t, uint32_t>(),
262 TracedCallback<uint32_t, double>());
280 for (uint32_t i = 0; i < 1000; i++)
282 for (uint32_t m = 2; m < 4; m++)
284 uint32_t bytesReq = 0;
285 uint32_t divider =
m_frameConf->GetCarrierMinPayloadInBytes() * 2;
288 std::rand() % divider,
289 std::rand() % divider,
290 std::rand() % divider,
291 std::rand() % divider,
293 (
bool)std::rand() % 2);
311 Ptr<SatTbtpMessage> tptp = CreateObject<SatTbtpMessage>();
313 tbtpContainer.push_back(tptp);
320 TracedCallback<uint32_t>(),
321 TracedCallback<uint32_t, uint32_t>(),
322 TracedCallback<uint32_t, double>());
336 tbtpContainer.clear();
337 tptp = CreateObject<SatTbtpMessage>();
338 tbtpContainer.push_back(tptp);
339 utAllocContainer.clear();
345 TracedCallback<uint32_t>(),
346 TracedCallback<uint32_t, uint32_t>(),
347 TracedCallback<uint32_t, double>());
362 Simulator::Destroy();
373 bool rcBasedAllocation,
377 uint16_t slotCount =
m_frameConf->GetTimeSlotCount();
378 uint16_t carrierCount =
m_frameConf->GetCarrierCount();
379 uint16_t slotsPerCarrier = slotCount / carrierCount;
380 uint32_t minCarrierBytes =
m_frameConf->GetCarrierMinPayloadInBytes();
382 uint32_t tbtpAllocatedBytes = 0;
383 uint32_t slotsAllocated = 0;
385 for (SatFrameAllocator::TbtpMsgContainer_t::const_iterator it = tbtpContainer.begin();
386 it != tbtpContainer.end();
391 for (SatTbtpMessage::DaTimeSlotConfContainer_t::const_iterator it2 = info.second.begin();
392 it2 != info.second.end();
395 tbtpAllocatedBytes +=
m_frameConf->GetWaveformConf()
396 ->GetWaveform((*it2)->GetWaveFormId())
397 ->GetPayloadInBytes();
400 slotsAllocated += info.second.size();
404 if (slotsAllocated > 0)
406 NS_TEST_ASSERT_MSG_EQ(utAllocContainer.at(req.
m_address).second,
408 "Control slot generation what expected!");
411 uint32_t utAllocContainerBytes = 0;
413 for (uint32_t i = 0; i < utAllocContainer.at(req.
m_address).first.size(); i++)
415 utAllocContainerBytes += utAllocContainer.at(req.
m_address).first.at(i);
420 NS_TEST_ASSERT_MSG_EQ(tbtpAllocatedBytes,
421 utAllocContainerBytes,
422 " TBTP bytes=" << tbtpAllocatedBytes
423 <<
", UT bytes=" << utAllocContainerBytes);
424 NS_ASSERT(tbtpAllocatedBytes == utAllocContainerBytes);
426 bool minBytesAllocated =
427 (utAllocContainerBytes >= std::min<uint32_t>(bytesReq, minCarrierBytes));
429 NS_TEST_ASSERT_MSG_EQ(minBytesAllocated,
true,
"Minimum bytes not allocated!");
430 NS_ASSERT(minBytesAllocated ==
true);
434 NS_TEST_ASSERT_MSG_EQ(utAllocContainer.empty(),
true,
"No allocations expected!");
435 NS_ASSERT(utAllocContainer.empty() ==
true);
438 uint32_t slotsExpected = 0;
443 std::ceil((
double)bytesReq / (
double)minCarrierBytes * (
double)slotsPerCarrier);
450 slotsExpected = std::min<uint32_t>(slotsExpected, slotsPerCarrier);
454 bool onlyCraRequested =
true;
456 for (uint32_t i = 0; i < req.
m_reqPerRc.size(); i++)
461 onlyCraRequested =
false;
465 if (((configType == SatSuperframeConf::CONFIG_TYPE_0) || (acmEnabled ==
false)) &&
466 (onlyCraRequested ==
false))
468 slotsExpected = slotsPerCarrier;
480 if ((configType == SatSuperframeConf::CONFIG_TYPE_0) && (rcBasedAllocation ==
false))
482 NS_TEST_ASSERT_MSG_EQ(slotsAllocated,
484 " slots allocated= " << slotsAllocated
485 <<
", slots expected= " << slotsExpected);
489 if (slotsExpected > 0)
491 NS_TEST_ASSERT_MSG_GT(slotsAllocated,
493 " slots allocated= " << slotsAllocated
494 <<
", at least one expected.");
498 NS_TEST_ASSERT_MSG_EQ(slotsAllocated,
500 " slots allocated= " << slotsAllocated
501 <<
", slots expected= " << slotsExpected);
512 InitFrame(SatSuperframeConf::CONFIG_TYPE_0);
514 uint32_t utBytesReq[6];
524 uint32_t waveformId[6];
525 double cnoThreshold = std::numeric_limits<double>::quiet_NaN();
527 for (uint32_t i = 0; i < 6; i++)
530 m_frameAllocator->GetBestWaveform(req[i].m_cno, waveformId[i], cnoThreshold);
533 bool allocationResult;
536 for (uint32_t n = 0; n < 5; n++)
538 for (uint32_t m = n + 1; m < 6; m++)
547 NS_TEST_ASSERT_MSG_EQ(
true, allocationResult,
"Allocation failed!");
551 NS_TEST_ASSERT_MSG_EQ(
true, allocationResult,
"Allocation failed!");
555 Ptr<SatTbtpMessage> tptp = CreateObject<SatTbtpMessage>();
557 tbtpContainer.push_back(tptp);
564 TracedCallback<uint32_t>(),
565 TracedCallback<uint32_t, uint32_t>(),
566 TracedCallback<uint32_t, double>());
570 std::make_pair(req[n].m_address, std::make_pair(req[n], utBytesReq[n])));
572 std::make_pair(req[m].m_address, std::make_pair(req[m], utBytesReq[m])));
580 for (uint32_t n = 0; n < 4; n++)
582 for (uint32_t m = n + 1; m < 5; m++)
584 for (uint32_t o = m + 2; o < 6; o++)
588 allocationResult =
m_frameAllocator->Allocate(SatFrameAllocator::CC_LEVEL_CRA,
591 NS_TEST_ASSERT_MSG_EQ(
true, allocationResult,
"Allocation failed!");
593 allocationResult =
m_frameAllocator->Allocate(SatFrameAllocator::CC_LEVEL_CRA,
596 NS_TEST_ASSERT_MSG_EQ(
true, allocationResult,
"Allocation failed!");
598 allocationResult =
m_frameAllocator->Allocate(SatFrameAllocator::CC_LEVEL_CRA,
601 NS_TEST_ASSERT_MSG_EQ(
true, allocationResult,
"Allocation failed!");
605 Ptr<SatTbtpMessage> tptp = CreateObject<SatTbtpMessage>();
607 tbtpContainer.push_back(tptp);
614 TracedCallback<uint32_t>(),
615 TracedCallback<uint32_t, uint32_t>(),
616 TracedCallback<uint32_t, double>());
620 std::make_pair(req[n].m_address, std::make_pair(req[n], utBytesReq[n])));
622 std::make_pair(req[m].m_address, std::make_pair(req[m], utBytesReq[m])));
624 std::make_pair(req[m].m_address, std::make_pair(req[o], utBytesReq[o])));
637 uint16_t carrierCount =
m_frameConf->GetCarrierCount();
638 uint32_t minCarrierBytes =
m_frameConf->GetCarrierMinPayloadInBytes();
640 for (SatFrameAllocator::UtAllocInfoContainer_t::const_iterator it = utAllocContainer.begin();
641 it != utAllocContainer.end();
644 uint32_t bytesAllocated = 0;
646 for (std::vector<uint32_t>::const_iterator it2 = it->second.first.begin();
647 it2 != it->second.first.end();
650 bytesAllocated += *it2;
654 if (utAllocContainer.size() > carrierCount)
656 NS_TEST_ASSERT_MSG_GT(bytesAllocated, 0,
"Allocation not what expected!");
658 else if (reqInfo.at(it->first).second == minCarrierBytes)
660 NS_TEST_ASSERT_MSG_EQ(minCarrierBytes, bytesAllocated,
"Allocation not what expected!");
664 NS_TEST_ASSERT_MSG_NE(minCarrierBytes, bytesAllocated,
"Allocation not what expected!");
672 uint32_t minRbdcBytes,
685 req.
m_address = Mac48Address::Allocate();
697 uint32_t craBytesReq = 0;
700 uint32_t maxCraBytes =
m_frameConf->GetCarrierMinPayloadInBytes();
701 uint32_t minCarrierBytes = maxCraBytes;
705 maxCraBytes -=
m_frameAllocator->GetMostRobustWaveform()->GetPayloadInBytes();
708 if (craBytesReq < maxCraBytes)
710 uint32_t craBytesLeft = maxCraBytes - craBytesReq;
712 std::min<uint32_t>(minCarrierBytes * craBytes / 10, craBytesLeft);
719 req.
m_reqPerRc[0].m_minRbdcBytes = minCarrierBytes * minRbdcBytes / 10;
720 req.
m_reqPerRc[0].m_rbdcBytes = minCarrierBytes * rbdcBytes / 10;
721 req.
m_reqPerRc[0].m_vbdcBytes = minCarrierBytes * vbdcBytes / 10;
734 uint32_t divider = minCarrierBytes + 1;
737 for (uint32_t i = 1; i < rcCount; i++)
739 if (craBytesReq < maxCraBytes)
741 uint32_t craBytesLeft = maxCraBytes - craBytesReq;
742 req.
m_reqPerRc[i].m_craBytes = std::min<uint32_t>(std::rand() % divider, craBytesLeft);
749 req.
m_reqPerRc[i].m_minRbdcBytes = std::rand() % divider;
750 req.
m_reqPerRc[i].m_rbdcBytes = std::rand() % divider;
751 req.
m_reqPerRc[i].m_vbdcBytes = std::rand() % divider;
771 Singleton<SatEnvVariables>::Get()->DoInitialize();
772 Singleton<SatEnvVariables>::Get()->SetOutputVariables(
"sat-frame-allocator",
"",
true);
797 Singleton<SatEnvVariables>::Get()->DoDispose();
810 : TestSuite(
"sat-frame-allocator-test", Type::UNIT)
Test case to unit test Satellite Frame Allocator.
SatFrameAllocator::SatFrameAllocReq ContructRequestForUt(uint32_t &totalBytes, uint32_t craBytes, uint32_t minRbdcBytes, uint32_t rbdcBytes, uint32_t vbdcBytes, uint32_t rcCount, bool controlSlot)
Ptr< SatFrameConf > m_frameConf
virtual ~SatFrameAllocatorTestCase()
void CheckMultiUtTestResults(SatFrameAllocator::UtAllocInfoContainer_t &utAllocContainer, ReqInfo_t &reqInfo)
static const uint32_t m_cnoValueCount
SatFrameAllocator::CcLevel_t m_ccLevels[m_ccLevelCount]
Ptr< SatWaveformConf > m_waveFormConf
std::map< Address, std::pair< SatFrameAllocator::SatFrameAllocReq, uint32_t > > ReqInfo_t
Ptr< SatFrameAllocator > m_frameAllocator
void InitFrame(SatSuperframeConf::ConfigType_t configType)
double m_cnoValues[m_cnoValueCount]
static const uint32_t m_ccLevelCount
void RunSingleUtTest(SatSuperframeConf::ConfigType_t configType, bool acmEnabled, bool fcaEnabled)
SatFrameAllocatorTestCase()
void CheckSingleUtTestResults(uint32_t bytesReq, SatFrameAllocator::SatFrameAllocReq req, bool allocated, SatSuperframeConf::ConfigType_t configType, SatFrameAllocator::TbtpMsgContainer_t &tbtpContainer, SatFrameAllocator::UtAllocInfoContainer_t &utAllocContainer, bool rcBasedAllocation, bool fcaEnabled, bool acmEnabled)
Test suite for Satellite Frame Allocator unit test cases.
SatFrameAllocatorTestSuite()
SatFrameAllocReq is used to define frame allocation parameters when requesting allocation from SatFra...
SatFrameAllocReqItemContainer_t m_reqPerRc
Allocation information item for the UT/RC requests [bytes].
std::vector< Ptr< SatTbtpMessage > > TbtpMsgContainer_t
Container to store generated TBTP messages.
CcLevel_t
Enum for CC levels.
std::map< Address, UtAllocInfoItem_t > UtAllocInfoContainer_t
Map container to store UT allocation information.
std::vector< SatFrameAllocReqItem > SatFrameAllocReqItemContainer_t
Container to store SatFrameAllocReqItem items.
ConfigType_t
Enum for configuration types.
std::pair< uint8_t, DaTimeSlotConfContainer_t > DaTimeSlotInfoItem_t
Item for DA time slot information.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatFrameAllocatorTestSuite satFrameAllocatorTestSuite
Helper struct to reduce the number of parameters fed into the SatFrameConf constructor.
Ptr< SatBtuConf > m_btuConf
uint8_t m_guardTimeSymbols
uint8_t m_allocationChannel
Ptr< SatWaveformConf > m_waveformConf
bool m_defaultWaveformInUse