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