sat-tutorial-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: Jani Puttonen <jani.puttonen@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 
44 NS_LOG_COMPONENT_DEFINE("sat-tutorial-example");
45 
46 int
47 main(int argc, char* argv[])
48 {
50  std::string scenario = "Simple";
51 
52  // Create simulation helper
53  auto simulationHelper = CreateObject<SimulationHelper>("example-tutorial");
54 
55  // Enable creation traces
56  Config::SetDefault("ns3::SatHelper::ScenarioCreationTraceEnabled", BooleanValue(true));
57 
58  // Enable packet traces (to file PacketTrace.log).
59  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
60 
61  /*****************************************************************************
62  'To Select super frame configuration, Option 2'
63  -- Start -- */
64 
66  Config::SetDefault("ns3::SatEnvVariables::SimulationTag", StringValue(scenario));
67  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
68 
69  // std::string inputFileNameWithPath = Singleton<SatEnvVariables>::Get ()->LocateDirectory
70  // ("contrib/satellite/examples") + "/sat-tutorial-input.xml";
71  //
72  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue (inputFileNameWithPath));
73  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Load"));
74  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
75  // ConfigStore inputConfig;
76  // inputConfig.ConfigureDefaults ();
82  /******************************************************************************
83  Read command line arguments
84  -- Start -- */
85 
86  CommandLine cmd;
87  cmd.AddValue("scenario", "Scenario to be created", scenario);
88  simulationHelper->AddDefaultUiArguments(cmd);
89  cmd.Parse(argc, argv);
95  /*****************************************************************************
96  Create helper and simulation scenario
97  -- Start -- */
98 
99  // select simulation scenario to use
100  if (scenario == "larger")
101  {
102  satScenario = SatHelper::LARGER;
103  }
104  else if (scenario == "full")
105  {
106  satScenario = SatHelper::FULL;
107  }
108 
109  simulationHelper->SetOutputTag(scenario);
110  simulationHelper->SetSimulationTime(Seconds(11));
111 
112  // enable info logs
113  LogComponentEnable("CbrApplication", LOG_LEVEL_INFO);
114  LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
115  LogComponentEnable("sat-tutorial-example", LOG_LEVEL_INFO);
116 
117  // remove next line from comments to run real time simulation
118  // GlobalValue::Bind ("SimulatorImplementationType", StringValue
119  // ("ns3::RealtimeSimulatorImpl"));
120 
121  /*****************************************************************************
122  'To Select super frame configuration, Option 1'
123  -- Start -- */
124 
125  // Config::SetDefault ("ns3::SatConf::SuperFrameConfForSeq0", EnumValue
126  // (SatSuperframeConf::CONFIG_TYPE_2)); Config::SetDefault
127  // ("ns3::SatConf::SuperFrameConfForSeq0", StringValue ("Configuration_2"));
128 
134  simulationHelper->LoadScenario("geo-33E");
135 
136  Ptr<SatHelper> helper = simulationHelper->CreateSatScenario(satScenario);
142  /*****************************************************************************
143  Manually creating an installing application (users) to satellite network.
144  Note that you may simply call SimulationHelper::Install TrafficModel when
145  using all nodes.
146  -- Start --
147  */
148  // for getting UT users
149  NodeContainer utUsers;
150 
151  // in full scenario get given beam UTs and use first UT's users
152  // other scenarios get all UT users.
153  if (scenario == "full")
154  {
155  NodeContainer uts = helper->GetBeamHelper()->GetUtNodes(0, 1);
156  utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes(uts.Get(0));
157  }
158  else
159  {
160  utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes();
161  }
162 
163  // get GW users
164  NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
165 
166  uint16_t port = 9;
167 
168  // create and install applications on GW user
169  PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
170  InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
171  CbrHelper cbrHelper("ns3::UdpSocketFactory",
172  InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port));
173 
174  // install sink to receive packets from UT
175  ApplicationContainer gwSink = sinkHelper.Install(gwUsers.Get(0));
176  gwSink.Start(Seconds(1.0));
177  gwSink.Stop(Seconds(10.0));
178 
179  // install CBR to send packets to UT
180  ApplicationContainer gwCbr = cbrHelper.Install(gwUsers.Get(0));
181  gwCbr.Start(Seconds(1.0));
182  gwCbr.Stop(Seconds(2.1));
183 
184  // create applications on UT user
185  sinkHelper.SetAttribute(
186  "Local",
187  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port))));
188  cbrHelper.SetAttribute(
189  "Remote",
190  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port))));
191 
192  // install sink to receive packets from GW
193  ApplicationContainer utSink = sinkHelper.Install(utUsers.Get(0));
194  utSink.Start(Seconds(1.0));
195  utSink.Stop(Seconds(10.0));
196 
197  // install CBR to send packets to GW
198  ApplicationContainer utCbr = cbrHelper.Install(utUsers.Get(0));
199  utCbr.Start(Seconds(7.0));
200  utCbr.Stop(Seconds(9.1));
206  NS_LOG_INFO("--- Tutorial-example ---");
207  NS_LOG_INFO(" Scenario used: " << scenario);
208  NS_LOG_INFO(" ");
209 
210  /*****************************************************************************
211  Store set attribute values to XML output file
212  -- Start -- */
213 
214  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("sat-tutorial-output.xml"));
215  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
216  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
217  // ConfigStore outputConfig;
218  // outputConfig.ConfigureDefaults ();
219 
225  /*****************************************************************************
226  Run, stop and destroy simulation
227  -- Start -- */
228 
229  simulationHelper->RunSimulation();
235  return 0;
236 }
PreDefinedScenario_t
Values for pre-defined scenarios to be used by helper when building satellite network topology base.
@ LARGER
LARGER Larger scenario used as base.
@ FULL
FULL Full scenario used as base.
@ SIMPLE
SIMPLE Simple scenario used as base.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.