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  CommandLine cmd (__FILE__);
45  cmd.Parse (argc, argv);
46 
47  /* nodes and positions */
48  NodeContainer tvTransmitterNodes;
49  NodeContainer spectrumAnalyzerNodes;
50  NodeContainer allNodes;
51  tvTransmitterNodes.Create (2);
52  spectrumAnalyzerNodes.Create (1);
53  allNodes.Add (tvTransmitterNodes);
54  allNodes.Add (spectrumAnalyzerNodes);
56  Ptr<ListPositionAllocator> nodePositionList = CreateObject<ListPositionAllocator> ();
57  nodePositionList->Add (Vector (128000.0, 0.0, 0.0)); // TV Transmitter 1; 128 km away from spectrum analyzer
58  nodePositionList->Add (Vector (0.0, 24000.0, 0.0)); // TV Transmitter 2; 24 km away from spectrum analyzer
59  nodePositionList->Add (Vector (0.0, 0.0, 0.0)); // Spectrum Analyzer
60  mobility.SetPositionAllocator (nodePositionList);
61  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
62  mobility.Install (allNodes);
63 
64  /* channel and propagation */
66  channelHelper.SetChannel ("ns3::MultiModelSpectrumChannel");
67  // constant path loss added just to show capability to set different propagation loss models
68  // FriisSpectrumPropagationLossModel already added by default in SpectrumChannelHelper
69  channelHelper.AddSpectrumPropagationLoss ("ns3::ConstantSpectrumPropagationLossModel");
70  Ptr<SpectrumChannel> channel = channelHelper.Create ();
71 
72  /* TV transmitter setup */
73  TvSpectrumTransmitterHelper tvTransHelper;
74  tvTransHelper.SetChannel (channel);
75  tvTransHelper.SetAttribute ("StartFrequency", DoubleValue (524e6));
76  tvTransHelper.SetAttribute ("ChannelBandwidth", DoubleValue (6e6));
77  tvTransHelper.SetAttribute ("StartingTime", TimeValue (Seconds (0)));
78  tvTransHelper.SetAttribute ("TransmitDuration", TimeValue (Seconds (0.2)));
79  // 22.22 dBm/Hz from 1000 kW ERP transmit power, flat 6 MHz PSD spectrum assumed for this approximation
80  tvTransHelper.SetAttribute ("BasePsd", DoubleValue (22.22));
81  tvTransHelper.SetAttribute ("TvType", EnumValue (TvSpectrumTransmitter::TVTYPE_8VSB));
82  tvTransHelper.SetAttribute ("Antenna", StringValue ("ns3::IsotropicAntennaModel"));
83  tvTransHelper.InstallAdjacent (tvTransmitterNodes);
84 
85  /* frequency range for spectrum analyzer */
86  std::vector<double> freqs;
87  for (int i = 0; i < 200; ++i)
88  {
89  freqs.push_back ((i + 5200) * 1e5);
90  }
91  Ptr<SpectrumModel> spectrumAnalyzerFreqModel = Create<SpectrumModel> (freqs);
92 
93  /* spectrum analyzer setup */
94  SpectrumAnalyzerHelper spectrumAnalyzerHelper;
95  spectrumAnalyzerHelper.SetChannel (channel);
96  spectrumAnalyzerHelper.SetRxSpectrumModel (spectrumAnalyzerFreqModel);
97  spectrumAnalyzerHelper.SetPhyAttribute ("NoisePowerSpectralDensity", DoubleValue (1e-15)); // -120 dBm/Hz
98  spectrumAnalyzerHelper.EnableAsciiAll ("spectrum-analyzer-tv-sim");
99  NetDeviceContainer spectrumAnalyzerDevices = spectrumAnalyzerHelper.Install (spectrumAnalyzerNodes);
100 
101  Simulator::Stop (Seconds (0.4));
102 
103  Simulator::Run ();
104 
106 
107  std::cout << "simulation done!" << std::endl;
108  std::cout << "see spectrum analyzer output file" << std::endl;
109 
110  return 0;
111 }
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
ns3::SpectrumAnalyzerHelper::SetPhyAttribute
void SetPhyAttribute(std::string name, const AttributeValue &v)
Definition: spectrum-analyzer-helper.cc:104
ns3::CommandLine
Parse command-line arguments.
Definition: command-line.h:228
ns3::ListPositionAllocator::Add
void Add(Vector v)
Add a position to the list of positions.
Definition: position-allocator.cc:70
ns3::SpectrumChannelHelper::SetChannel
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())
Definition: spectrum-helper.cc:45
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::SpectrumAnalyzerHelper::Install
NetDeviceContainer Install(NodeContainer c) const
Definition: spectrum-analyzer-helper.cc:160
third.channel
channel
Definition: third.py:92
ns3::TvSpectrumTransmitterHelper
Helper class which uses TvSpectrumTransmitter class to create customizable TV transmitter(s) that tra...
Definition: tv-spectrum-transmitter-helper.h:68
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition: node-container.cc:98
ns3::EnumValue
Hold variables of type enum.
Definition: enum.h:55
ns3::NodeContainer::Add
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Definition: node-container.cc:114
ns3::SpectrumChannelHelper::Create
Ptr< SpectrumChannel > Create(void) const
Definition: spectrum-helper.cc:157
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::SpectrumAnalyzerHelper
Class to allow the Spectrum Analysis.
Definition: spectrum-analyzer-helper.h:45
ns3::Simulator::Stop
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
ns3::TvSpectrumTransmitterHelper::SetAttribute
void SetAttribute(std::string name, const AttributeValue &val)
Set attribute for each TvSpectrumTransmitter instance to be created.
Definition: tv-spectrum-transmitter-helper.cc:121
ns3::TvSpectrumTransmitter::TVTYPE_8VSB
@ TVTYPE_8VSB
Definition: tv-spectrum-transmitter.h:56
ns3::SpectrumAnalyzerHelper::EnableAsciiAll
void EnableAsciiAll(std::string prefix)
Enable ASCII output.
Definition: spectrum-analyzer-helper.cc:151
second.cmd
cmd
Definition: second.py:35
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::SpectrumAnalyzerHelper::SetRxSpectrumModel
void SetRxSpectrumModel(Ptr< SpectrumModel > m)
Set the spectrum model used by the created SpectrumAnalyzer instances to represent incoming signals.
Definition: spectrum-analyzer-helper.cc:144
ns3::SpectrumChannelHelper::AddSpectrumPropagationLoss
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())
Definition: spectrum-helper.cc:101
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::TvSpectrumTransmitterHelper::InstallAdjacent
NetDeviceContainer InstallAdjacent(NodeContainer nodes)
Set up and start the TV Transmitter's transmission on the spectrum channel.
Definition: tv-spectrum-transmitter-helper.cc:228
ns3::TimeValue
AttributeValue implementation for Time.
Definition: nstime.h:1353
ns3::TvSpectrumTransmitterHelper::SetChannel
void SetChannel(Ptr< SpectrumChannel > c)
Set the spectrum channel for the device(s) to transmit on.
Definition: tv-spectrum-transmitter-helper.cc:114
ns3::NodeContainer
keep track of a set of node pointers.
Definition: node-container.h:39
ns3::SpectrumAnalyzerHelper::SetChannel
void SetChannel(Ptr< SpectrumChannel > channel)
Set the SpectrumChannel that will be used by SpectrumPhy instances created by this helper.
Definition: spectrum-analyzer-helper.cc:88
ns3::SpectrumChannelHelper
Setup a SpectrumChannel.
Definition: spectrum-helper.h:45
ns3::SpectrumChannelHelper::Default
static SpectrumChannelHelper Default()
Setup a default SpectrumChannel.
Definition: spectrum-helper.cc:35
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition: mobility-helper.h:43
third.mobility
mobility
Definition: third.py:108