A Discrete-Event Network Simulator
API
tv-trans-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 {
44  /* nodes and positions */
45  NodeContainer tvTransmitterNodes;
46  NodeContainer spectrumAnalyzerNodes;
47  NodeContainer allNodes;
48  tvTransmitterNodes.Create (2);
49  spectrumAnalyzerNodes.Create (1);
50  allNodes.Add (tvTransmitterNodes);
51  allNodes.Add (spectrumAnalyzerNodes);
53  Ptr<ListPositionAllocator> nodePositionList = CreateObject<ListPositionAllocator> ();
54  nodePositionList->Add (Vector (128000.0, 0.0, 0.0)); // TV Transmitter 1; 128 km away from spectrum analyzer
55  nodePositionList->Add (Vector (0.0, 24000.0, 0.0)); // TV Transmitter 2; 24 km away from spectrum analyzer
56  nodePositionList->Add (Vector (0.0, 0.0, 0.0)); // Spectrum Analyzer
57  mobility.SetPositionAllocator (nodePositionList);
58  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
59  mobility.Install (allNodes);
60 
61  /* channel and propagation */
63  channelHelper.SetChannel ("ns3::MultiModelSpectrumChannel");
64  // constant path loss added just to show capability to set different propagation loss models
65  // FriisSpectrumPropagationLossModel already added by default in SpectrumChannelHelper
66  channelHelper.AddSpectrumPropagationLoss ("ns3::ConstantSpectrumPropagationLossModel");
67  Ptr<SpectrumChannel> channel = channelHelper.Create ();
68 
69  /* TV transmitter setup */
70  TvSpectrumTransmitterHelper tvTransHelper;
71  tvTransHelper.SetChannel (channel);
72  tvTransHelper.SetAttribute ("StartFrequency", DoubleValue (524e6));
73  tvTransHelper.SetAttribute ("ChannelBandwidth", DoubleValue (6e6));
74  tvTransHelper.SetAttribute ("StartingTime", TimeValue (Seconds (0)));
75  tvTransHelper.SetAttribute ("TransmitDuration", TimeValue (Seconds (0.2)));
76  // 22.22 dBm/Hz from 1000 kW ERP transmit power, flat 6 MHz PSD spectrum assumed for this approximation
77  tvTransHelper.SetAttribute ("BasePsd", DoubleValue (22.22));
78  tvTransHelper.SetAttribute ("TvType", EnumValue (TvSpectrumTransmitter::TVTYPE_8VSB));
79  tvTransHelper.SetAttribute ("Antenna", StringValue ("ns3::IsotropicAntennaModel"));
80  tvTransHelper.InstallAdjacent (tvTransmitterNodes);
81 
82  /* frequency range for spectrum analyzer */
83  std::vector<double> freqs;
84  for (int i = 0; i < 200; ++i)
85  {
86  freqs.push_back ((i + 5200) * 1e5);
87  }
88  Ptr<SpectrumModel> spectrumAnalyzerFreqModel = Create<SpectrumModel> (freqs);
89 
90  /* spectrum analyzer setup */
91  SpectrumAnalyzerHelper spectrumAnalyzerHelper;
92  spectrumAnalyzerHelper.SetChannel (channel);
93  spectrumAnalyzerHelper.SetRxSpectrumModel (spectrumAnalyzerFreqModel);
94  spectrumAnalyzerHelper.SetPhyAttribute ("NoisePowerSpectralDensity", DoubleValue (1e-15)); // -120 dBm/Hz
95  spectrumAnalyzerHelper.EnableAsciiAll ("spectrum-analyzer-tv-sim");
96  NetDeviceContainer spectrumAnalyzerDevices = spectrumAnalyzerHelper.Install (spectrumAnalyzerNodes);
97 
98  Simulator::Stop (Seconds (0.4));
99 
100  Simulator::Run ();
101 
103 
104  std::cout << "simulation done!" << std::endl;
105  std::cout << "see spectrum analyzer output file" << std::endl;
106 
107  return 0;
108 }
Class to allow the Spectrum Analysis.
tuple channel
Definition: third.py:85
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:200
Ptr< SpectrumChannel > Create(void) const
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
Hold variables of type enum.
Definition: enum.h:54
AttributeValue implementation for Time.
Definition: nstime.h:957
holds a vector of ns3::NetDevice pointers
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:164
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetMobilityModel(std::string type, 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(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
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())
NetDeviceContainer InstallAdjacent(NodeContainer nodes)
Set up and start the TV Transmitter's transmission on the spectrum channel.
void AddSpectrumPropagationLoss(std::string name, 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())
Helper class used to assign positions and mobility models to nodes.
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:208
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
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.
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.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
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.