Loading...
Searching...
No Matches
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
29using namespace ns3;
30
46
47NS_LOG_COMPONENT_DEFINE("sat-multi-application-rtn-example");
48
49int
50main(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 simulationHelper->LoadScenario("geo-33E");
92
93 // Creating the reference system.
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 = Singleton<SatTopology>::Get()->GetUtUserNodes();
99 NodeContainer gwUsers = Singleton<SatTopology>::Get()->GetGwUserNodes();
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 and set the ToS values.
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 gwCbrSinkApps;
164 ApplicationContainer gwOnOffSinkApps;
165 ApplicationContainer utCbrApps;
166 ApplicationContainer utOnOffApps;
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
175 uint32_t cbrGwUserId(0);
176 uint32_t onOffGwUserId(1);
177
178 if (utCbrUsers.GetN() > 0)
179 {
180 // create application on UT user
181 PacketSinkHelper cbrSinkHelper(
182 "ns3::UdpSocketFactory",
183 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port));
184 CbrHelper cbrHelper(
185 "ns3::UdpSocketFactory",
186 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port));
187 cbrHelper.SetAttribute("Interval", StringValue(interval));
188 cbrHelper.SetAttribute("PacketSize", UintegerValue(packetSize));
189 cbrHelper.SetAttribute("Tos", UintegerValue(cbrTos));
190
191 // Set destination addresses
192 InetSocketAddress cbrDest(helper->GetUserAddress(gwUsers.Get(cbrGwUserId)), port);
193
194 // Cbr and Sink applications creation. CBR to UT users and sinks to GW users.
195 gwCbrSinkApps.Add(cbrSinkHelper.Install(gwUsers.Get(cbrGwUserId)));
196 gwCbrSinkApps.Get(0)->SetStartTime(Seconds(0.1));
197 gwCbrSinkApps.Get(0)->SetStopTime(appStopTime);
198
199 for (uint32_t i = 0; i < utCbrUsers.GetN(); i++)
200 {
201 cbrHelper.SetAttribute("Remote", AddressValue(Address(cbrDest)));
202 cbrSinkHelper.SetAttribute("Local", AddressValue(Address(cbrDest)));
203
204 utCbrApps.Add(cbrHelper.Install(utCbrUsers.Get(i)));
205
206 startDelay += Seconds(0.001);
207
208 // Set start and end times
209 utCbrApps.Get(i)->SetStartTime(startDelay);
210 utCbrApps.Get(i)->SetStopTime(appStopTime);
211 }
212 }
213 //---- Stop CBR application definitions
214
215 //---- Start OnOff application definitions
216
217 if (utOnOffUsers.GetN() > 0)
218 {
219 NS_LOG_INFO("Creating OnOff applications and sinks");
220
221 std::string dataRate = "100kb/s";
222 std::string onTime = "2.0";
223 std::string offTime = "2.0";
224
225 Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(packetSize));
226 Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(dataRate));
227 Config::SetDefault("ns3::OnOffApplication::OnTime",
228 StringValue("ns3::ConstantRandomVariable[Constant=" + onTime + "]"));
229 Config::SetDefault("ns3::OnOffApplication::OffTime",
230 StringValue("ns3::ConstantRandomVariable[Constant=" + offTime + "]"));
231
232 // create helpers for application creation
233 // set address of the first UT connected user
234 PacketSinkHelper onOffSinkHelper(
235 "ns3::UdpSocketFactory",
236 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
237 OnOffHelper onOffHelper("ns3::UdpSocketFactory",
238 InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port));
239
240 startDelay = appStartTime;
241
242 // Set destination addresses
243 InetSocketAddress onOffDest(helper->GetUserAddress(gwUsers.Get(onOffGwUserId)), port);
244
245 // Cbr and Sink applications creation
246 gwOnOffSinkApps.Add(onOffSinkHelper.Install(gwUsers.Get(onOffGwUserId)));
247 gwOnOffSinkApps.Get(0)->SetStartTime(Seconds(0.1));
248 gwOnOffSinkApps.Get(0)->SetStopTime(appStopTime);
249
250 for (uint32_t i = 0; i < utOnOffUsers.GetN(); i++)
251 {
252 onOffHelper.SetAttribute("Remote", AddressValue(Address(onOffDest)));
253 onOffHelper.SetAttribute("Tos", UintegerValue(onOffTos));
254 onOffSinkHelper.SetAttribute("Local", AddressValue(Address(onOffDest)));
255
256 utOnOffApps.Add(onOffHelper.Install(utOnOffUsers.Get(i)));
257
258 startDelay += Seconds(0.001);
259
260 utOnOffApps.Get(i)->SetStartTime(startDelay);
261 utOnOffApps.Get(i)->SetStopTime(appStopTime);
262 }
263 }
264
265 //---- Stop OnOff application definitions
266
267 // prompt info of the used parameters
268 NS_LOG_INFO("--- sat-multi-application-rtn-example ---");
269 NS_LOG_INFO(" Packet size in bytes: " << packetSize);
270 NS_LOG_INFO(" Packet sending interval: " << interval);
271 NS_LOG_INFO(" Simulation length: " << simLength);
272 NS_LOG_INFO(" Number of UTs: " << utsPerBeam);
273 NS_LOG_INFO(" Number of end users per UT: " << endUsersPerUt);
274 NS_LOG_INFO(" ");
275
276 simulationHelper->RunSimulation();
277 return 0;
278}
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.