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  Ptr<SatHelper> helper = simulationHelper->CreateSatScenario(satScenario);
140  /*****************************************************************************
141  Manually creating an installing application (users) to satellite network.
142  Note that you may simply call SimulationHelper::Install TrafficModel when
143  using all nodes.
144  -- Start --
145  */
146  // for getting UT users
147  NodeContainer utUsers;
148 
149  // in full scenario get given beam UTs and use first UT's users
150  // other scenarios get all UT users.
151  if (scenario == "full")
152  {
153  NodeContainer uts = helper->GetBeamHelper()->GetUtNodes(0, 1);
154  utUsers = helper->GetUserHelper()->GetUtUsers(uts.Get(0));
155  }
156  else
157  {
158  utUsers = helper->GetUtUsers();
159  }
160 
161  // get GW users
162  NodeContainer gwUsers = helper->GetGwUsers();
163 
164  uint16_t port = 9;
165 
166  // create and install applications on GW user
167  PacketSinkHelper sinkHelper("ns3::UdpSocketFactory",
168  InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
169  CbrHelper cbrHelper("ns3::UdpSocketFactory",
170  InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port));
171 
172  // install sink to receive packets from UT
173  ApplicationContainer gwSink = sinkHelper.Install(gwUsers.Get(0));
174  gwSink.Start(Seconds(1.0));
175  gwSink.Stop(Seconds(10.0));
176 
177  // install CBR to send packets to UT
178  ApplicationContainer gwCbr = cbrHelper.Install(gwUsers.Get(0));
179  gwCbr.Start(Seconds(1.0));
180  gwCbr.Stop(Seconds(2.1));
181 
182  // create applications on UT user
183  sinkHelper.SetAttribute(
184  "Local",
185  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port))));
186  cbrHelper.SetAttribute(
187  "Remote",
188  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port))));
189 
190  // install sink to receive packets from GW
191  ApplicationContainer utSink = sinkHelper.Install(utUsers.Get(0));
192  utSink.Start(Seconds(1.0));
193  utSink.Stop(Seconds(10.0));
194 
195  // install CBR to send packets to GW
196  ApplicationContainer utCbr = cbrHelper.Install(utUsers.Get(0));
197  utCbr.Start(Seconds(7.0));
198  utCbr.Stop(Seconds(9.1));
204  NS_LOG_INFO("--- Tutorial-example ---");
205  NS_LOG_INFO(" Scenario used: " << scenario);
206  NS_LOG_INFO(" ");
207 
208  /*****************************************************************************
209  Store set attribute values to XML output file
210  -- Start -- */
211 
212  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("sat-tutorial-output.xml"));
213  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
214  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
215  // ConfigStore outputConfig;
216  // outputConfig.ConfigureDefaults ();
217 
223  /*****************************************************************************
224  Run, stop and destroy simulation
225  -- Start -- */
226 
227  simulationHelper->RunSimulation();
233  return 0;
234 }
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.