sat-multi-application-rtn-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/core-module.h"
24 #include "ns3/ipv4-l3-protocol.h"
25 #include "ns3/network-module.h"
26 #include "ns3/satellite-module.h"
27 #include "ns3/traffic-module.h"
28 
29 using namespace ns3;
30 
47 NS_LOG_COMPONENT_DEFINE("sat-multi-application-rtn-example");
48 
49 int
50 main(int argc, char* argv[])
51 {
52  // LogComponentEnable ("OnOffApplication", LOG_LEVEL_INFO);
53  // LogComponentEnable ("CbrApplication", LOG_LEVEL_ALL);
54  // LogComponentEnable ("PacketSink", LOG_LEVEL_ALL);
55  LogComponentEnable("sat-multi-application-rtn-example", LOG_LEVEL_INFO);
56 
57  uint32_t endUsersPerUt(3);
58  uint32_t utsPerBeam(3);
59  double cbrProbability(0.5);
60  uint32_t packetSize = 512;
61  std::string interval = "1s";
62  double simLength(15.0);
63 
64  Time appStartTime = Seconds(0.001);
65  Time appStopTime = Seconds(10.0);
66 
68  auto simulationHelper = CreateObject<SimulationHelper>("example-multi-application-rtn");
69  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
70  Config::SetDefault("ns3::SatHelper::PacketTraceEnabled", BooleanValue(true));
71 
72  // read command line parameters given by user
73  CommandLine cmd;
74  cmd.AddValue("endUsersPerUt", "Number of end users per UT", endUsersPerUt);
75  cmd.AddValue("utsPerBeam", "Number of UTs per spot-beam", utsPerBeam);
76  cmd.AddValue("cbrProbability", "Probability of CBR end users", cbrProbability);
77  cmd.AddValue("simLength", "Simulation length in seconds", simLength);
78  simulationHelper->AddDefaultUiArguments(cmd);
79  cmd.Parse(argc, argv);
80 
81  simulationHelper->SetUtCountPerBeam(1);
82  simulationHelper->SetUserCountPerUt(1);
83  simulationHelper->SetBeamSet({12, 22});
84  simulationHelper->SetSimulationTime(simLength);
85 
86  // No PHY errors
88  Config::SetDefault("ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
89  Config::SetDefault("ns3::SatGwHelper::RtnLinkErrorModel", EnumValue(em));
90 
91  // Creating the reference system. Note, currently the satellite module supports
92  // only one reference system, which is named as "Scenario72". The string is utilized
93  // in mapping the scenario to the needed reference system configuration files. Arbitrary
94  // scenario name results in fatal error.
95  Ptr<SatHelper> helper = simulationHelper->CreateSatScenario();
96 
97  // Get the end users so that it is possible to attach
98  // applications on them
99  NodeContainer utUsers = helper->GetUtUsers();
100  NodeContainer gwUsers = helper->GetGwUsers();
101 
102  // Random variable for sharing the UTs to CBR and On-Off users
103  Ptr<UniformRandomVariable> rand = CreateObject<UniformRandomVariable>();
104 
105  NodeContainer utCbrUsers;
106  NodeContainer utOnOffUsers;
107 
108  /* DSCP values
109 
110  BE:
111  DscpDefault = 0x00,
112 
113  AF:
114  DSCP_CS1 = 0x20,
115  DSCP_AF11 = 0x28,
116  DSCP_AF12 = 0x30,
117  DSCP_AF13 = 0x38,
118 
119  DSCP_CS2 = 0x40,
120  DSCP_AF21 = 0x48,
121  DSCP_AF22 = 0x50,
122  DSCP_AF23 = 0x58,
123 
124  DSCP_CS3 = 0x60,
125  DSCP_AF31 = 0x68,
126  DSCP_AF32 = 0x70,
127  DSCP_AF33 = 0x78,
128 
129  DSCP_CS4 = 0x80,
130  DSCP_AF41 = 0x88,
131  DSCP_AF42 = 0x90,
132  DSCP_AF43 = 0x98,
133 
134  EF:
135  DSCP_CS5 = 0xA0,
136  DSCP_EF = 0xB8,
137 
138  DSCP_CS6 = 0xC0,
139  DSCP_CS7 = 0xE0
140  */
141 
142  // ToS fields of applications
143  uint8_t onOffTos(0x28);
144  uint8_t cbrTos(0xB8);
145 
146  // Divide the users into CBR and On-Off users and set the ToS values.
147  for (NodeContainer::Iterator i = utUsers.Begin(); i != utUsers.End(); i++)
148  {
149  // CBR
150  if (rand->GetValue() < cbrProbability)
151  {
152  utCbrUsers.Add(*i);
153  }
154  // OnOff
155  else
156  {
157  utOnOffUsers.Add(*i);
158  }
159  }
160 
161  NS_LOG_INFO("Number of created CBR users: " << utCbrUsers.GetN()
162  << ", On-Off users: " << utOnOffUsers.GetN());
163 
164  ApplicationContainer gwCbrSinkApps;
165  ApplicationContainer gwOnOffSinkApps;
166  ApplicationContainer utCbrApps;
167  ApplicationContainer utOnOffApps;
168 
169  //---- Start CBR application definitions
170 
171  NS_LOG_INFO("Creating CBR applications and sinks");
172 
173  uint16_t port = 9;
174  Time startDelay = appStartTime;
175 
176  uint32_t cbrGwUserId(0);
177  uint32_t onOffGwUserId(1);
178 
179  if (utCbrUsers.GetN() > 0)
180  {
181  // create application on UT user
182  PacketSinkHelper cbrSinkHelper(
183  "ns3::UdpSocketFactory",
184  InetSocketAddress(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port));
185  CbrHelper cbrHelper(
186  "ns3::UdpSocketFactory",
187  InetSocketAddress(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port));
188  cbrHelper.SetAttribute("Interval", StringValue(interval));
189  cbrHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
190 
191  // Set destination addresses
192  InetSocketAddress cbrDest(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port);
193  cbrDest.SetTos(cbrTos);
194 
195  // Cbr and Sink applications creation. CBR to UT users and sinks to GW users.
196  gwCbrSinkApps.Add(cbrSinkHelper.Install(gwUsers.Get(cbrGwUserId)));
197  gwCbrSinkApps.Get(0)->SetStartTime(Seconds(0.1));
198  gwCbrSinkApps.Get(0)->SetStopTime(appStopTime);
199 
200  for (uint32_t i = 0; i < utCbrUsers.GetN(); i++)
201  {
202  cbrHelper.SetAttribute("Remote", AddressValue(Address(cbrDest)));
203  cbrSinkHelper.SetAttribute("Local", AddressValue(Address(cbrDest)));
204 
205  utCbrApps.Add(cbrHelper.Install(utCbrUsers.Get(i)));
206 
207  startDelay += Seconds(0.001);
208 
209  // Set start and end times
210  utCbrApps.Get(i)->SetStartTime(startDelay);
211  utCbrApps.Get(i)->SetStopTime(appStopTime);
212  }
213  }
214  //---- Stop CBR application definitions
215 
216  //---- Start OnOff application definitions
217 
218  if (utOnOffUsers.GetN() > 0)
219  {
220  NS_LOG_INFO("Creating OnOff applications and sinks");
221 
222  std::string dataRate = "100kb/s";
223  std::string onTime = "2.0";
224  std::string offTime = "2.0";
225 
226  Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(packetSize));
227  Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(dataRate));
228  Config::SetDefault("ns3::OnOffApplication::OnTime",
229  StringValue("ns3::ConstantRandomVariable[Constant=" + onTime + "]"));
230  Config::SetDefault("ns3::OnOffApplication::OffTime",
231  StringValue("ns3::ConstantRandomVariable[Constant=" + offTime + "]"));
232 
233  // create helpers for application creation
234  // set address of the first UT connected user
235  PacketSinkHelper onOffSinkHelper(
236  "ns3::UdpSocketFactory",
237  InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
238  OnOffHelper onOffHelper("ns3::UdpSocketFactory",
239  InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
240 
241  startDelay = appStartTime;
242 
243  // Set destination addresses
244  InetSocketAddress onOffDest(helper->GetUserAddress(gwUsers.Get(onOffGwUserId)), port);
245  onOffDest.SetTos(onOffTos);
246 
247  // Cbr and Sink applications creation
248  gwOnOffSinkApps.Add(onOffSinkHelper.Install(gwUsers.Get(onOffGwUserId)));
249  gwOnOffSinkApps.Get(0)->SetStartTime(Seconds(0.1));
250  gwOnOffSinkApps.Get(0)->SetStopTime(appStopTime);
251 
252  for (uint32_t i = 0; i < utOnOffUsers.GetN(); i++)
253  {
254  onOffHelper.SetAttribute("Remote", AddressValue(Address(onOffDest)));
255  onOffSinkHelper.SetAttribute("Local", AddressValue(Address(onOffDest)));
256 
257  utOnOffApps.Add(onOffHelper.Install(utOnOffUsers.Get(i)));
258 
259  startDelay += Seconds(0.001);
260 
261  utOnOffApps.Get(i)->SetStartTime(startDelay);
262  utOnOffApps.Get(i)->SetStopTime(appStopTime);
263  }
264  }
265 
266  //---- Stop OnOff application definitions
267 
268  // prompt info of the used parameters
269  NS_LOG_INFO("--- sat-multi-application-rtn-example ---");
270  NS_LOG_INFO(" Packet size in bytes: " << packetSize);
271  NS_LOG_INFO(" Packet sending interval: " << interval);
272  NS_LOG_INFO(" Simulation length: " << simLength);
273  NS_LOG_INFO(" Number of UTs: " << utsPerBeam);
274  NS_LOG_INFO(" Number of end users per UT: " << endUsersPerUt);
275  NS_LOG_INFO(" ");
276 
277  simulationHelper->RunSimulation();
278  return 0;
279 }
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.