38#include "ns3/buildings-module.h"
39#include "ns3/core-module.h"
40#include "ns3/mobility-module.h"
41#include "ns3/network-module.h"
42#include "ns3/spectrum-signal-parameters.h"
43#include "ns3/three-gpp-channel-model.h"
44#include "ns3/three-gpp-spectrum-propagation-loss-model.h"
45#include "ns3/three-gpp-v2v-propagation-loss-model.h"
46#include "ns3/uniform-planar-array.h"
89 Vector aPos = thisDevice->GetNode()->GetObject<
MobilityModel>()->GetPosition();
90 Vector bPos = otherDevice->GetNode()->GetObject<
MobilityModel>()->GetPosition();
93 Angles completeAngle(bPos, aPos);
96 thisAntenna->SetBeamformingVector(bf);
112 NS_LOG_DEBUG(
"Pathloss " << -propagationGainDb <<
" dB");
113 double propagationGainLinear = std::pow(10.0, (propagationGainDb) / 10.0);
114 *(params.txParams->psd) *= propagationGainLinear;
122 NS_LOG_DEBUG(
"Average rx power " << 10 * log10(
Sum(*rxPsd) * 180e3) <<
" dB");
126 const double kT_dBm_Hz = -174.0;
127 double kT_W_Hz = std::pow(10.0, (kT_dBm_Hz - 30) / 10.0);
128 double noiseFigureLinear = std::pow(10.0, params.noiseFigure / 10.0);
129 double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
130 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(params.txParams->psd->GetSpectrumModel());
131 (*noisePsd) = noisePowerSpectralDensity;
138 f.open(
"example-output.txt", std::ios::out | std::ios::app);
140 << params.txMob->GetPosition().x <<
" " << params.txMob->GetPosition().y <<
" "
141 << params.rxMob->GetPosition().x <<
" " << params.rxMob->GetPosition().y <<
" "
142 << cond->GetLosCondition() <<
" "
143 << 10 * log10(
Sum(*rxPsd) /
Sum(*noisePsd)) <<
" "
144 << -propagationGainDb << std::endl;
156 std::ofstream outFile;
157 outFile.open(filename, std::ios_base::out | std::ios_base::trunc);
158 if (!outFile.is_open())
167 Box box = (*it)->GetBoundaries();
168 outFile <<
"set object " << index <<
" rect from " << box.
xMin <<
"," << box.
yMin <<
" to "
169 << box.
xMax <<
"," << box.
yMax << std::endl;
174main(
int argc,
char* argv[])
176 double frequency = 28.0e9;
177 double txPow_dbm = 30.0;
178 double noiseFigure = 9.0;
181 std::string scenario =
"V2V-Urban";
183 double subCarrierSpacing = 60e3;
187 cmd.AddValue(
"frequency",
"operating frequency in Hz", frequency);
188 cmd.AddValue(
"txPow",
"tx power in dBm", txPow_dbm);
189 cmd.AddValue(
"noiseFigure",
"noise figure in dB", noiseFigure);
190 cmd.AddValue(
"scenario",
"3GPP propagation scenario, V2V-Urban or V2V-Highway", scenario);
191 cmd.Parse(argc, argv);
209 CreateObjectWithAttributes<UniformPlanarArray>(
"NumColumns",
216 CreateObjectWithAttributes<UniformPlanarArray>(
"NumColumns",
225 if (scenario ==
"V2V-Urban")
231 double buildingSizeX = 250 - 3.5 * 2 - 3;
232 double buildingSizeY = 433 - 3.5 * 2 - 3;
233 double streetWidth = 20;
234 double buildingHeight = 10;
237 double maxAxisX = (buildingSizeX + streetWidth) * numBuildingsX;
238 double maxAxisY = (buildingSizeY + streetWidth) * numBuildingsY;
240 std::vector<Ptr<Building>> buildingVector;
241 for (
uint32_t buildingIdX = 0; buildingIdX < numBuildingsX; ++buildingIdX)
243 for (
uint32_t buildingIdY = 0; buildingIdY < numBuildingsY; ++buildingIdY)
246 building = CreateObject<Building>();
248 building->SetBoundaries(
249 Box(buildingIdX * (buildingSizeX + streetWidth),
250 buildingIdX * (buildingSizeX + streetWidth) + buildingSizeX,
251 buildingIdY * (buildingSizeY + streetWidth),
252 buildingIdY * (buildingSizeY + streetWidth) + buildingSizeY,
255 building->SetNRoomsX(1);
256 building->SetNRoomsY(1);
257 building->SetNFloors(1);
258 buildingVector.push_back(building);
264 double vRx = vScatt / 2;
265 txMob = CreateObject<WaypointMobilityModel>();
266 rxMob = CreateObject<WaypointMobilityModel>();
269 Waypoint(nextWaypoint, Vector(maxAxisX / 2 - streetWidth / 2, 1.0, 1.5)));
270 nextWaypoint +=
Seconds((maxAxisY - streetWidth) / 2 / vTx);
273 Vector(maxAxisX / 2 - streetWidth / 2, maxAxisY / 2 - streetWidth / 2, 1.5)));
274 nextWaypoint +=
Seconds((maxAxisX - streetWidth) / 2 / vTx);
276 Waypoint(nextWaypoint, Vector(0.0, maxAxisY / 2 - streetWidth / 2, 1.5)));
279 Waypoint(nextWaypoint, Vector(maxAxisX / 2 - streetWidth / 2, 0.0, 1.5)));
280 nextWaypoint +=
Seconds(maxAxisY / vRx);
282 Waypoint(nextWaypoint, Vector(maxAxisX / 2 - streetWidth / 2, maxAxisY, 1.5)));
288 m_condModel = CreateObject<ThreeGppV2vUrbanChannelConditionModel>();
293 else if (scenario ==
"V2V-Highway")
301 double vRx = vScatt / 2;
303 txMob = CreateObject<ConstantVelocityMobilityModel>();
304 rxMob = CreateObject<ConstantVelocityMobilityModel>();
314 m_condModel = CreateObject<ThreeGppV2vHighwayChannelConditionModel>();
332 channelModel->SetAttribute(
"Scenario",
StringValue(scenario));
333 channelModel->SetAttribute(
"Frequency",
DoubleValue(frequency));
335 channelModel->SetAttribute(
"vScatt",
DoubleValue(vScatt));
350 double freqSubBand = frequency;
351 for (
uint32_t n = 0; n < numRb; ++n)
355 freqSubBand += subCarrierSpacing / 2;
357 freqSubBand += subCarrierSpacing / 2;
364 double txPow_w = std::pow(10., (txPow_dbm - 30) / 10);
365 double txPowDens = (txPow_w / (numRb * subCarrierSpacing));
366 (*txPsd) = txPowDens;
367 txParams->psd = txPsd->Copy();
369 for (
int i = 0; i < simTime / timeRes; i++)
377 f.open(
"example-output.txt", std::ios::out);
378 f <<
"Time[s] TxPosX[m] TxPosY[m] RxPosX[m] RxPosY[m] ChannelState SNR[dB] Pathloss[dB]"
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.
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.
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'.
MatrixArray class inherits ValArray class and provides additional interfaces to ValArray which enable...
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 SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Ptr< SpectrumValue > CalcRxPowerSpectralDensity(Ptr< const SpectrumSignalParameters > 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.
Smart pointer class similar to boost::intrusive_ptr.
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.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
AttributeValue implementation for Time.
Hold an unsigned integer type.
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 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)
FtrParams params
Fit Fluctuating Two Ray model to the 3GPP TR 38.901 using the Anderson-Darling goodness-of-fit ##.
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< SpectrumSignalParameters > txParams
the params of the tx signal
Ptr< PhasedArrayModel > rxAntenna
the rx antenna array
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.
static void ComputeSnr(const ComputeSnrParams ¶ms)
Compute the average SNR.
void PrintGnuplottableBuildingListToFile(std::string filename)
Generates a GNU-plottable file representing the buildings deployed in the scenario.
static Ptr< ThreeGppSpectrumPropagationLossModel > m_spectrumLossModel
the SpectrumPropagationLossModel object