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  // enable info logs
94  LogComponentEnable("OnOffApplication", LOG_LEVEL_INFO);
95  LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
96  LogComponentEnable("OnOff-example", LOG_LEVEL_INFO);
97 
98  // remove next line from comments to run real time simulation
99  // GlobalValue::Bind ("SimulatorImplementationType", StringValue
100  // ("ns3::RealtimeSimulatorImpl"));
101 
102  simulationHelper->LoadScenario("geo-33E");
103 
104  // Creating the reference system.
105  simulationHelper->CreateSatScenario(satScenario);
106 
107  // --- Create applications according to given user parameters
108 
109  // assert if sender is not valid
110  NS_ASSERT_MSG(((sender == "gw") || (sender == "ut") || (sender == "both")),
111  "Sender argument invalid.");
112 
113  // in case of sender is GW or Both, create OnOff application to GW connected user
114  // and Sink application to UT connected user
115  if ((sender == "gw") || (sender == "both"))
116  {
117  simulationHelper->GetTrafficHelper()->AddOnOffTraffic(
120  DataRate(dataRate),
121  packetSize,
122  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
123  Singleton<SatTopology>::Get()->GetUtUserNodes(),
124  "ns3::ConstantRandomVariable[Constant=" + onTime + "]",
125  "ns3::ConstantRandomVariable[Constant=" + offTime + "]",
126  Seconds(1.0),
127  Time(simDuration),
128  Seconds(0));
129  }
130 
131  // in case of sender is UT or Both, create OnOff application to UT connected user
132  // and Sink application to GW connected user
133  if (sender == "ut" || sender == "both")
134  {
135  simulationHelper->GetTrafficHelper()->AddOnOffTraffic(
138  DataRate(dataRate),
139  packetSize,
140  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
141  Singleton<SatTopology>::Get()->GetUtUserNodes(),
142  "ns3::ConstantRandomVariable[Constant=" + onTime + "]",
143  "ns3::ConstantRandomVariable[Constant=" + offTime + "]",
144  Seconds(2.0),
145  Time(simDuration),
146  Seconds(0));
147  }
148 
149  // prompt info of the used parameters
150  NS_LOG_INFO("--- sat-onoff-example ---");
151  NS_LOG_INFO(" Scenario used: " << scenario);
152  NS_LOG_INFO(" Sender: " << sender);
153  NS_LOG_INFO(" PacketSize: " << packetSize);
154  NS_LOG_INFO(" DataRate: " << dataRate);
155  NS_LOG_INFO(" OnTime: " << onTime);
156  NS_LOG_INFO(" OffTime: " << offTime);
157  NS_LOG_INFO(" Duration: " << simDuration);
158  NS_LOG_INFO(" ");
159 
160  // run simulation and finally destroy it
161  simulationHelper->RunSimulation();
162 
163  return 0;
164 }
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.