Loading...
Searching...
No Matches
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
30using namespace ns3;
31
49
50NS_LOG_COMPONENT_DEFINE("sat-link-budget-example");
51
52// callback called when packet is received by phy RX carrier
53static void
54LinkBudgetTraceCb(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
72int
73main(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 SatEnvVariables::GetInstance()->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 simulationHelper->LoadScenario("geo-33E");
119
120 // Creating the reference system.
121 simulationHelper->CreateSatScenario();
122
123 // set callback traces where we want results out
124 Config::Connect("/NodeList/*/DeviceList/*/SatPhy/PhyRx/RxCarrierList/*/LinkBudgetTrace",
125 MakeCallback(&LinkBudgetTraceCb));
126
127 Config::Connect("/NodeList/*/DeviceList/*/UserPhy/*/PhyRx/RxCarrierList/*/LinkBudgetTrace",
128 MakeCallback(&LinkBudgetTraceCb));
129
130 Config::Connect("/NodeList/*/DeviceList/*/FeederPhy/*/PhyRx/RxCarrierList/*/LinkBudgetTrace",
131 MakeCallback(&LinkBudgetTraceCb));
132 // Set UT position
133 Ptr<SatMobilityModel> utMob =
134 Singleton<SatTopology>::Get()->GetUtNode(0)->GetObject<SatMobilityModel>();
135
136 // Install CBR traffic model
137 simulationHelper->GetTrafficHelper()->AddCbrTraffic(
140 MilliSeconds(100),
141 512,
142 NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
143 Singleton<SatTopology>::Get()->GetUtUserNodes(),
144 Seconds(0.1),
145 Seconds(0.25),
146 Seconds(0));
147
148 simulationHelper->GetTrafficHelper()->AddCbrTraffic(
151 MilliSeconds(100),
152 512,
153 NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
154 Singleton<SatTopology>::Get()->GetUtUserNodes(),
155 Seconds(0.1),
156 Seconds(0.25),
157 Seconds(0));
158
159 Ptr<SatMobilityModel> gwMob =
160 Singleton<SatTopology>::Get()->GetGwNode(0)->GetObject<SatMobilityModel>();
161
162 Ptr<Node> sat = Singleton<SatTopology>::Get()->GetOrbiterNode(0);
163 Ptr<SatMobilityModel> satMob = sat->GetObject<SatMobilityModel>();
164
165 // print used parameters using log info
166 NS_LOG_INFO("--- satellite-link-budget-example ---");
167 NS_LOG_INFO(" Beam ID: " << beamId);
168 NS_LOG_INFO(" Sat position: " << satMob->GetGeoPosition() << " " << satMob->GetPosition());
169 NS_LOG_INFO(" GW position: " << gwMob->GetGeoPosition() << " " << gwMob->GetPosition());
170 NS_LOG_INFO(" UT position: " << utMob->GetGeoPosition() << " " << utMob->GetPosition());
171 NS_LOG_INFO(" ");
172 NS_LOG_INFO("Link results (Time, Channel type, Own address, Dest. address, Beam ID, Carrier "
173 "Center freq, IF Power, RX Power, SINR, Composite SINR) :");
174 // results are printed out in callback (LinkBudgetTraceCb)
175
176 simulationHelper->RunSimulation();
177
178 return 0;
179}
GeoCoordinate class is used to store and operate with geodetic coordinates.
static Ptr< SatEnvVariables > GetInstance()
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.