39#include "ns3/buildings-module.h"
40#include "ns3/mobility-module.h"
41#include "ns3/core-module.h"
42#include "ns3/network-module.h"
44#include "ns3/uniform-planar-array.h"
45#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
46#include "ns3/three-gpp-v2v-propagation-loss-model.h"
47#include "ns3/three-gpp-channel-model.h"
109 Angles completeAngle (bPos,aPos);
129 NS_LOG_DEBUG (
"Pathloss " << -propagationGainDb <<
" dB");
130 double propagationGainLinear = std::pow (10.0, (propagationGainDb) / 10.0);
131 *(rxPsd) *= propagationGainLinear;
135 NS_LOG_DEBUG (
"Average rx power " << 10 * log10 (
Sum (*rxPsd) * 180e3) <<
" dB");
139 const double kT_dBm_Hz = -174.0;
140 double kT_W_Hz = std::pow (10.0, (kT_dBm_Hz - 30) / 10.0);
141 double noiseFigureLinear = std::pow (10.0, params.
noiseFigure / 10.0);
142 double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
144 (*noisePsd) = noisePowerSpectralDensity;
147 NS_LOG_DEBUG (
"Average SNR " << 10 * log10 (
Sum (*rxPsd) /
Sum (*noisePsd)) <<
" dB");
151 f.open (
"example-output.txt", std::ios::out | std::ios::app);
157 << cond->GetLosCondition () <<
" "
158 << 10 * log10 (
Sum (*rxPsd) /
Sum (*noisePsd)) <<
" "
159 << -propagationGainDb << std::endl;
171 std::ofstream outFile;
172 outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
173 if (!outFile.is_open ())
182 Box box = (*it)->GetBoundaries ();
183 outFile <<
"set object " << index
184 <<
" rect from " << box.
xMin <<
"," << box.
yMin
185 <<
" to " << box.
xMax <<
"," << box.
yMax
191main (
int argc,
char *argv[])
193 double frequency = 28.0e9;
194 double txPow_dbm = 30.0;
195 double noiseFigure = 9.0;
198 std::string scenario =
"V2V-Urban";
200 double subCarrierSpacing = 60e3;
204 cmd.AddValue (
"frequency",
"operating frequency in Hz", frequency);
205 cmd.AddValue (
"txPow",
"tx power in dBm", txPow_dbm);
206 cmd.AddValue (
"noiseFigure",
"noise figure in dB", noiseFigure);
207 cmd.AddValue (
"scenario",
"3GPP propagation scenario, V2V-Urban or V2V-Highway", scenario);
208 cmd.Parse (argc, argv);
219 nodes.Get (0)->AddDevice (txDev);
220 txDev->SetNode (
nodes.Get (0));
221 nodes.Get (1)->AddDevice (rxDev);
222 rxDev->SetNode (
nodes.Get (1));
230 if (scenario ==
"V2V-Urban")
236 double buildingSizeX = 250 - 3.5 * 2 - 3;
237 double buildingSizeY = 433 - 3.5 * 2 - 3;
238 double streetWidth = 20;
239 double buildingHeight = 10;
242 double maxAxisX = (buildingSizeX + streetWidth) * numBuildingsX;
243 double maxAxisY = (buildingSizeY + streetWidth) * numBuildingsY;
245 std::vector<Ptr<Building> > buildingVector;
246 for (
uint32_t buildingIdX = 0; buildingIdX < numBuildingsX; ++buildingIdX)
248 for (
uint32_t buildingIdY = 0; buildingIdY < numBuildingsY; ++buildingIdY)
251 building = CreateObject<Building> ();
253 building->SetBoundaries (
Box (buildingIdX * (buildingSizeX + streetWidth),
254 buildingIdX * (buildingSizeX + streetWidth) + buildingSizeX,
255 buildingIdY * (buildingSizeY + streetWidth),
256 buildingIdY * (buildingSizeY + streetWidth) + buildingSizeY,
257 0.0, buildingHeight));
258 building->SetNRoomsX (1);
259 building->SetNRoomsY (1);
260 building->SetNFloors (1);
261 buildingVector.push_back (building);
267 double vRx = vScatt / 2;
268 txMob = CreateObject<WaypointMobilityModel> ();
269 rxMob = CreateObject<WaypointMobilityModel> ();
272 nextWaypoint +=
Seconds ((maxAxisY - streetWidth) / 2 / vTx);
274 nextWaypoint +=
Seconds ((maxAxisX - streetWidth) / 2 / vTx);
278 nextWaypoint +=
Seconds (maxAxisY / vRx);
281 nodes.Get (0)->AggregateObject (txMob);
282 nodes.Get (1)->AggregateObject (rxMob);
285 m_condModel = CreateObject<ThreeGppV2vUrbanChannelConditionModel> ();
290 else if (scenario ==
"V2V-Highway")
298 double vRx = vScatt / 2;
300 txMob = CreateObject<ConstantVelocityMobilityModel> ();
301 rxMob = CreateObject<ConstantVelocityMobilityModel> ();
307 nodes.Get (0)->AggregateObject (txMob);
308 nodes.Get (1)->AggregateObject (rxMob);
311 m_condModel = CreateObject<ThreeGppV2vHighwayChannelConditionModel> ();
329 channelModel->SetAttribute (
"Scenario",
StringValue (scenario));
330 channelModel->SetAttribute (
"Frequency",
DoubleValue (frequency));
332 channelModel->SetAttribute (
"vScatt",
DoubleValue (vScatt));
337 BuildingsHelper::Install (
nodes);
345 double freqSubBand = frequency;
346 for (uint16_t n = 0; n < numRb; ++n)
350 freqSubBand += subCarrierSpacing / 2;
352 freqSubBand += subCarrierSpacing / 2;
358 double txPow_w = std::pow (10., (txPow_dbm - 30) / 10);
359 double txPowDens = (txPow_w / (numRb * subCarrierSpacing));
360 (*txPsd) = txPowDens;
362 for (
int i = 0; i < simTime / timeRes; i++)
369 f.open (
"example-output.txt", std::ios::out);
370 f <<
"Time[s] TxPosX[m] TxPosY[m] RxPosX[m] RxPosY[m] ChannelState SNR[dB] Pathloss[dB]" << std::endl;
377 Simulator::Destroy ();
double f(double x, void *params)
Class holding the azimuth and inclination angles of spherical coordinates.
AttributeValue implementation for Boolean.
double yMax
The y coordinate of the top bound of the box.
double xMin
The x coordinate of the left bound of the box.
double yMin
The y coordinate of the bottom bound of the box.
double xMax
The x coordinate of the right bound of the box.
std::vector< Ptr< Building > >::const_iterator Iterator
Const Iterator.
Parse command-line arguments.
Mobility model for which the current speed does not change once it has been set and until it is set a...
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.
Vector GetPosition(void) const
virtual Ptr< Node > GetNode(void) const =0
keep track of a set of node pointers.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
ComplexVector GetBeamformingVector(void) const
Returns the beamforming vector that is currently being used.
void SetBeamformingVector(const ComplexVector &beamformingVector)
Sets the beamforming vector to be used.
std::vector< std::complex< double > > ComplexVector
type definition for complex vectors
Ptr< SpectrumValue > CalcRxPowerSpectralDensity(Ptr< const SpectrumValue > txPsd, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, Ptr< const PhasedArrayModel > aPhasedArrayModel, Ptr< const PhasedArrayModel > bPhasedArrayModel) const
This method is to be called to calculate.
Hold objects of type Ptr<T>.
double CalcRxPower(double txPowerDbm, Ptr< MobilityModel > a, Ptr< MobilityModel > b) const
Returns the Rx Power taking into account all the PropagationLossModel(s) chained to the current one.
Ptr< SpectrumValue > Copy() const
Ptr< const SpectrumModel > GetSpectrumModel() const
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
Hold an unsigned integer type.
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Waypoint-based mobility model.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
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.
std::vector< BandInfo > Bands
Container of BandInfo.
double Sum(const SpectrumValue &x)
A structure that holds the parameters for the ComputeSnr function.
Ptr< PhasedArrayModel > txAntenna
the tx antenna array
Ptr< MobilityModel > rxMob
the rx mobility model
double noiseFigure
the noise figure in dB
Ptr< PhasedArrayModel > rxAntenna
the rx antenna array
ComputeSnrParams(Ptr< MobilityModel > pTxMob, Ptr< MobilityModel > pRxMob, Ptr< SpectrumValue > pTxPsd, double pNoiseFigure, Ptr< PhasedArrayModel > pTxAntenna, Ptr< PhasedArrayModel > pRxAntenna)
Constructor.
Ptr< SpectrumValue > txPsd
the PSD of the tx signal
Ptr< MobilityModel > txMob
the tx mobility model
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband
static Ptr< ChannelConditionModel > m_condModel
the ChannelConditionModel object
static Ptr< ThreeGppPropagationLossModel > m_propagationLossModel
the PropagationLossModel object
static void DoBeamforming(Ptr< NetDevice > thisDevice, Ptr< PhasedArrayModel > thisAntenna, Ptr< NetDevice > otherDevice)
Perform the beamforming using the DFT beamforming method.
void PrintGnuplottableBuildingListToFile(std::string filename)
Generates a GNU-plottable file representig the buildings deployed in the scenario.
static void ComputeSnr(ComputeSnrParams ¶ms)
Compute the average SNR.
static Ptr< ThreeGppSpectrumPropagationLossModel > m_spectrumLossModel
the SpectrumPropagationLossModel object
static void SetPosition(Ptr< Node > node, Vector position)
static Vector GetPosition(Ptr< Node > node)