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/three-gpp-antenna-array-model.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" 73 Angles completeAngle (bPos,aPos);
75 double hAngleRadian = fmod (completeAngle.
phi, 2.0 * M_PI);
78 hAngleRadian += 2.0 * M_PI;
80 double vAngleRadian = completeAngle.
theta;
86 double power = 1 / sqrt (totNoArrayElements);
89 for (
int ind = 0; ind < totNoArrayElements; ind++)
92 double phase = -2 * M_PI * (sin (vAngleRadian) * cos (hAngleRadian) * loc.x
93 + sin (vAngleRadian) * sin (hAngleRadian) * loc.y
94 + cos (vAngleRadian) * loc.z);
95 antennaWeights.push_back (exp (std::complex<double> (0, phase)) * power);
119 NS_LOG_DEBUG (
"Pathloss " << -propagationGainDb <<
" dB");
120 double propagationGainLinear = std::pow (10.0, (propagationGainDb) / 10.0);
121 *(rxPsd) *= propagationGainLinear;
125 NS_LOG_DEBUG (
"Average rx power " << 10 * log10 (
Sum (*rxPsd) * 180e3) <<
" dB");
129 const double kT_dBm_Hz = -174.0;
130 double kT_W_Hz = std::pow (10.0, (kT_dBm_Hz - 30) / 10.0);
131 double noiseFigureLinear = std::pow (10.0, noiseFigure / 10.0);
132 double noisePowerSpectralDensity = kT_W_Hz * noiseFigureLinear;
134 (*noisePsd) = noisePowerSpectralDensity;
137 NS_LOG_DEBUG (
"Average SNR " << 10 * log10 (
Sum (*rxPsd) /
Sum (*noisePsd)) <<
" dB");
141 f.open (
"example-output.txt", std::ios::out | std::ios::app);
148 << 10 * log10 (
Sum (*rxPsd) /
Sum (*noisePsd)) <<
" " 149 << -propagationGainDb << std::endl;
161 std::ofstream outFile;
162 outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
163 if (!outFile.is_open ())
172 Box box = (*it)->GetBoundaries ();
173 outFile <<
"set object " << index
174 <<
" rect from " << box.
xMin <<
"," << box.
yMin 175 <<
" to " << box.
xMax <<
"," << box.
yMax 181 main (
int argc,
char *argv[])
183 double frequency = 28.0e9;
184 double txPow_dbm = 30.0;
185 double noiseFigure = 9.0;
188 std::string scenario =
"V2V-Urban";
190 double subCarrierSpacing = 60e3;
191 uint32_t numRb = 275;
194 cmd.AddValue (
"frequency",
"operating frequency in Hz", frequency);
195 cmd.AddValue (
"txPow",
"tx power in dBm", txPow_dbm);
196 cmd.AddValue (
"noiseFigure",
"noise figure in dB", noiseFigure);
197 cmd.AddValue (
"scenario",
"3GPP propagation scenario, V2V-Urban or V2V-Highway", scenario);
198 cmd.Parse (argc, argv);
209 nodes.Get (0)->AddDevice (txDev);
211 nodes.Get (1)->AddDevice (rxDev);
212 rxDev->SetNode (
nodes.Get (1));
220 if (scenario ==
"V2V-Urban")
226 double buildingSizeX = 250 - 3.5 * 2 - 3;
227 double buildingSizeY = 433 - 3.5 * 2 - 3;
228 double streetWidth = 20;
229 double buildingHeight = 10;
230 uint32_t numBuildingsX = 2;
231 uint32_t numBuildingsY = 2;
232 double maxAxisX = (buildingSizeX + streetWidth) * numBuildingsX;
233 double maxAxisY = (buildingSizeY + streetWidth) * numBuildingsY;
235 std::vector<Ptr<Building> > buildingVector;
236 for (uint32_t buildingIdX = 0; buildingIdX < numBuildingsX; ++buildingIdX)
238 for (uint32_t buildingIdY = 0; buildingIdY < numBuildingsY; ++buildingIdY)
241 building = CreateObject<Building> ();
244 buildingIdX * (buildingSizeX + streetWidth) + buildingSizeX,
245 buildingIdY * (buildingSizeY + streetWidth),
246 buildingIdY * (buildingSizeY + streetWidth) + buildingSizeY,
247 0.0, buildingHeight));
251 buildingVector.push_back (building);
257 double vRx = vScatt / 2;
258 txMob = CreateObject<WaypointMobilityModel> ();
259 rxMob = CreateObject<WaypointMobilityModel> ();
262 nextWaypoint +=
Seconds ((maxAxisY - streetWidth) / 2 / vTx);
263 txMob->GetObject<
WaypointMobilityModel> ()->AddWaypoint (
Waypoint (nextWaypoint, Vector (maxAxisX / 2 - streetWidth / 2, maxAxisY / 2 - streetWidth / 2, 1.5)));
264 nextWaypoint +=
Seconds ((maxAxisX - streetWidth) / 2 / vTx);
268 nextWaypoint +=
Seconds (maxAxisY / vRx);
271 nodes.Get (0)->AggregateObject (txMob);
272 nodes.Get (1)->AggregateObject (rxMob);
275 m_condModel = CreateObject<ThreeGppV2vUrbanChannelConditionModel> ();
280 else if (scenario ==
"V2V-Highway")
288 double vRx = vScatt / 2;
290 txMob = CreateObject<ConstantVelocityMobilityModel> ();
291 rxMob = CreateObject<ConstantVelocityMobilityModel> ();
297 nodes.Get (0)->AggregateObject (txMob);
298 nodes.Get (1)->AggregateObject (rxMob);
301 m_condModel = CreateObject<ThreeGppV2vHighwayChannelConditionModel> ();
339 double freqSubBand = frequency;
340 for (uint16_t
n = 0;
n < numRb; ++
n)
344 freqSubBand += subCarrierSpacing / 2;
346 freqSubBand += subCarrierSpacing / 2;
352 double txPow_w = std::pow (10., (txPow_dbm - 30) / 10);
353 double txPowDens = (txPow_w / (numRb * subCarrierSpacing));
354 (*txPsd) = txPowDens;
356 for (
int i = 0; i < simTime / timeRes; i++)
363 f.open (
"example-output.txt", std::ios::out);
364 f <<
"Time[s] TxPosX[m] TxPosY[m] RxPosX[m] RxPosY[m] ChannelState SNR[dB] Pathloss[dB]" << std::endl;
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
virtual uint64_t GetNumberOfElements(void) const
Returns the number of antenna elements.
Simulation virtual time values and global simulation resolution.
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...
AttributeValue implementation for Boolean.
void SetNRoomsY(uint16_t nroomy)
std::vector< std::complex< double > > ComplexVector
type definition for complex vectors
Hold variables of type string.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
static void Run(void)
Run the simulation.
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.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
static Iterator End(void)
double theta
the inclination angle in radians
LosConditionValue GetLosCondition() const
Get the LosConditionValue contaning the information about the LOS/NLOS state of the channel...
double xMax
The x coordinate of the right bound of the box.
static Iterator Begin(void)
static void ComputeSnr(Ptr< MobilityModel > txMob, Ptr< MobilityModel > rxMob, Ptr< const SpectrumValue > txPsd, double noiseFigure)
Compute the average SNR.
static Vector GetPosition(Ptr< Node > node)
std::vector< BandInfo > Bands
Container of BandInfo.
static void SetPosition(Ptr< Node > node, Vector position)
virtual Vector GetElementLocation(uint64_t index) const
Returns the location of the antenna element with the specified index assuming the left bottom corner ...
double yMax
The y coordinate of the top bound of the box.
Keep track of the current position and velocity of an object.
virtual void SetNode(Ptr< Node > node)
AttributeValue implementation for Time.
void PrintGnuplottableBuildingListToFile(std::string filename)
Generates a GNU-plottable file representig the buildings deployed in the scenario.
Hold an unsigned integer type.
void SetNFloors(uint16_t nfloors)
double fc
center frequency
std::vector< Ptr< Building > >::const_iterator Iterator
static Ptr< ChannelConditionModel > m_condModel
the ChannelConditionModel object
double yMin
The y coordinate of the bottom bound of the box.
Parse command-line arguments.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Ptr< SpectrumValue > Copy() const
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.
double f(double x, void *params)
static void DoBeamforming(Ptr< NetDevice > thisDevice, Ptr< ThreeGppAntennaArrayModel > thisAntenna, Ptr< NetDevice > otherDevice)
Perform the beamforming using the DFT beamforming method.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double fl
lower limit of subband
keep track of a set of node pointers.
Hold objects of type Ptr<T>.
Ptr< const SpectrumModel > GetSpectrumModel() const
static Time Now(void)
Return the current simulation virtual time.
Vector GetPosition(void) const
static Ptr< ThreeGppSpectrumPropagationLossModel > m_spectrumLossModel
the SpectrumPropagationLossModel object
#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.
double phi
the azimuth angle in radians
double Sum(const SpectrumValue &x)
Waypoint-based mobility model.
void SetNRoomsX(uint16_t nroomx)
Mobility model for which the current speed does not change once it has been set and until it is set a...
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
struct holding the azimuth and inclination angles of spherical coordinates.
double fh
upper limit of subband
This class can be used to hold variables of floating point type such as 'double' or 'float'...
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
The building block of a SpectrumModel.
void SetBoundaries(Box box)
Set the boundaries of the building.
static Ptr< ThreeGppPropagationLossModel > m_propagationLossModel
the PropagationLossModel object
double xMin
The x coordinate of the left bound of the box.
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.