sat-link-budget-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 Magister Solutions
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: Sami Rantanen <sami.rantanen@magister.fi>
19  *
20  */
21 
22 #include "ns3/applications-module.h"
23 #include "ns3/config-store-module.h"
24 #include "ns3/core-module.h"
25 #include "ns3/internet-module.h"
26 #include "ns3/network-module.h"
27 #include "ns3/satellite-module.h"
28 #include "ns3/traffic-module.h"
29 
30 using namespace ns3;
31 
50 NS_LOG_COMPONENT_DEFINE("sat-link-budget-example");
51 
52 // callback called when packet is received by phy RX carrier
53 static void
54 LinkBudgetTraceCb(std::string context,
55  Ptr<SatSignalParameters> params,
56  Mac48Address ownAdd,
57  Mac48Address destAdd,
58  double ifPower,
59  double cSinr)
60 {
61  // print only unicast message to prevent printing control messages like TBTP messages
62  if (!destAdd.IsBroadcast())
63  {
64  NS_LOG_INFO("" << params->m_channelType << " " << ownAdd << " " << destAdd << " "
65  << params->m_beamId << " " << params->m_carrierFreq_hz << " "
66  << SatUtils::WToDbW(ifPower) << " " << SatUtils::WToDbW(params->m_rxPower_W)
67  << " " << SatUtils::LinearToDb(params->GetSinr()) << " "
68  << SatUtils::LinearToDb(cSinr));
69  }
70 }
71 
72 int
73 main(int argc, char* argv[])
74 {
75  uint32_t beamId = 11;
76  double latitude = 50.00;
77  double longitude = -1.00;
78  double altitude = 0.00;
79 
81  auto simulationHelper = CreateObject<SimulationHelper>("example-link-budget");
82  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
83  std::string inputFileNameWithPath =
84  Singleton<SatEnvVariables>::Get()->LocateDirectory("contrib/satellite/examples") +
85  "/sat-link-budget-input-attributes.xml";
86 
87  // read command line parameters can be given by user
88  CommandLine cmd;
89  cmd.AddValue("beam", "Beam to use for testing. (1 - 72)", beamId);
90  cmd.AddValue("latitude", "Latitude of UT position (-90 ... 90.0)", latitude);
91  cmd.AddValue("longitude", "Longitude of UT position (-180 ... 180)", longitude);
92  cmd.AddValue("altitude", "Altitude of UT position (meters)", altitude);
93  simulationHelper->AddDefaultUiArguments(cmd, inputFileNameWithPath);
94  cmd.Parse(argc, argv);
95 
96  // To change attributes having affect on link budget,
97  // modify attributes available in sat-link-budget-input-attributes.xml found in same directory
98  // this source file
99  Config::SetDefault("ns3::ConfigStore::Filename", StringValue(inputFileNameWithPath));
100  Config::SetDefault("ns3::ConfigStore::Mode", StringValue("Load"));
101  Config::SetDefault("ns3::ConfigStore::FileFormat", StringValue("Xml"));
102  ConfigStore inputConfig;
103  inputConfig.ConfigureDefaults();
104 
105  simulationHelper->SetUtCountPerBeam(1);
106  simulationHelper->SetUserCountPerUt(1);
107  simulationHelper->SetBeamSet({beamId});
108  simulationHelper->SetSimulationTime(Seconds(1.1));
109 
110  // enable info logs
111  LogComponentEnable("sat-link-budget-example", LOG_LEVEL_INFO);
112 
113  // Create a position allocator for our single UT
114  Ptr<SatListPositionAllocator> posAllocator = CreateObject<SatListPositionAllocator>();
115  posAllocator->Add(GeoCoordinate(latitude, longitude, altitude));
116  simulationHelper->SetUtPositionAllocatorForBeam(beamId, posAllocator);
117 
118  // Creating the reference system. Note, currently the satellite module supports
119  // only one reference system, which is named as "Scenario72". The string is utilized
120  // in mapping the scenario to the needed reference system configuration files. Arbitrary
121  // scenario name results in fatal error.
122  Ptr<SatHelper> helper = simulationHelper->CreateSatScenario();
123 
124  // set callback traces where we want results out
125  Config::Connect("/NodeList/*/DeviceList/*/SatPhy/PhyRx/RxCarrierList/*/LinkBudgetTrace",
126  MakeCallback(&LinkBudgetTraceCb));
127 
128  Config::Connect("/NodeList/*/DeviceList/*/UserPhy/*/PhyRx/RxCarrierList/*/LinkBudgetTrace",
129  MakeCallback(&LinkBudgetTraceCb));
130 
131  Config::Connect("/NodeList/*/DeviceList/*/FeederPhy/*/PhyRx/RxCarrierList/*/LinkBudgetTrace",
132  MakeCallback(&LinkBudgetTraceCb));
133  // Set UT position
134  NodeContainer ut = helper->UtNodes();
135  Ptr<SatMobilityModel> utMob = ut.Get(0)->GetObject<SatMobilityModel>();
136 
137  // Install CBR traffic model
138  Config::SetDefault("ns3::CbrApplication::Interval", StringValue("0.1s"));
139  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(512));
140  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
143  Seconds(0.1),
144  Seconds(0.25));
145 
146  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
149  Seconds(0.1),
150  Seconds(0.25));
151 
152  NodeContainer gw = helper->GwNodes();
153  Ptr<SatMobilityModel> gwMob = gw.Get(0)->GetObject<SatMobilityModel>();
154 
155  Ptr<Node> geo = helper->GeoSatNodes().Get(0);
156  Ptr<SatMobilityModel> geoMob = geo->GetObject<SatMobilityModel>();
157 
158  // print used parameters using log info
159  NS_LOG_INFO("--- satellite-link-budget-example ---");
160  NS_LOG_INFO(" Beam ID: " << beamId);
161  NS_LOG_INFO(" Geo position: " << geoMob->GetGeoPosition() << " " << geoMob->GetPosition());
162  NS_LOG_INFO(" GW position: " << gwMob->GetGeoPosition() << " " << gwMob->GetPosition());
163  NS_LOG_INFO(" UT position: " << utMob->GetGeoPosition() << " " << utMob->GetPosition());
164  NS_LOG_INFO(" ");
165  NS_LOG_INFO("Link results (Time, Channel type, Own address, Dest. address, Beam ID, Carrier "
166  "Center freq, IF Power, RX Power, SINR, Composite SINR) :");
167  // results are printed out in callback (LinkBudgetTraceCb)
168 
169  simulationHelper->RunSimulation();
170 
171  return 0;
172 }
GeoCoordinate class is used to store and operate with geodetic coordinates.
Keep track of the current position and velocity of an object in satellite network.
static T WToDbW(T w)
Converts Watts to Decibel Watts.
static T LinearToDb(T linear)
Converts linear to decibels.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.