A Discrete-Event Network Simulator
API
tv-trans-regional-example.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Benjamin Cizdziel <ben.cizdziel@gmail.com>
19  */
20 
21 #include <iostream>
22 #include <stdlib.h>
23 #include <ns3/core-module.h>
24 #include <ns3/mobility-module.h>
25 #include <ns3/spectrum-helper.h>
26 #include <ns3/spectrum-analyzer-helper.h>
27 #include <ns3/tv-spectrum-transmitter-helper.h>
28 
29 using namespace ns3;
30 
42 int main (int argc, char** argv)
43 {
45  cmd.Parse (argc, argv);
46 
47  /* random seed and run number; adjust these to change random draws */
50 
51  /* nodes and positions */
52  NodeContainer spectrumAnalyzerNodes;
53  spectrumAnalyzerNodes.Create (1);
55  Ptr<ListPositionAllocator> nodePositionList = CreateObject<ListPositionAllocator> ();
56  Vector coordinates = GeographicPositions::GeographicToCartesianCoordinates (48.86,
57  2.35,
58  0,
60  nodePositionList->Add (coordinates); // spectrum analyzer
61  mobility.SetPositionAllocator (nodePositionList);
62  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
63  mobility.Install (spectrumAnalyzerNodes);
64 
65  /* channel and propagation */
67  channelHelper.SetChannel ("ns3::MultiModelSpectrumChannel");
68  Ptr<SpectrumChannel> channel = channelHelper.Create ();
69 
70  /* TV transmitter setup */
71  TvSpectrumTransmitterHelper tvTransHelper;
72  tvTransHelper.SetChannel (channel);
73  tvTransHelper.SetAttribute ("StartingTime", TimeValue (Seconds (0.1)));
74  tvTransHelper.SetAttribute ("TransmitDuration", TimeValue (Seconds (0.1)));
75  // 7.96 dBm/Hz from 50 kW ERP transmit power, flat 8 MHz PSD spectrum assumed for this approximation
76  tvTransHelper.SetAttribute ("BasePsd", DoubleValue (7.96));
78  tvTransHelper.SetAttribute ("Antenna", StringValue ("ns3::IsotropicAntennaModel"));
79 
80  tvTransHelper.AssignStreams (300);
83  48.86,
84  2.35,
85  0,
86  250000);
87 
88  /* frequency range for spectrum analyzer */
89  std::vector<double> freqs;
90  for (int i = 0; i < 6860; i = i + 5)
91  {
92  freqs.push_back ((i + 1740) * 1e5);
93  }
94  Ptr<SpectrumModel> spectrumAnalyzerFreqModel = Create<SpectrumModel> (freqs);
95 
96  /* spectrum analyzer setup */
97  SpectrumAnalyzerHelper spectrumAnalyzerHelper;
98  spectrumAnalyzerHelper.SetChannel (channel);
99  spectrumAnalyzerHelper.SetRxSpectrumModel (spectrumAnalyzerFreqModel);
100  spectrumAnalyzerHelper.SetPhyAttribute ("NoisePowerSpectralDensity", DoubleValue (4.14e-21)); // approx -174 dBm/Hz
101  spectrumAnalyzerHelper.EnableAsciiAll ("spectrum-analyzer-tv-sim-regional");
102  NetDeviceContainer spectrumAnalyzerDevices = spectrumAnalyzerHelper.Install (spectrumAnalyzerNodes);
103 
104  Simulator::Stop (Seconds (0.4));
105 
106  Simulator::Run ();
107 
109 
110  std::cout << "simulation done!" << std::endl;
111  std::cout << "see spectrum analyzer output file" << std::endl;
112 
113  return 0;
114 }
Class to allow the Spectrum Analysis.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
Hold variables of type string.
Definition: string.h:41
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
cmd
Definition: second.py:35
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...
static void SetRun(uint64_t run)
Set the run number of simulation.
channel
Definition: third.py:85
mobility
Definition: third.py:101
Hold variables of type enum.
Definition: enum.h:54
AttributeValue implementation for Time.
Definition: nstime.h:1076
holds a vector of ns3::NetDevice pointers
Parse command-line arguments.
Definition: command-line.h:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
int64_t AssignStreams(int64_t streamNum)
Assigns the stream number for the uniform random number generator to use.
void SetChannel(std::string type, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
static void SetSeed(uint32_t seed)
Set the seed.
Helper class used to assign positions and mobility models to nodes.
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
void Add(Vector v)
Add a position to the list of positions.
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...
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Setup a SpectrumChannel.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &val)
Set attribute for each TvSpectrumTransmitter instance to be created.
void SetChannel(Ptr< SpectrumChannel > c)
Set the spectrum channel for the device(s) to transmit on.
Ptr< SpectrumChannel > Create(void) const