20 #include "ns3/abort.h" 22 #include "ns3/config.h" 23 #include "ns3/double.h" 24 #include "ns3/uinteger.h" 25 #include "ns3/string.h" 26 #include "ns3/angles.h" 27 #include "ns3/pointer.h" 28 #include "ns3/node-container.h" 29 #include "ns3/constant-position-mobility-model.h" 30 #include "ns3/three-gpp-antenna-array-model.h" 31 #include "ns3/three-gpp-channel-model.h" 32 #include "ns3/simple-net-device.h" 33 #include "ns3/simulator.h" 34 #include "ns3/channel-condition-model.h" 35 #include "ns3/three-gpp-spectrum-propagation-loss-model.h" 36 #include "ns3/wifi-spectrum-value-helper.h" 64 virtual void DoRun (
void);
80 :
TestCase (
"Check the dimensions and the norm of the channel matrix")
96 double channelNorm = 0;
97 uint8_t numTotClusters = channelMatrix->
m_channel.at (0).at (0).size ();
98 for (uint8_t cIndex = 0; cIndex < numTotClusters; cIndex++)
100 double clusterNorm = 0;
101 for (uint64_t sIndex = 0; sIndex < txAntennaElements; sIndex++)
103 for (uint32_t uIndex = 0; uIndex < rxAntennaElements; uIndex++)
105 clusterNorm += std::pow (std::abs (channelMatrix->
m_channel.at (uIndex).at (sIndex).at (cIndex)), 2);
108 channelNorm += clusterNorm;
117 uint8_t txAntennaElements[] {2, 2};
118 uint8_t rxAntennaElements[] {2, 2};
119 uint32_t updatePeriodMs = 100;
126 channelModel->SetAttribute (
"Frequency",
DoubleValue (60.0e9));
127 channelModel->SetAttribute (
"Scenario",
StringValue (
"RMa"));
128 channelModel->SetAttribute (
"ChannelConditionModel",
PointerValue (channelConditionModel));
140 nodes.Get (0)->AddDevice (txDev);
142 nodes.Get (1)->AddDevice (rxDev);
143 rxDev->SetNode (
nodes.Get (1));
152 nodes.Get (0)->AggregateObject (txMob);
153 nodes.Get (1)->AggregateObject (rxMob);
163 NS_TEST_ASSERT_MSG_EQ (channelMatrix->m_channel.at (0).size (), txAntennaElements [0] * txAntennaElements [1],
"The second dimension of H should be equal to the number of tx antenna elements");
164 NS_TEST_ASSERT_MSG_EQ (channelMatrix->m_channel.size (), rxAntennaElements [0] * rxAntennaElements [1],
"The first dimension of H should be equal to the number of rx antenna elements");
167 uint16_t numIt = 1000;
168 for (uint16_t i = 0; i < numIt; i++)
176 double sampleMean = 0;
184 double sampleStd = 0;
187 sampleStd += ((i - sampleMean) * (i - sampleMean));
189 sampleStd = std::sqrt (sampleStd / (numIt - 1));
195 double t = (sampleMean - txAntennaElements [0] * txAntennaElements [1] * rxAntennaElements [0] * rxAntennaElements [1]) / (sampleMean / std::sqrt (numIt));
199 NS_TEST_ASSERT_MSG_EQ_TOL (std::abs (t), 0, 1.65,
"We reject the hypothesis E[|H|^2] = M*N with a significance level of 0.05");
201 Simulator::Destroy ();
226 virtual void DoRun (
void);
244 :
TestCase (
"Check if the channel realizations are correctly updated during the simulation")
276 uint8_t txAntennaElements[] {2, 2};
277 uint8_t rxAntennaElements[] {4, 4};
278 uint32_t updatePeriodMs = 100;
285 channelModel->SetAttribute (
"Frequency",
DoubleValue (60.0e9));
286 channelModel->SetAttribute (
"Scenario",
StringValue (
"UMa"));
287 channelModel->SetAttribute (
"ChannelConditionModel",
PointerValue (channelConditionModel));
299 nodes.Get (0)->AddDevice (txDev);
301 nodes.Get (1)->AddDevice (rxDev);
302 rxDev->SetNode (
nodes.Get (1));
311 nodes.Get (0)->AggregateObject (txMob);
312 nodes.Get (1)->AggregateObject (rxMob);
321 uint32_t firstTimeMs = 1;
333 Simulator::Destroy ();
361 virtual void DoRun (
void);
394 :
TestCase (
"Test case for the ThreeGppSpectrumPropagationLossModel class")
411 Angles completeAngle (bPos,aPos);
413 double hAngleRadian = fmod (completeAngle.
phi, 2.0 * M_PI);
414 if (hAngleRadian < 0)
416 hAngleRadian += 2.0 * M_PI;
418 double vAngleRadian = completeAngle.
theta;
421 double power = 1 / sqrt (totNoArrayElements);
423 for (
int ind = 0; ind < totNoArrayElements; ind++)
426 double phase = -2 * M_PI * (sin (vAngleRadian) * cos (hAngleRadian) * loc.x
427 + sin (vAngleRadian) * sin (hAngleRadian) * loc.y
428 + cos (vAngleRadian) * loc.z);
429 antennaWeights.push_back (exp (std::complex<double> (0, phase)) * power);
439 for (uint8_t i = 0; i <
first->GetSpectrumModel ()->GetNumBands (); i++)
441 if ((*
first) [i] != (*second) [i])
463 uint8_t txAntennaElements[] {4, 4};
464 uint8_t rxAntennaElements[] {4, 4};
473 lossModel->SetChannelModelAttribute (
"Frequency",
DoubleValue(2.4e9));
474 lossModel->SetChannelModelAttribute (
"Scenario",
StringValue(
"UMa"));
475 lossModel->SetChannelModelAttribute (
"ChannelConditionModel",
PointerValue (condModel));
486 nodes.Get (0)->AddDevice (txDev);
488 nodes.Get (1)->AddDevice (rxDev);
489 rxDev->SetNode (
nodes.Get (1));
498 nodes.Get (0)->AggregateObject (txMob);
499 nodes.Get (1)->AggregateObject (rxMob);
506 lossModel->AddDevice (txDev, txAntenna);
507 lossModel->AddDevice (rxDev, rxAntenna);
515 double txPower = 0.1;
516 uint32_t channelNumber = 1;
520 Ptr<SpectrumValue> rxPsdOld = lossModel->DoCalcRxPowerSpectralDensity (txPsd, txMob, rxMob);
523 Ptr<SpectrumValue> rxPsdNew = lossModel->DoCalcRxPowerSpectralDensity (txPsd, rxMob, txMob);
530 txBfVector [0] = std::complex<double> (0.0, 0.0);
533 rxPsdNew = lossModel->DoCalcRxPowerSpectralDensity (txPsd, rxMob, txMob);
543 Simulator::Destroy ();
ThreeGppChannelMatrixUpdateTest()
Constructor.
virtual uint64_t GetNumberOfElements(void) const
Returns the number of antenna elements.
Smart pointer class similar to boost::intrusive_ptr.
AttributeValue implementation for Boolean.
std::vector< std::complex< double > > ComplexVector
type definition for complex vectors
Hold variables of type string.
virtual Ptr< Node > GetNode(void) const =0
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
ThreeGppSpectrumPropagationLossModelTest()
Constructor.
virtual void DoRun(void)
Build the test scenario.
double theta
the inclination angle in radians
static bool ArePsdEqual(Ptr< SpectrumValue > first, Ptr< SpectrumValue > second)
Checks if two PSDs are equal.
static Vector GetPosition(Ptr< Node > node)
Test case for the ThreeGppChannelModel class.
virtual Vector GetElementLocation(uint64_t index) const
Returns the location of the antenna element with the specified index assuming the left bottom corner ...
Keep track of the current position and velocity of an object.
virtual void SetNode(Ptr< Node > node)
virtual ~ThreeGppSpectrumPropagationLossModelTest()
Destructor.
AttributeValue implementation for Time.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
std::vector< double > m_normVector
each element is the norm of a channel realization
Hold an unsigned integer type.
#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.
Ptr< const ChannelMatrix > GetChannel(Ptr< const MobilityModel > aMob, Ptr< const MobilityModel > bMob, Ptr< const ThreeGppAntennaArrayModel > aAntenna, Ptr< const ThreeGppAntennaArrayModel > bAntenna) override
Looks for the channel matrix associated to the aMob and bMob pair in m_channelMap.
Test case for the ThreeGppSpectrumPropagationLossModelTest class.
#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...
static ThreeGppChannelTestSuite myTestSuite
Complex3DVector m_channel
channel matrix H[u][s][n].
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void SetBeamformingVector(const ComplexVector &beamformingVector)
Sets the beamforming vector to be used.
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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Hold objects of type Ptr<T>.
Test suite for the ThreeGppChannelModel class.
Ptr< const ThreeGppChannelModel::ChannelMatrix > m_currentChannel
used by DoGetChannel to store the current channel matrix
void DoGetChannel(Ptr< ThreeGppChannelModel > channelModel, Ptr< MobilityModel > txMob, Ptr< MobilityModel > rxMob, Ptr< ThreeGppAntennaArrayModel > txAntenna, Ptr< ThreeGppAntennaArrayModel > rxAntenna, bool update)
This method is used to schedule the channel matrix computation at different time instants and to chec...
ThreeGppChannelMatrixComputationTest()
Constructor.
const ComplexVector & GetBeamformingVector(void) const
Returns the beamforming vector that is currently being used.
ThreeGppChannelTestSuite()
Constructor.
void SetPosition(const Vector &position)
virtual ~ThreeGppChannelMatrixComputationTest()
Destructor.
virtual void DoRun(void)
Build the test scenario.
void SetDefault(std::string name, const AttributeValue &value)
double phi
the azimuth angle in radians
void CheckLongTermUpdate(Ptr< ThreeGppSpectrumPropagationLossModel > lossModel, Ptr< SpectrumValue > txPsd, Ptr< MobilityModel > txMob, Ptr< MobilityModel > rxMob, Ptr< SpectrumValue > rxPsdOld)
Test of the long term component is correctly updated when the channel matrix is recomputed.
void DoComputeNorm(Ptr< ThreeGppChannelModel > channelModel, Ptr< MobilityModel > txMob, Ptr< MobilityModel > rxMob, Ptr< ThreeGppAntennaArrayModel > txAntenna, Ptr< ThreeGppAntennaArrayModel > rxAntenna)
Compute the Frobenius norm of the channel matrix and stores it in m_normVector.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
void DoBeamforming(Ptr< NetDevice > thisDevice, Ptr< ThreeGppAntennaArrayModel > thisAntenna, Ptr< NetDevice > otherDevice, Ptr< ThreeGppAntennaArrayModel > otherAntenna)
Points the beam of thisDevice towards otherDevice.
Ptr< SpectrumValue > DoCalcRxPowerSpectralDensity(Ptr< const SpectrumValue > txPsd, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const override
Computes the received PSD.
virtual ~ThreeGppChannelMatrixUpdateTest()
Destructor.
struct holding the azimuth and inclination angles of spherical coordinates.
Test case for the ThreeGppChannelModel class.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Implements Wifi SpectrumValue for the 2.4 GHz ISM band only, with a 5 MHz spectrum resolution...
virtual void DoRun(void)
Build the test scenario.