sat-list-position-ext-fading-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 
56 NS_LOG_COMPONENT_DEFINE("sat-list-position-ext-fading-example");
57 
58 // callback called when packet is received by phy RX carrier
59 static void
60 LinkBudgetTraceCb(std::string context,
61  Ptr<SatSignalParameters> params,
62  Mac48Address ownAdd,
63  Mac48Address destAdd,
64  double ifPower,
65  double cSinr)
66 {
67  // print only unicast message to prevent printing control messages like TBTP messages
68  if (!destAdd.IsBroadcast())
69  {
70  NS_LOG_INFO("" << params->m_channelType << " " << ownAdd << " " << destAdd << " "
71  << params->m_beamId << " " << SatUtils::LinearToDb(params->GetSinr()) << " "
72  << SatUtils::LinearToDb(cSinr));
73  }
74 }
75 
76 int
77 main(int argc, char* argv[])
78 {
79  uint32_t utCount = 4;
80  uint32_t usersPerUt = 1;
81  uint32_t beamId = 1;
82  bool checkBeam = false;
83  std::string extUtPositions = "utpositions/BeamId-1_256_UT_Positions.txt";
84 
85  Config::SetDefault("ns3::SatHelper::ScenarioCreationTraceEnabled", BooleanValue(true));
86 
88  auto simulationHelper = CreateObject<SimulationHelper>("example-list-position-external-fading");
89  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
90 
91  // read command line parameters can be given by user
92  CommandLine cmd;
93  cmd.AddValue("beamId", "The beam ID to be used.", beamId);
94  cmd.AddValue("checkBeam",
95  "Check that given beam is the best according in the configured positions.",
96  checkBeam);
97  cmd.AddValue("utCount", "Number of the UTs.", utCount);
98  cmd.AddValue("usersPerUt", "Users per UT.", usersPerUt);
99  cmd.AddValue("externalUtPositionFile", "UT position input file (in data/)", extUtPositions);
100  simulationHelper->AddDefaultUiArguments(cmd);
101  cmd.Parse(argc, argv);
102 
103  // Set default values for some attributes for position setting and external fading trace
104  // This done before command line parsing in order to override them if needed
105 
106  simulationHelper->SetUserCountPerUt(usersPerUt);
107  simulationHelper->SetUtCountPerBeam(utCount);
108  simulationHelper->SetBeamSet({beamId});
109  simulationHelper->SetSimulationTime(Seconds(1.1));
110 
111  // Enable default fading traces
112  simulationHelper->EnableExternalFadingInputTrace();
113 
114  // Enable UT positions from input file
115  simulationHelper->EnableUtListPositionsFromInputFile(extUtPositions, checkBeam);
116 
117  // enable info logs
118  LogComponentEnable("sat-list-position-ext-fading-example", LOG_LEVEL_INFO);
119 
120  // Creating the reference system. Note, currently the satellite module supports
121  // only one reference system, which is named as "Scenario72". The string is utilized
122  // in mapping the scenario to the needed reference system configuration files. Arbitrary
123  // scenario name results in fatal error.
124  Ptr<SatHelper> helper = simulationHelper->CreateSatScenario();
125 
126  // set callback traces where we want results out
127  Config::Connect("/NodeList/*/DeviceList/*/SatPhy/PhyRx/RxCarrierList/*/LinkBudgetTrace",
128  MakeCallback(&LinkBudgetTraceCb));
129 
130  Config::Connect("/NodeList/*/DeviceList/*/UserPhy/*/PhyRx/RxCarrierList/*/LinkBudgetTrace",
131  MakeCallback(&LinkBudgetTraceCb));
132 
133  Config::Connect("/NodeList/*/DeviceList/*/FeederPhy/*/PhyRx/RxCarrierList/*/LinkBudgetTrace",
134  MakeCallback(&LinkBudgetTraceCb));
135 
136  // Install CBR traffic model
137  Config::SetDefault("ns3::CbrApplication::Interval", StringValue("0.1s"));
138  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(512));
139  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
142  Seconds(0.1),
143  Seconds(0.25));
144 
145  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
148  Seconds(0.1),
149  Seconds(0.25));
150 
151  NS_LOG_INFO("--- List Position External Fading Example ---");
152  NS_LOG_INFO("UT info (Beam ID, UT ID, Latitude, Longitude, Altitude + addresses");
153 
154  // print UT info
155  NS_LOG_INFO(helper->GetBeamHelper()->GetUtInfo());
156  NS_LOG_INFO("Link results (Time, Channel type, Own address, Dest. address, Beam ID, SINR, "
157  "Composite SINR) :");
158  // results are printed out in callback (PacketTraceCb)
159 
160  simulationHelper->RunSimulation();
161 
162  return 0;
163 }
static T LinearToDb(T linear)
Converts linear to decibels.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static void LinkBudgetTraceCb(std::string context, Ptr< SatSignalParameters > params, Mac48Address ownAdd, Mac48Address destAdd, double ifPower, double cSinr)