9#include "ns3/channel-condition-model.h"
10#include "ns3/config.h"
11#include "ns3/constant-position-mobility-model.h"
12#include "ns3/double.h"
13#include "ns3/ism-spectrum-value-helper.h"
14#include "ns3/isotropic-antenna-model.h"
16#include "ns3/node-container.h"
17#include "ns3/pointer.h"
18#include "ns3/rng-seed-manager.h"
19#include "ns3/simple-net-device.h"
20#include "ns3/simulator.h"
21#include "ns3/spectrum-signal-parameters.h"
22#include "ns3/string.h"
24#include "ns3/three-gpp-antenna-model.h"
25#include "ns3/three-gpp-channel-model.h"
26#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
27#include "ns3/uinteger.h"
28#include "ns3/uniform-planar-array.h"
70 void DoRun()
override;
98 :
TestCase(
"Check the dimensions and the norm of the channel matrix")
117 uint64_t txAntennaElements = txAntenna->GetNumElems();
118 uint64_t rxAntennaElements = rxAntenna->GetNumElems();
121 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
123 double channelNorm = 0;
124 uint16_t numTotalClusters = channelMatrix->m_channel.GetNumPages();
125 for (uint16_t cIndex = 0; cIndex < numTotalClusters; cIndex++)
127 double clusterNorm = 0;
128 for (uint64_t sIndex = 0; sIndex < txAntennaElements; sIndex++)
130 for (uint64_t uIndex = 0; uIndex < rxAntennaElements; uIndex++)
133 std::pow(std::abs(channelMatrix->m_channel(uIndex, sIndex, cIndex)), 2);
136 channelNorm += clusterNorm;
155 channelModel->SetAttribute(
"Frequency",
DoubleValue(60.0e9));
156 channelModel->SetAttribute(
"Scenario",
StringValue(
"RMa"));
157 channelModel->SetAttribute(
"ChannelConditionModel",
PointerValue(channelConditionModel));
159 channelModel->AssignStreams(1);
177 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
179 rxMob->SetPosition(Vector(100.0, 0.0, 10.0));
195 "NumHorizontalPorts",
207 "NumHorizontalPorts",
211 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
215 channelMatrix->m_channel.GetNumCols(),
217 "The third dimension of H should be equal to the number of tx antenna elements");
219 channelMatrix->m_channel.GetNumRows(),
221 "The second dimension of H should be equal to the number of rx antenna elements");
224 uint16_t numIt = 1000;
225 for (uint16_t i = 0; i < numIt; i++)
240 double sampleMean = 0;
248 double sampleStd = 0;
251 sampleStd += ((i - sampleMean) * (i - sampleMean));
253 sampleStd = std::sqrt(sampleStd / (numIt - 1));
261 (sampleStd / std::sqrt(numIt));
269 "We reject the hypothesis E[|H|^2] = M*N with a significance level of 0.05");
308 void DoRun()
override;
339 :
TestCase(
"Check if the channel realizations are correctly updated during the simulation")
361 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
375 <<
" The channel matrix is not correctly updated");
391 channelModel->SetAttribute(
"Frequency",
DoubleValue(60.0e9));
392 channelModel->SetAttribute(
"Scenario",
StringValue(
"UMa"));
393 channelModel->SetAttribute(
"ChannelConditionModel",
PointerValue(channelConditionModel));
412 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
414 rxMob->SetPosition(Vector(100.0, 0.0, 1.6));
430 "NumHorizontalPorts",
442 "NumHorizontalPorts",
512 void DoRun()
override;
540 :
TestCase(
"Check if the channel realizations are correctly updated after antenna port changes "
541 "during the simulation")
559 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
567 <<
" The channel matrix is not correctly updated");
584 channelModel->SetAttribute(
"Frequency",
DoubleValue(60.0e9));
585 channelModel->SetAttribute(
"Scenario",
StringValue(
"UMa"));
586 channelModel->SetAttribute(
"ChannelConditionModel",
PointerValue(channelConditionModel));
605 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
607 rxMob->SetPosition(Vector(100.0, 0.0, 1.6));
623 "NumHorizontalPorts",
635 "NumHorizontalPorts",
666 [&txAntenna]() { txAntenna->SetNumRows(txAntenna->GetNumRows() + 1); });
690 [&rxAntenna]() { rxAntenna->SetNumRows(rxAntenna->GetNumRows() + 1); });
771 void DoRun()
override;
804 :
TestCase(
"Test case for the ThreeGppSpectrumPropagationLossModel class")
822 Vector aPos = thisDevice->GetNode()->GetObject<
MobilityModel>()->GetPosition();
823 Vector bPos = otherDevice->GetNode()->GetObject<
MobilityModel>()->GetPosition();
826 Angles completeAngle(bPos, aPos);
829 thisAntenna->GetBeamformingVector(completeAngle);
830 thisAntenna->SetBeamformingVector(antennaWeights);
837 auto rxPsdNewParams = params.lossModel->DoCalcRxPowerSpectralDensity(params.txParams,
844 "The long term is not updated when the channel matrix is recomputed");
861 lossModel->SetChannelModelAttribute(
"Frequency",
DoubleValue(2.4e9));
862 lossModel->SetChannelModelAttribute(
"Scenario",
StringValue(
"UMa"));
863 lossModel->SetChannelModelAttribute(
864 "ChannelConditionModel",
884 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
887 Vector(15.0, 0.0, 10.0));
903 "NumHorizontalPorts",
915 "NumHorizontalPorts",
924 double txPower = 0.1;
928 txParams->psd = txPsd->Copy();
932 lossModel->DoCalcRxPowerSpectralDensity(txParams, txMob, rxMob, txAntenna, rxAntenna);
936 lossModel->DoCalcRxPowerSpectralDensity(txParams, rxMob, txMob, rxAntenna, txAntenna);
939 "The long term for the direct and the reverse channel are different");
943 rxMob->SetPosition(Vector(10.0, 5.0, 10.0));
945 txBfVector[0] = std::complex<double>(0.0, 0.0);
946 txAntenna->SetBeamformingVector(txBfVector);
949 lossModel->DoCalcRxPowerSpectralDensity(txParams, rxMob, txMob, rxAntenna, txAntenna);
952 "Changing the BF vectors the rx PSD does not change");
955 (*rxParamsOld->spectrumChannelMatrix == *rxParamsNew->spectrumChannelMatrix),
957 "Changing the BF should change de frequency domain channel matrix");
960 rxParamsOld = rxParamsNew;
964 params{lossModel, txParams, txMob, rxMob, rxParamsOld->psd, txAntenna, rxAntenna};
1017 void DoRun()
override;
1021 :
TestCase(
"Check long term channel matrix generation when multiple ports at TX and RX are "
1039 channelModel->SetAttribute(
"Frequency",
DoubleValue(2.0e9));
1040 channelModel->SetAttribute(
"Scenario",
StringValue(
"RMa"));
1041 channelModel->SetAttribute(
"ChannelConditionModel",
PointerValue(channelConditionModel));
1059 txMob->SetPosition(Vector(0.0, 0.0, 10.0));
1061 rxMob->SetPosition(Vector(10.0, 0.0, 10.0));
1077 "NumHorizontalPorts",
1089 "NumHorizontalPorts",
1093 Angles completeAngleTxRx(rxMob->GetPosition(), txMob->GetPosition());
1094 Angles completeAngleRxTx(txMob->GetPosition(), rxMob->GetPosition());
1096 txAntenna1->SetBeamformingVector(txAntenna1->GetBeamformingVector(completeAngleTxRx));
1097 rxAntenna1->SetBeamformingVector(rxAntenna1->GetBeamformingVector(completeAngleRxTx));
1101 channelModel->GetChannel(txMob, rxMob, txAntenna1, rxAntenna1);
1109 threeGppSplm->CalcLongTerm(channelMatrixM0, txAntenna1, rxAntenna1);
1121 "NumHorizontalPorts",
1133 "NumHorizontalPorts",
1136 txAntenna2->SetBeamformingVector(txAntenna2->GetBeamformingVector(completeAngleTxRx));
1137 rxAntenna2->SetBeamformingVector(rxAntenna2->GetBeamformingVector(completeAngleRxTx));
1140 threeGppSplm->CalcLongTerm(channelMatrixM0, txAntenna2, rxAntenna2);
1152 "NumHorizontalPorts",
1154 "AntennaHorizontalSpacing",
1166 "NumHorizontalPorts",
1168 "AntennaHorizontalSpacing",
1173 channelMatrixMA->m_channel = *matrixA;
1175 txAntenna3->SetBeamformingVector(txAntenna3->GetBeamformingVector(completeAngleTxRx));
1176 rxAntenna3->SetBeamformingVector(rxAntenna3->GetBeamformingVector(completeAngleRxTx));
1179 threeGppSplm->CalcLongTerm(channelMatrixMA, txAntenna3, rxAntenna3);
1183 "Matrix B and Matrix C should be equal.");
1265 std::valarray<std::complex<double>> testChannel,
1277 void DoRun()
override;
1292 std::valarray<std::complex<double>>
1299 std::string testCaseName,
1304 std::valarray<std::complex<double>> testChannel,
1306 :
TestCase(
"Test MIMO using dual polarization." + testCaseName),
1308 m_txParams(txParams),
1310 m_rxParams(rxParams),
1311 m_testChannel(testChannel),
1312 m_tolerance(tolerance)
1325 if (params.m_isotropic)
1342 "NumHorizontalPorts",
1359 channelModel->SetAttribute(
"Frequency",
DoubleValue(60e9));
1360 channelModel->SetAttribute(
"Scenario",
StringValue(
"RMa"));
1361 channelModel->SetAttribute(
"ChannelConditionModel",
1364 int64_t randomStream = 1;
1365 randomStream += channelModel->AssignStreams(randomStream);
1396 txAntenna->SetBeamformingVector(
1397 txAntenna->GetBeamformingVector(
Angles(rxMob->GetPosition(), txMob->GetPosition())));
1398 rxAntenna->SetBeamformingVector(
1399 rxAntenna->GetBeamformingVector(
Angles(txMob->GetPosition(), rxMob->GetPosition())));
1403 channelModel->GetChannel(txMob, rxMob, txAntenna, rxAntenna);
1408 const std::complex<double>* strongestClusterPtr = channelMatrix->m_channel.GetPagePtr(0);
1410 channelMatrix->m_channel.GetNumRows() * channelMatrix->m_channel.GetNumCols();
1413 channelMatrix->m_channel.GetNumRows(),
1414 channelMatrix->m_channel.GetNumCols(),
1415 std::valarray<std::complex<double>>(strongestClusterPtr, matrixSize));
1418 channelMatrix->m_channel.GetNumCols(),
1421 NS_LOG_INFO(
"Channel matrix:" << strongestCluster);
1422 NS_LOG_INFO(
"Test channel matrix: " << testChannel);
1427 "The strongest cluster and the test channel matrix should be almost equal");
1461 TestCase::Duration::QUICK);
1463 TestCase::Duration::QUICK);
1465 TestCase::Duration::QUICK);
1467 TestCase::Duration::QUICK);
1479 std::valarray<std::complex<double>> testChannel1 =
1480 {5.9, 5.9, 0, 0, 5.9, 5.9, 0, 0, 0, 0, -5.8, -5.8, 0, 0, -5.8, -5.8};
1488 TestCase::Duration::QUICK);
1505 {5, 5, 3, 3, 5, 5, 3, 3, 3, 3, -5, -5, 3, 3, -5, -5},
1507 TestCase::Duration::QUICK);
1524 {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, -4, -4, 4, 4, -4, -4},
1526 TestCase::Duration::QUICK);
1538 "Face-to-face. 90 and 0 pol. slant angles.",
1543 {0, 0, 5.8, 5.8, 0, 0, 5.8, 5.8, 5.9, 5.9, 0, 0, 5.9, 5.9, 0, 0},
1545 TestCase::Duration::QUICK);
1562 "angles. 0 and 0 pol. slant angles.",
1565 Vector{6.363961031, 6.363961031, 3},
1569 TestCase::Duration::QUICK);
1582 "Not face-to-face. Different heights. 0 and 0 pol. slant angles.",
1604 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.
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.
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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#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.