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