A Discrete-Event Network Simulator
API
tv-trans-regional-example.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
18  */
19 
20 #include <ns3/core-module.h>
21 #include <ns3/mobility-module.h>
22 #include <ns3/spectrum-analyzer-helper.h>
23 #include <ns3/spectrum-helper.h>
24 #include <ns3/tv-spectrum-transmitter-helper.h>
25 
26 #include <iostream>
27 #include <stdlib.h>
28 
29 using namespace ns3;
30 
42 int
43 main(int argc, char** argv)
44 {
45  CommandLine cmd(__FILE__);
46  cmd.Parse(argc, argv);
47 
48  /* random seed and run number; adjust these to change random draws */
51 
52  /* nodes and positions */
53  NodeContainer spectrumAnalyzerNodes;
54  spectrumAnalyzerNodes.Create(1);
56  Ptr<ListPositionAllocator> nodePositionList = CreateObject<ListPositionAllocator>();
57  Vector coordinates =
59  2.35,
60  0,
62  nodePositionList->Add(coordinates); // spectrum analyzer
63  mobility.SetPositionAllocator(nodePositionList);
64  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
65  mobility.Install(spectrumAnalyzerNodes);
66 
67  /* channel and propagation */
69  channelHelper.SetChannel("ns3::MultiModelSpectrumChannel");
70  Ptr<SpectrumChannel> channel = channelHelper.Create();
71 
72  /* TV transmitter setup */
73  TvSpectrumTransmitterHelper tvTransHelper;
74  tvTransHelper.SetChannel(channel);
75  tvTransHelper.SetAttribute("StartingTime", TimeValue(Seconds(0.1)));
76  tvTransHelper.SetAttribute("TransmitDuration", TimeValue(Seconds(0.1)));
77  // 7.96 dBm/Hz from 50 kW ERP transmit power, flat 8 MHz PSD spectrum assumed for this
78  // approximation
79  tvTransHelper.SetAttribute("BasePsd", DoubleValue(7.96));
81  tvTransHelper.SetAttribute("Antenna", StringValue("ns3::IsotropicAntennaModel"));
82 
83  tvTransHelper.AssignStreams(300);
86  48.86,
87  2.35,
88  0,
89  250000);
90 
91  /* frequency range for spectrum analyzer */
92  std::vector<double> freqs;
93  for (int i = 0; i < 6860; i = i + 5)
94  {
95  freqs.push_back((i + 1740) * 1e5);
96  }
97  Ptr<SpectrumModel> spectrumAnalyzerFreqModel = Create<SpectrumModel>(freqs);
98 
99  /* spectrum analyzer setup */
100  SpectrumAnalyzerHelper spectrumAnalyzerHelper;
101  spectrumAnalyzerHelper.SetChannel(channel);
102  spectrumAnalyzerHelper.SetRxSpectrumModel(spectrumAnalyzerFreqModel);
103  spectrumAnalyzerHelper.SetPhyAttribute("NoisePowerSpectralDensity",
104  DoubleValue(4.14e-21)); // approx -174 dBm/Hz
105  spectrumAnalyzerHelper.EnableAsciiAll("spectrum-analyzer-tv-sim-regional");
106  NetDeviceContainer spectrumAnalyzerDevices =
107  spectrumAnalyzerHelper.Install(spectrumAnalyzerNodes);
108 
109  Simulator::Stop(Seconds(0.4));
110 
111  Simulator::Run();
112 
114 
115  std::cout << "simulation done!" << std::endl;
116  std::cout << "see spectrum analyzer output file" << std::endl;
117 
118  return 0;
119 }
Parse command-line arguments.
Definition: command-line.h:232
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:62
static Vector GeographicToCartesianCoordinates(double latitude, double longitude, double altitude, EarthSpheroidType sphType)
Converts earth geographic/geodetic coordinates (latitude and longitude in degrees) with a given altit...
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Class to allow the Spectrum Analysis.
NetDeviceContainer Install(NodeContainer c) const
void SetPhyAttribute(std::string name, const AttributeValue &v)
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper.
void EnableAsciiAll(std::string prefix)
Enable ASCII output.
void SetRxSpectrumModel(Ptr< SpectrumModel > m)
Set the spectrum model used by the created SpectrumAnalyzer instances to represent incoming signals.
Setup a SpectrumChannel.
Ptr< SpectrumChannel > Create() const
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
void SetChannel(std::string type, Ts &&... args)
Hold variables of type string.
Definition: string.h:56
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
void SetChannel(Ptr< SpectrumChannel > c)
Set the spectrum channel for the device(s) to transmit on.
int64_t AssignStreams(int64_t streamNum)
Assigns the stream number for the uniform random number generator to use.
void CreateRegionalTvTransmitters(Region region, Density density, double originLatitude, double originLongitude, double maxAltitude, double maxRadius)
Generates and installs (starts transmission on the spectrum channel) a random number of TV transmitte...
void SetAttribute(std::string name, const AttributeValue &val)
Set attribute for each TvSpectrumTransmitter instance to be created.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:40
channel
Definition: third.py:88
mobility
Definition: third.py:105