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  simulationHelper->LoadScenario("geo-33E");
113 
114  // Creating the reference system.
115  Ptr<SatHelper> helper = simulationHelper->CreateSatScenario(satScenario);
116 
117  // in full scenario get given beam UTs and use first UT's users
118  // other scenarios get all UT users.
119  if (scenario == "full")
120  {
121  // Manual configuration of applications
122 
123  // get users
124  NodeContainer uts = helper->GetBeamHelper()->GetUtNodes(0, beamIdInFullScenario);
125  NodeContainer utUsers = Singleton<SatTopology>::Get()->GetUtUserNodes(uts.Get(0));
126  NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
127 
128  uint16_t port = 9;
129 
130  // create application on GW user
131  PacketSinkHelper sinkHelper(
132  "ns3::UdpSocketFactory",
133  InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
134  CbrHelper cbrHelper("ns3::UdpSocketFactory",
135  InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port));
136  cbrHelper.SetAttribute("Interval", StringValue(interval));
137  cbrHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
138 
139  ApplicationContainer gwSink = sinkHelper.Install(gwUsers.Get(0));
140  gwSink.Start(Seconds(1.0));
141  gwSink.Stop(Seconds(10.0));
142 
143  ApplicationContainer gwCbr = cbrHelper.Install(gwUsers.Get(0));
144  gwCbr.Start(Seconds(1.0));
145  gwCbr.Stop(Seconds(2.1));
146 
147  // create application on UT user
148  sinkHelper.SetAttribute(
149  "Local",
150  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port))));
151  cbrHelper.SetAttribute(
152  "Remote",
153  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port))));
154 
155  ApplicationContainer utSink = sinkHelper.Install(utUsers.Get(0));
156  utSink.Start(Seconds(1.0));
157  utSink.Stop(Seconds(10.0));
158 
159  ApplicationContainer utCbr = cbrHelper.Install(utUsers.Get(0));
160  utCbr.Start(Seconds(7.0));
161  utCbr.Stop(Seconds(9.1));
162  }
163  else
164  {
165  /*simulationHelper->GetTrafficHelper()->AddCbrTraffic(SatTrafficHelper::FWD_LINK,
166  SatTrafficHelper::UDP,
167  Time(interval),
168  packetSize,
169  Singleton<SatTopology>::Get()->GetGwUserNodes(),
170  Singleton<SatTopology>::Get()->GetUtUserNodes(),
171  Seconds(1.0),
172  Seconds(2.1),
173  Seconds(0));*/
174 
175  simulationHelper->GetTrafficHelper()->AddCbrTraffic(
178  Time(interval),
179  packetSize,
180  Singleton<SatTopology>::Get()->GetGwUserNodes(),
181  Singleton<SatTopology>::Get()->GetUtUserNodes(),
182  Seconds(7.0),
183  Seconds(9.1),
184  Seconds(0));
185  }
186 
187  NS_LOG_INFO("--- sat-cbr-example ---");
188  NS_LOG_INFO(" Scenario used: " << scenario);
189  if (scenario == "full")
190  {
191  NS_LOG_INFO(" UT used in full scenario from beam: " << beamIdInFullScenario);
192  }
193  NS_LOG_INFO(" PacketSize: " << packetSize);
194  NS_LOG_INFO(" Interval: " << interval);
195  NS_LOG_INFO(" ");
196 
197  // To store attributes to file
198  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("output-attributes.xml"));
199  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
200  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
201  // ConfigStore outputConfig;
202  // outputConfig.ConfigureDefaults ();
203 
204  simulationHelper->RunSimulation();
205 
206  return 0;
207 }
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.