Loading...
Searching...
No Matches
sat-fwd-system-test-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/config-store-module.h"
24#include "ns3/core-module.h"
25#include "ns3/internet-module.h"
26#include "ns3/network-module.h"
27#include "ns3/satellite-module.h"
28#include "ns3/traffic-module.h"
29
30using namespace ns3;
31
41
42NS_LOG_COMPONENT_DEFINE("sat-fwd-sys-test");
43
44static void
45PrintBbFrameInfo(Ptr<SatBbFrame> bbFrame)
46{
47 if (!bbFrame)
48 {
49 std::cout << "[BBFrameTx] Time: " << Now().GetSeconds() << ", Frame Type: DUMMY_FRAME"
50 << std::endl;
51 return;
52 }
53
54 std::cout << "[BBFrameTx] " << "Time: " << Now().GetSeconds()
55 << ", Frame Type: " << SatEnums::GetFrameTypeName(bbFrame->GetFrameType())
56 << ", ModCod: " << SatEnums::GetModcodTypeName(bbFrame->GetModcod())
57 << ", Occupancy: " << bbFrame->GetOccupancy()
58 << ", Duration: " << bbFrame->GetDuration()
59 << ", Space used: " << bbFrame->GetSpaceUsedInBytes()
60 << ", Space Left: " << bbFrame->GetSpaceLeftInBytes();
61
62 std::cout << " [Receivers: ";
63
64 for (SatBbFrame::SatBbFramePayload_t::const_iterator it = bbFrame->GetPayload().begin();
65 it != bbFrame->GetPayload().end();
66 it++)
67 {
68 SatMacTag tag;
69
70 if ((*it)->PeekPacketTag(tag))
71 {
72 if (it != bbFrame->GetPayload().begin())
73 {
74 std::cout << ", ";
75 }
76
77 std::cout << tag.GetDestAddress();
78 }
79 else
80 {
81 NS_FATAL_ERROR("No tag");
82 }
83 }
84
85 std::cout << "]" << std::endl;
86}
87
88static void
89PrintBbFrameMergeInfo(Ptr<SatBbFrame> mergeTo, Ptr<SatBbFrame> mergeFrom)
90{
91 std::cout << "[Merge Info Begins]" << std::endl;
92 std::cout << "Merge To -> ";
93 PrintBbFrameInfo(mergeTo);
94 std::cout << "Merge From <- ";
95 PrintBbFrameInfo(mergeFrom);
96 std::cout << "[Merge Info Ends]" << std::endl;
97}
98
99int
100main(int argc, char* argv[])
101{
102 // Enable some logs.
103 LogComponentEnable("sat-fwd-sys-test", LOG_INFO);
104
105 // Spot-beam served by GW1
106 uint32_t beamId = 26;
107 uint32_t gwEndUsers = 10;
108
109 uint32_t testCase = 0;
110 std::string trafficModel = "cbr";
111 double simLength(40.0); // in seconds
112 Time senderAppStartTime = Seconds(0.1);
113 bool traceFrameInfo = false;
114 bool traceMergeInfo = false;
115
116 uint32_t packetSize(128); // in bytes
117 Time interval(MicroSeconds(50));
118 DataRate dataRate(DataRate(16000));
119
121 auto simulationHelper = CreateObject<SimulationHelper>("example-fwd-system-test");
122 Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
123
124 Config::SetDefault("ns3::SatBbFrameConf::BbFrameHighOccupancyThreshold", DoubleValue(0.9));
125 Config::SetDefault("ns3::SatBbFrameConf::BbFrameLowOccupancyThreshold", DoubleValue(0.8));
126 Config::SetDefault("ns3::SatBbFrameConf::BBFrameUsageMode",
127 StringValue("ShortAndNormalFrames"));
128 Config::SetDefault("ns3::SatConf::FwdCarrierAllocatedBandwidth", DoubleValue(1.25e+07));
129
130 // read command line parameters given by user
131 CommandLine cmd;
132 cmd.AddValue(
133 "testCase",
134 "Test case to execute. 0 = scheduler, ACM off, 1 = scheduler, ACM on, 2 = ACM one UT",
135 testCase);
136 cmd.AddValue("gwEndUsers", "Number of the GW end users", gwEndUsers);
137 cmd.AddValue("simLength", "Length of simulation", simLength);
138 cmd.AddValue("traceFrameInfo", "Trace (print) BB frame info", traceFrameInfo);
139 cmd.AddValue("traceMergeInfo", "Trace (print) BB frame merge info", traceMergeInfo);
140 cmd.AddValue("beamId", "Beam Id", beamId);
141 cmd.AddValue("trafficModel", "Traffic model: either 'cbr' or 'onoff'", trafficModel);
142 cmd.AddValue("senderAppStartTime", "Sender application (first) start time", senderAppStartTime);
143 cmd.Parse(argc, argv);
144
145 if (trafficModel != "cbr" && trafficModel != "onoff")
146 {
147 NS_FATAL_ERROR("Invalid traffic model, use either 'cbr' or 'onoff'");
148 }
149
150 simulationHelper->SetUtCountPerBeam(gwEndUsers);
151 simulationHelper->SetUserCountPerUt(1);
152 simulationHelper->SetSimulationTime(simLength);
153 simulationHelper->SetGwUserCount(gwEndUsers);
154 simulationHelper->SetBeamSet({beamId});
155
159
160 switch (testCase)
161 {
162 case 0: // scheduler, ACM disabled
163 Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(false));
164 break;
165
166 case 1: // scheduler, ACM enabled
167 Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(true));
168 break;
169
170 case 2: // ACM enabled, one UT with one user, Markov + external fading
171 Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(true));
172 Config::SetDefault("ns3::SatBeamHelper::FadingModel", StringValue("FadingMarkov"));
173
174 // Note, that the positions of the fading files do not necessarily match with the
175 // beam location, since this example is not using list position allocator!
176 Config::SetDefault("ns3::SatChannel::EnableExternalFadingInputTrace", BooleanValue(true));
177 Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtFwdDownIndexFileName",
178 StringValue("BeamId-1_256_UT_fading_fwddwn_trace_index.txt"));
179 Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtRtnUpIndexFileName",
180 StringValue("BeamId-1_256_UT_fading_rtnup_trace_index.txt"));
181
182 gwEndUsers = 1;
183 break;
184
185 default:
186 break;
187 }
188
189 simulationHelper->LoadScenario("geo-33E");
190
191 // Creating the reference system.
192 simulationHelper->CreateSatScenario();
193
194 // connect BB frame TX traces on, if enabled
195 if (traceFrameInfo)
196 {
197 Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatMac/BBFrameTxTrace",
198 MakeCallback(&PrintBbFrameInfo));
199 }
200
201 // connect BB frame merge traces on, if enabled
202 if (traceMergeInfo)
203 {
204 Config::ConnectWithoutContext(
205 "/NodeList/*/DeviceList/*/SatMac/Scheduler/BBFrameContainer/BBFrameMergeTrace",
206 MakeCallback(&PrintBbFrameMergeInfo));
207 }
208
212 if (trafficModel == "cbr")
213 {
214 simulationHelper->GetTrafficHelper()->AddCbrTraffic(
217 interval,
218 packetSize,
219 NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
220 Singleton<SatTopology>::Get()->GetUtUserNodes(),
221 senderAppStartTime,
222 Seconds(simLength),
223 MicroSeconds(20));
224 }
225 else
226 {
227 simulationHelper->GetTrafficHelper()->AddOnOffTraffic(
230 dataRate,
231 packetSize,
232 NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
233 Singleton<SatTopology>::Get()->GetUtUserNodes(),
234 "ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]",
235 "ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]",
236 senderAppStartTime,
237 Seconds(simLength),
238 MicroSeconds(20));
239 }
240
241 simulationHelper->EnableProgressLogs();
242
243 NS_LOG_INFO("--- sat-fwd-sys-test ---");
244 NS_LOG_INFO(" Packet size: " << packetSize);
245 NS_LOG_INFO(" Interval (CBR): " << interval.GetSeconds());
246 NS_LOG_INFO(" Data rate (OnOff): " << dataRate);
247 NS_LOG_INFO(" Simulation length: " << simLength);
248 NS_LOG_INFO(" Number of GW end users: " << gwEndUsers);
249 NS_LOG_INFO(" ");
250
254 // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("sat-fwd-sys-test.xml"));
255 // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
256 // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
257 // ConfigStore outputConfig;
258 // outputConfig.ConfigureDefaults ();
259
263 simulationHelper->RunSimulation();
264
265 Simulator::Destroy();
266
267 return 0;
268}
static std::string GetFrameTypeName(SatBbFrameType_t frameType)
static std::string GetModcodTypeName(SatModcod_t modcod)
This class implements a tag that carries the satellite MAC specific information, such as source and d...
Mac48Address GetDestAddress(void) const
Get destination MAC address.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static void PrintBbFrameMergeInfo(Ptr< SatBbFrame > mergeTo, Ptr< SatBbFrame > mergeFrom)
static void PrintBbFrameInfo(Ptr< SatBbFrame > bbFrame)