sat-onoff-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/core-module.h"
24 #include "ns3/internet-module.h"
25 #include "ns3/network-module.h"
26 #include "ns3/satellite-module.h"
27 
28 using namespace ns3;
29 
45 NS_LOG_COMPONENT_DEFINE("OnOff-example");
46 
47 int
48 main(int argc, char* argv[])
49 {
50  uint32_t packetSize = 512;
51  std::string dataRate = "500kb/s";
52  std::string onTime = "1.0";
53  std::string offTime = "0.5";
54  std::string scenario = "simple";
55  std::string sender = "both";
56  std::string simDuration = "11s";
57 
59  auto simulationHelper = CreateObject<SimulationHelper>("example-onoff");
60  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
61  Config::SetDefault("ns3::SatHelper::ScenarioCreationTraceEnabled", BooleanValue(true));
62 
63  // enable packet traces on satellite modules
64  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
65 
67 
68  // read command line parameters given by user
69  CommandLine cmd;
70  cmd.AddValue("packetSize", "Size of constant packet (bytes e.g 512)", packetSize);
71  cmd.AddValue("dataRate", "Data rate (e.g. 500kb/s)", dataRate);
72  cmd.AddValue("onTime", "Time for packet sending is on in seconds, (e.g. (1.0)", onTime);
73  cmd.AddValue("offTime", "Time for packet sending is off in seconds, (e.g. (0.5)", offTime);
74  cmd.AddValue("sender", "Packet sender (ut, gw, or both).", sender);
75  cmd.AddValue("scenario", "Test scenario to use. (simple, larger or full", scenario);
76  cmd.AddValue("simDuration", "Duration of the simulation (Time)", simDuration);
77  simulationHelper->AddDefaultUiArguments(cmd);
78  cmd.Parse(argc, argv);
79 
80  simulationHelper->SetSimulationTime(Time(simDuration));
81  simulationHelper->SetOutputTag(scenario);
82 
83  // select scenario, if correct one given, by default simple scenarion is used.
84  if (scenario == "larger")
85  {
86  satScenario = SatHelper::LARGER;
87  }
88  else if (scenario == "full")
89  {
90  satScenario = SatHelper::FULL;
91  }
92 
93  // Set up user given parameters for on/off functionality.
94  Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(packetSize));
95  Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(dataRate));
96  Config::SetDefault("ns3::OnOffApplication::OnTime",
97  StringValue("ns3::ConstantRandomVariable[Constant=" + onTime + "]"));
98  Config::SetDefault("ns3::OnOffApplication::OffTime",
99  StringValue("ns3::ConstantRandomVariable[Constant=" + offTime + "]"));
100 
101  // enable info logs
102  LogComponentEnable("OnOffApplication", LOG_LEVEL_INFO);
103  LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
104  LogComponentEnable("OnOff-example", LOG_LEVEL_INFO);
105 
106  // remove next line from comments to run real time simulation
107  // GlobalValue::Bind ("SimulatorImplementationType", StringValue
108  // ("ns3::RealtimeSimulatorImpl"));
109 
110  // create satellite helper with given scenario default=simple
111 
112  // Creating the reference system. Note, currently the satellite module supports
113  // only one reference system, which is named as "Scenario72". The string is utilized
114  // in mapping the scenario to the needed reference system configuration files. Arbitrary
115  // scenario name results in fatal error.
116  Ptr<SatHelper> helper = simulationHelper->CreateSatScenario(satScenario);
117 
118  // --- Create applications according to given user parameters
119 
120  // assert if sender is not valid
121  NS_ASSERT_MSG(((sender == "gw") || (sender == "ut") || (sender == "both")),
122  "Sender argument invalid.");
123 
124  // in case of sender is GW or Both, create OnOff application to GW connected user
125  // and Sink application to UT connected user
126  if ((sender == "gw") || (sender == "both"))
127  {
128  simulationHelper->InstallTrafficModel(SimulationHelper::ONOFF,
131  Seconds(1.0));
132  }
133 
134  // in case of sender is UT or Both, create OnOff application to UT connected user
135  // and Sink application to GW connected user
136  if (sender == "ut" || sender == "both")
137  {
138  simulationHelper->InstallTrafficModel(SimulationHelper::ONOFF,
141  Seconds(2.0));
142  }
143 
144  // prompt info of the used parameters
145  NS_LOG_INFO("--- sat-onoff-example ---");
146  NS_LOG_INFO(" Scenario used: " << scenario);
147  NS_LOG_INFO(" Sender: " << sender);
148  NS_LOG_INFO(" PacketSize: " << packetSize);
149  NS_LOG_INFO(" DataRate: " << dataRate);
150  NS_LOG_INFO(" OnTime: " << onTime);
151  NS_LOG_INFO(" OffTime: " << offTime);
152  NS_LOG_INFO(" Duration: " << simDuration);
153  NS_LOG_INFO(" ");
154 
155  // run simulation and finally destroy it
156  simulationHelper->RunSimulation();
157 
158  return 0;
159 }
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.