sat-cbr-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 
48 NS_LOG_COMPONENT_DEFINE("sat-cbr-example");
49 
50 int
51 main(int argc, char* argv[])
52 {
53  uint32_t beamIdInFullScenario = 10;
54  uint32_t packetSize = 512;
55  std::string interval = "1s";
56  std::string scenario = "simple";
58 
59  // To read attributes from file
60  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("input-attributes.xml"));
61  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Load"));
62  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
63  // ConfigStore inputConfig;
64  // inputConfig.ConfigureDefaults ();
65 
67  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
68 
70  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
71  Ptr<SimulationHelper> simulationHelper = CreateObject<SimulationHelper>("example-cbr");
72 
73  // read command line parameters given by user
74  CommandLine cmd;
75  cmd.AddValue("beamIdInFullScenario",
76  "Id where Sending/Receiving UT is selected in FULL scenario. (used only when "
77  "scenario is full) ",
78  beamIdInFullScenario);
79  cmd.AddValue("packetSize", "Size of constant packet (bytes)", packetSize);
80  cmd.AddValue("interval", "Interval to sent packets in seconds, (e.g. (1s)", interval);
81  cmd.AddValue("scenario", "Test scenario to use. (simple, larger or full", scenario);
82  simulationHelper->AddDefaultUiArguments(cmd);
83  cmd.Parse(argc, argv);
84 
85  if (scenario == "larger")
86  {
87  satScenario = SatHelper::LARGER;
88  }
89  else if (scenario == "full")
90  {
91  satScenario = SatHelper::FULL;
92  }
93  // Set tag, if output path is not explicitly defined
94  simulationHelper->SetOutputTag(scenario);
95 
96  simulationHelper->SetSimulationTime(Seconds(11));
97 
98  // Set beam ID
99  std::stringstream beamsEnabled;
100  beamsEnabled << beamIdInFullScenario;
101  simulationHelper->SetBeams(beamsEnabled.str());
102 
103  // enable info logs
104  LogComponentEnable("CbrApplication", LOG_LEVEL_INFO);
105  LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
106  LogComponentEnable("sat-cbr-example", LOG_LEVEL_INFO);
107 
108  // remove next line from comments to run real time simulation
109  // GlobalValue::Bind ("SimulatorImplementationType", StringValue
110  // ("ns3::RealtimeSimulatorImpl"));
111 
112  // create satellite helper with given scenario default=simple
113 
114  // Creating the reference system. Note, currently the satellite module supports
115  // only one reference system, which is named as "Scenario72". The string is utilized
116  // in mapping the scenario to the needed reference system configuration files. Arbitrary
117  // scenario name results in fatal error.
118  Ptr<SatHelper> helper = simulationHelper->CreateSatScenario(satScenario);
119 
120  // in full scenario get given beam UTs and use first UT's users
121  // other scenarios get all UT users.
122  if (scenario == "full")
123  {
124  // Manual configuration of applications
125 
126  // get users
127  NodeContainer uts = helper->GetBeamHelper()->GetUtNodes(0, beamIdInFullScenario);
128  NodeContainer utUsers = helper->GetUserHelper()->GetUtUsers(uts.Get(0));
129 
130  NodeContainer gwUsers = helper->GetGwUsers();
131 
132  uint16_t port = 9;
133 
134  // create application on GW user
135  PacketSinkHelper sinkHelper(
136  "ns3::UdpSocketFactory",
137  InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
138  CbrHelper cbrHelper("ns3::UdpSocketFactory",
139  InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port));
140  cbrHelper.SetAttribute("Interval", StringValue(interval));
141  cbrHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
142 
143  ApplicationContainer gwSink = sinkHelper.Install(gwUsers.Get(0));
144  gwSink.Start(Seconds(1.0));
145  gwSink.Stop(Seconds(10.0));
146 
147  ApplicationContainer gwCbr = cbrHelper.Install(gwUsers.Get(0));
148  gwCbr.Start(Seconds(1.0));
149  gwCbr.Stop(Seconds(2.1));
150 
151  // create application on UT user
152  sinkHelper.SetAttribute(
153  "Local",
154  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port))));
155  cbrHelper.SetAttribute(
156  "Remote",
157  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port))));
158 
159  ApplicationContainer utSink = sinkHelper.Install(utUsers.Get(0));
160  utSink.Start(Seconds(1.0));
161  utSink.Stop(Seconds(10.0));
162 
163  ApplicationContainer utCbr = cbrHelper.Install(utUsers.Get(0));
164  utCbr.Start(Seconds(7.0));
165  utCbr.Stop(Seconds(9.1));
166  }
167  else
168  {
169  Config::SetDefault("ns3::CbrApplication::Interval", StringValue(interval));
170  Config::SetDefault("ns3::CbrApplication::PacketSize", UintegerValue(packetSize));
171 
172  /*simulationHelper->InstallTrafficModel (
173  SimulationHelper::CBR, SimulationHelper::UDP, SimulationHelper::FWD_LINK,
174  Seconds (1.0), Seconds (2.1));*/
175  simulationHelper->InstallTrafficModel(SimulationHelper::CBR,
178  Seconds(7.0),
179  Seconds(9.1));
180  }
181 
182  NS_LOG_INFO("--- sat-cbr-example ---");
183  NS_LOG_INFO(" Scenario used: " << scenario);
184  if (scenario == "full")
185  {
186  NS_LOG_INFO(" UT used in full scenario from beam: " << beamIdInFullScenario);
187  }
188  NS_LOG_INFO(" PacketSize: " << packetSize);
189  NS_LOG_INFO(" Interval: " << interval);
190  NS_LOG_INFO(" ");
191 
192  // To store attributes to file
193  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("output-attributes.xml"));
194  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
195  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
196  // ConfigStore outputConfig;
197  // outputConfig.ConfigureDefaults ();
198 
199  simulationHelper->RunSimulation();
200 
201  return 0;
202 }
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.