19#include "ns3/angles.h"
20#include "ns3/channel-condition-model.h"
21#include "ns3/config.h"
22#include "ns3/constant-position-mobility-model.h"
23#include "ns3/double.h"
24#include "ns3/ism-spectrum-value-helper.h"
25#include "ns3/isotropic-antenna-model.h"
27#include "ns3/node-container.h"
28#include "ns3/pointer.h"
29#include "ns3/rng-seed-manager.h"
30#include "ns3/simple-net-device.h"
31#include "ns3/simulator.h"
32#include "ns3/spectrum-signal-parameters.h"
33#include "ns3/string.h"
35#include "ns3/three-gpp-antenna-model.h"
36#include "ns3/three-gpp-channel-model.h"
37#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
38#include "ns3/uinteger.h"
39#include "ns3/uniform-planar-array.h"
81 void DoRun()
override;
109 :
TestCase(
"Check the dimensions and the norm of the channel matrix")
128 uint64_t txAntennaElements = txAntenna->GetNumElems();
129 uint64_t rxAntennaElements = rxAntenna->GetNumElems();
132 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
134 double channelNorm = 0;
135 uint16_t numTotalClusters = channelMatrix->m_channel.GetNumPages();
136 for (uint16_t cIndex = 0; cIndex < numTotalClusters; cIndex++)
138 double clusterNorm = 0;
139 for (uint64_t sIndex = 0; sIndex < txAntennaElements; sIndex++)
141 for (uint64_t uIndex = 0; uIndex < rxAntennaElements; uIndex++)
144 std::pow(std::abs(channelMatrix->m_channel(uIndex, sIndex, cIndex)), 2);
147 channelNorm += clusterNorm;
162 CreateObject<NeverLosChannelConditionModel>();
166 channelModel->SetAttribute(
"Frequency",
DoubleValue(60.0e9));
167 channelModel->SetAttribute(
"Scenario",
StringValue(
"RMa"));
168 channelModel->SetAttribute(
"ChannelConditionModel",
PointerValue(channelConditionModel));
170 channelModel->AssignStreams(1);
188 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
190 rxMob->SetPosition(Vector(100.0, 0.0, 10.0));
206 "NumHorizontalPorts",
218 "NumHorizontalPorts",
222 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
226 channelMatrix->m_channel.GetNumCols(),
228 "The third dimension of H should be equal to the number of tx antenna elements");
230 channelMatrix->m_channel.GetNumRows(),
232 "The second dimension of H should be equal to the number of rx antenna elements");
235 uint16_t numIt = 1000;
236 for (uint16_t i = 0; i < numIt; i++)
251 double sampleMean = 0;
259 double sampleStd = 0;
262 sampleStd += ((i - sampleMean) * (i - sampleMean));
264 sampleStd = std::sqrt(sampleStd / (numIt - 1));
272 (sampleStd / std::sqrt(numIt));
280 "We reject the hypothesis E[|H|^2] = M*N with a significance level of 0.05");
319 void DoRun()
override;
350 :
TestCase(
"Check if the channel realizations are correctly updated during the simulation")
372 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
386 <<
" The channel matrix is not correctly updated");
398 CreateObject<AlwaysLosChannelConditionModel>();
402 channelModel->SetAttribute(
"Frequency",
DoubleValue(60.0e9));
403 channelModel->SetAttribute(
"Scenario",
StringValue(
"UMa"));
404 channelModel->SetAttribute(
"ChannelConditionModel",
PointerValue(channelConditionModel));
423 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
425 rxMob->SetPosition(Vector(100.0, 0.0, 1.6));
441 "NumHorizontalPorts",
453 "NumHorizontalPorts",
523 void DoRun()
override;
551 :
TestCase(
"Check if the channel realizations are correctly updated after antenna port changes "
552 "during the simulation")
570 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
578 <<
" The channel matrix is not correctly updated");
591 CreateObject<AlwaysLosChannelConditionModel>();
595 channelModel->SetAttribute(
"Frequency",
DoubleValue(60.0e9));
596 channelModel->SetAttribute(
"Scenario",
StringValue(
"UMa"));
597 channelModel->SetAttribute(
"ChannelConditionModel",
PointerValue(channelConditionModel));
616 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
618 rxMob->SetPosition(Vector(100.0, 0.0, 1.6));
634 "NumHorizontalPorts",
646 "NumHorizontalPorts",
677 [&txAntenna]() { txAntenna->SetNumRows(txAntenna->GetNumRows() + 1); });
701 [&rxAntenna]() { rxAntenna->SetNumRows(rxAntenna->GetNumRows() + 1); });
782 void DoRun()
override;
815 :
TestCase(
"Test case for the ThreeGppSpectrumPropagationLossModel class")
833 Vector aPos = thisDevice->GetNode()->GetObject<
MobilityModel>()->GetPosition();
834 Vector bPos = otherDevice->GetNode()->GetObject<
MobilityModel>()->GetPosition();
837 Angles completeAngle(bPos, aPos);
840 thisAntenna->GetBeamformingVector(completeAngle);
841 thisAntenna->SetBeamformingVector(antennaWeights);
848 auto rxPsdNewParams = params.lossModel->DoCalcRxPowerSpectralDensity(params.txParams,
855 "The long term is not updated when the channel matrix is recomputed");
871 CreateObject<ThreeGppSpectrumPropagationLossModel>();
872 lossModel->SetChannelModelAttribute(
"Frequency",
DoubleValue(2.4e9));
873 lossModel->SetChannelModelAttribute(
"Scenario",
StringValue(
"UMa"));
874 lossModel->SetChannelModelAttribute(
875 "ChannelConditionModel",
895 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
898 Vector(15.0, 0.0, 10.0));
914 "NumHorizontalPorts",
926 "NumHorizontalPorts",
935 double txPower = 0.1;
939 txParams->psd = txPsd->Copy();
943 lossModel->DoCalcRxPowerSpectralDensity(txParams, txMob, rxMob, txAntenna, rxAntenna);
947 lossModel->DoCalcRxPowerSpectralDensity(txParams, rxMob, txMob, rxAntenna, txAntenna);
950 "The long term for the direct and the reverse channel are different");
954 rxMob->SetPosition(Vector(10.0, 5.0, 10.0));
956 txBfVector[0] = std::complex<double>(0.0, 0.0);
957 txAntenna->SetBeamformingVector(txBfVector);
960 lossModel->DoCalcRxPowerSpectralDensity(txParams, rxMob, txMob, rxAntenna, txAntenna);
963 "Changing the BF vectors the rx PSD does not change");
966 (*rxParamsOld->spectrumChannelMatrix == *rxParamsNew->spectrumChannelMatrix),
968 "Changing the BF should change de frequency domain channel matrix");
971 rxParamsOld = rxParamsNew;
975 params{lossModel, txParams, txMob, rxMob, rxParamsOld->psd, txAntenna, rxAntenna};
1028 void DoRun()
override;
1032 :
TestCase(
"Check long term channel matrix generation when multiple ports at TX and RX are "
1046 CreateObject<AlwaysLosChannelConditionModel>();
1050 channelModel->SetAttribute(
"Frequency",
DoubleValue(2.0e9));
1051 channelModel->SetAttribute(
"Scenario",
StringValue(
"RMa"));
1052 channelModel->SetAttribute(
"ChannelConditionModel",
PointerValue(channelConditionModel));
1070 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
1072 rxMob->SetPosition(Vector(10.0, 0.0, 10.0));
1088 "NumHorizontalPorts",
1100 "NumHorizontalPorts",
1104 Angles completeAngleTxRx(rxMob->GetPosition(), txMob->GetPosition());
1105 Angles completeAngleRxTx(txMob->GetPosition(), rxMob->GetPosition());
1107 txAntenna1->SetBeamformingVector(txAntenna1->GetBeamformingVector(completeAngleTxRx));
1108 rxAntenna1->SetBeamformingVector(rxAntenna1->GetBeamformingVector(completeAngleRxTx));
1112 channelModel->GetChannel(txMob, rxMob, txAntenna1, rxAntenna1);
1117 CreateObject<ThreeGppSpectrumPropagationLossModel>();
1120 threeGppSplm->CalcLongTerm(channelMatrixM0, txAntenna1, rxAntenna1);
1132 "NumHorizontalPorts",
1144 "NumHorizontalPorts",
1147 txAntenna2->SetBeamformingVector(txAntenna2->GetBeamformingVector(completeAngleTxRx));
1148 rxAntenna2->SetBeamformingVector(rxAntenna2->GetBeamformingVector(completeAngleRxTx));
1151 threeGppSplm->CalcLongTerm(channelMatrixM0, txAntenna2, rxAntenna2);
1163 "NumHorizontalPorts",
1165 "AntennaHorizontalSpacing",
1177 "NumHorizontalPorts",
1179 "AntennaHorizontalSpacing",
1183 Create<ThreeGppChannelModel::ChannelMatrix>();
1184 channelMatrixMA->m_channel = *matrixA;
1186 txAntenna3->SetBeamformingVector(txAntenna3->GetBeamformingVector(completeAngleTxRx));
1187 rxAntenna3->SetBeamformingVector(rxAntenna3->GetBeamformingVector(completeAngleRxTx));
1190 threeGppSplm->CalcLongTerm(channelMatrixMA, txAntenna3, rxAntenna3);
1194 "Matrix B and Matrix C should be equal.");
1276 std::valarray<std::complex<double>> testChannel,
1288 void DoRun()
override;
1303 std::valarray<std::complex<double>>
1310 std::string testCaseName,
1315 std::valarray<std::complex<double>> testChannel,
1317 :
TestCase(
"Test MIMO using dual polarization." + testCaseName),
1319 m_txParams(txParams),
1321 m_rxParams(rxParams),
1322 m_testChannel(testChannel),
1323 m_tolerance(tolerance)
1336 if (params.m_isotropic)
1338 antenna = CreateObject<IsotropicAntennaModel>();
1342 antenna = CreateObject<ThreeGppAntennaModel>();
1345 return CreateObjectWithAttributes<UniformPlanarArray>(
"NumColumns",
1353 "NumHorizontalPorts",
1370 channelModel->SetAttribute(
"Frequency",
DoubleValue(60e9));
1371 channelModel->SetAttribute(
"Scenario",
StringValue(
"RMa"));
1372 channelModel->SetAttribute(
"ChannelConditionModel",
1373 PointerValue(CreateObject<AlwaysLosChannelConditionModel>()));
1375 int64_t randomStream = 1;
1376 randomStream += channelModel->AssignStreams(randomStream);
1407 txAntenna->SetBeamformingVector(
1408 txAntenna->GetBeamformingVector(
Angles(rxMob->GetPosition(), txMob->GetPosition())));
1409 rxAntenna->SetBeamformingVector(
1410 rxAntenna->GetBeamformingVector(
Angles(txMob->GetPosition(), rxMob->GetPosition())));
1414 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
1419 const std::complex<double>* strongestClusterPtr = channelMatrix->m_channel.GetPagePtr(0);
1421 channelMatrix->m_channel.GetNumRows() * channelMatrix->m_channel.GetNumCols();
1424 channelMatrix->m_channel.GetNumRows(),
1425 channelMatrix->m_channel.GetNumCols(),
1426 std::valarray<std::complex<double>>(strongestClusterPtr, matrixSize));
1429 channelMatrix->m_channel.GetNumCols(),
1432 NS_LOG_INFO(
"Channel matrix:" << strongestCluster);
1433 NS_LOG_INFO(
"Test channel matrix: " << testChannel);
1438 "The strongest cluster and the test channel matrix should be almost equal");
1472 TestCase::Duration::QUICK);
1474 TestCase::Duration::QUICK);
1476 TestCase::Duration::QUICK);
1478 TestCase::Duration::QUICK);
1490 std::valarray<std::complex<double>> testChannel1 =
1491 {5.9, 5.9, 0, 0, 5.9, 5.9, 0, 0, 0, 0, -5.8, -5.8, 0, 0, -5.8, -5.8};
1499 TestCase::Duration::QUICK);
1516 {5, 5, 3, 3, 5, 5, 3, 3, 3, 3, -5, -5, 3, 3, -5, -5},
1518 TestCase::Duration::QUICK);
1535 {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, -4, -4, 4, 4, -4, -4},
1537 TestCase::Duration::QUICK);
1549 "Face-to-face. 90 and 0 pol. slant angles.",
1554 {0, 0, 5.8, 5.8, 0, 0, 5.8, 5.8, 5.9, 5.9, 0, 0, 5.9, 5.9, 0, 0},
1556 TestCase::Duration::QUICK);
1573 "angles. 0 and 0 pol. slant angles.",
1576 Vector{6.363961031, 6.363961031, 3},
1580 TestCase::Duration::QUICK);
1593 "Not face-to-face. Different heights. 0 and 0 pol. slant angles.",
1615 TestCase::Duration::QUICK);
Test case for the ThreeGppChannelModel class.
uint32_t m_rxPorts
number of horizontal and vertical ports of rx antenna array
~ThreeGppAntennaSetupChangedTest() override
Destructor.
uint32_t m_txPorts
number of horizontal and vertical ports of tx antenna array
uint32_t m_rxAntennaElements
number of rows and columns of rx antenna array
uint32_t m_txAntennaElements
number of rows and columns of tx antenna array
void DoGetChannel(Ptr< ThreeGppChannelModel > channelModel, Ptr< MobilityModel > txMob, Ptr< MobilityModel > rxMob, Ptr< PhasedArrayModel > txAntenna, Ptr< PhasedArrayModel > rxAntenna, bool update)
This method is used to schedule the channel matrix computation at different time instants and to chec...
Ptr< const ThreeGppChannelModel::ChannelMatrix > m_currentChannel
used by DoGetChannel to store the current channel matrix
ThreeGppAntennaSetupChangedTest()
Constructor.
void DoRun() override
Build the test scenario.
Test case that test the correct use of the multi-port antennas in spectrum.
~ThreeGppCalcLongTermMultiPortTest() override
Destructor.
void DoRun() override
Build the test scenario.
ThreeGppCalcLongTermMultiPortTest()
Constructor.
Test case for the ThreeGppChannelModel class.
ThreeGppChannelMatrixComputationTest(uint32_t txAntennaElements=2, uint32_t rxAntennaElements=2, uint32_t txPorts=1, uint32_t rxPorts=1)
Constructor.
void DoRun() override
Build the test scenario.
uint32_t m_rxPorts
number of horizontal and vertical ports of rx antenna array
~ThreeGppChannelMatrixComputationTest() override
Destructor.
std::vector< double > m_normVector
each element is the norm of a channel realization
void DoComputeNorm(Ptr< ThreeGppChannelModel > channelModel, Ptr< MobilityModel > txMob, Ptr< MobilityModel > rxMob, Ptr< PhasedArrayModel > txAntenna, Ptr< PhasedArrayModel > rxAntenna)
Compute the Frobenius norm of the channel matrix and stores it in m_normVector.
uint32_t m_rxAntennaElements
number of rows and columns of rx antenna array
uint32_t m_txAntennaElements
number of rows and columns of tx antenna array
uint32_t m_txPorts
number of horizontal and vertical ports of tx antenna array
Test case for the ThreeGppChannelModel class.
void DoGetChannel(Ptr< ThreeGppChannelModel > channelModel, Ptr< MobilityModel > txMob, Ptr< MobilityModel > rxMob, Ptr< PhasedArrayModel > txAntenna, Ptr< PhasedArrayModel > rxAntenna, bool update)
This method is used to schedule the channel matrix computation at different time instants and to chec...
ThreeGppChannelMatrixUpdateTest(uint32_t txAntennaElements=2, uint32_t rxAntennaElements=4, uint32_t txPorts=1, uint32_t rxPorts=1)
Constructor.
uint32_t m_txAntennaElements
number of rows and columns of tx antenna array
void DoRun() override
Build the test scenario.
~ThreeGppChannelMatrixUpdateTest() override
Destructor.
uint32_t m_rxPorts
number of horizontal and vertical ports of rx antenna array
Ptr< const ThreeGppChannelModel::ChannelMatrix > m_currentChannel
used by DoGetChannel to store the current channel matrix
uint32_t m_txPorts
number of horizontal and vertical ports of tx antenna array
uint32_t m_rxAntennaElements
number of rows and columns of rx antenna array
Test suite for the ThreeGppChannelModel class.
ThreeGppChannelTestSuite()
Constructor.
This test tests that the channel matrix is correctly generated when dual-polarized antennas are being...
void DoRun() override
Build the test scenario.
Vector m_txLoc
Position of the TX device.
Vector m_rxLoc
Position of the RX device.
Ptr< PhasedArrayModel > CreateAndConfigureAntenna(const MimoPolarizationAntennaParams ¶ms)
Function that can be used to configure the antenna using the set of parameters.
MimoPolarizationAntennaParams m_txParams
Parameters used to configure the TX antenna array.
double m_tolerance
The tolerance to be used when comparing the channel matrix with the test matrix.
std::valarray< std::complex< double > > m_testChannel
The test value for the matrix representing the strongest cluster.
ThreeGppMimoPolarizationTest(std::string testCaseName, Vector txLoc, const MimoPolarizationAntennaParams &txAntennaParams, Vector rxLoc, const MimoPolarizationAntennaParams &rxAntennaParams, std::valarray< std::complex< double > > testChannel, double tolerance)
Constructor that receives MIMO polarization parameters of TX and RX devices.
~ThreeGppMimoPolarizationTest() override
Destructor.
MimoPolarizationAntennaParams m_rxParams
Parameters used to configure the RX antenna array.
Test case for the ThreeGppSpectrumPropagationLossModelTest class.
ThreeGppSpectrumPropagationLossModelTest(uint32_t txAntennaElements=4, uint32_t rxAntennaElements=4, uint32_t txPorts=1, uint32_t rxPorts=1)
Constructor.
void DoRun() override
Build the test scenario.
uint32_t m_txPorts
number of horizontal and vertical ports of tx antenna array
uint32_t m_rxAntennaElements
number of rows and columns of rx antenna array
uint32_t m_rxPorts
number of horizontal and vertical ports of rx antenna array
~ThreeGppSpectrumPropagationLossModelTest() override
Destructor.
void CheckLongTermUpdate(const CheckLongTermUpdateParams ¶ms)
Test of the long term component is correctly updated when the channel matrix is recomputed.
void DoBeamforming(Ptr< NetDevice > thisDevice, Ptr< PhasedArrayModel > thisAntenna, Ptr< NetDevice > otherDevice, Ptr< PhasedArrayModel > otherAntenna)
Points the beam of thisDevice towards otherDevice.
uint32_t m_txAntennaElements
number of rows and columns of tx antenna array
Class holding the azimuth and inclination angles of spherical coordinates.
AttributeValue implementation for Boolean.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
Implements Wifi SpectrumValue for the 2.4 GHz ISM band only, with a 5 MHz spectrum resolution.
virtual Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint8_t channel)
Creates a SpectrumValue instance that represents the TX Power Spectral Density of a wifi device corre...
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
Hold an unsigned integer type.
bool IsAlmostEqual(const ValArray< T > &rhs, T tol) const
Compare Valarray up to a given absolute tolerance.
void SetDefault(std::string name, const AttributeValue &value)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A structure that holds the parameters for the function CheckLongTermUpdate.
Ptr< ThreeGppSpectrumPropagationLossModel > lossModel
the ThreeGppSpectrumPropagationLossModel object used to compute the rx PSD
Ptr< MobilityModel > txMob
the mobility model of the tx device
Ptr< SpectrumValue > rxPsdOld
the previously received PSD
Ptr< SpectrumSignalParameters > txParams
the params of the tx signal
Ptr< PhasedArrayModel > rxAntenna
the antenna array of the rx device
Ptr< MobilityModel > rxMob
the mobility model of the rx device
Ptr< PhasedArrayModel > txAntenna
the antenna array of the tx device
Structure that contains some of the main configuration parameters of the antenna array that are used ...
uint32_t m_rows
the number of rows of antenna array
double m_bearingAngle
bearing angle of the antenna array
MimoPolarizationAntennaParams(bool isotropic, double polSlantAngle=0, double bearingAngle=0)
Constructor Currently only configurable through constructor are polSlantAngle and bearingAngle.
bool m_isotropic
defines whether the antenna elements are isotropic
uint32_t m_hPorts
the number of horizontal ports of antenna array
double m_polSlantAngle
polarization angle of the antenna array
uint32_t m_cols
the number of columns of antenna array
uint32_t m_vPorts
the number of vertical ports of antenna array
Complex3DVector m_channel
Channel matrix H[u][s][n].
static ThreeGppChannelTestSuite myTestSuite
Static variable for test initialization.