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 
30 using namespace ns3;
31 
42 NS_LOG_COMPONENT_DEFINE("sat-fwd-sys-test");
43 
44 static void
45 PrintBbFrameInfo(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] "
55  << "Time: " << Now().GetSeconds()
56  << ", Frame Type: " << SatEnums::GetFrameTypeName(bbFrame->GetFrameType())
57  << ", ModCod: " << SatEnums::GetModcodTypeName(bbFrame->GetModcod())
58  << ", Occupancy: " << bbFrame->GetOccupancy()
59  << ", Duration: " << bbFrame->GetDuration()
60  << ", Space used: " << bbFrame->GetSpaceUsedInBytes()
61  << ", Space Left: " << bbFrame->GetSpaceLeftInBytes();
62 
63  std::cout << " [Receivers: ";
64 
65  for (SatBbFrame::SatBbFramePayload_t::const_iterator it = bbFrame->GetPayload().begin();
66  it != bbFrame->GetPayload().end();
67  it++)
68  {
69  SatMacTag tag;
70 
71  if ((*it)->PeekPacketTag(tag))
72  {
73  if (it != bbFrame->GetPayload().begin())
74  {
75  std::cout << ", ";
76  }
77 
78  std::cout << tag.GetDestAddress();
79  }
80  else
81  {
82  NS_FATAL_ERROR("No tag");
83  }
84  }
85 
86  std::cout << "]" << std::endl;
87 }
88 
89 static void
90 PrintBbFrameMergeInfo(Ptr<SatBbFrame> mergeTo, Ptr<SatBbFrame> mergeFrom)
91 {
92  std::cout << "[Merge Info Begins]" << std::endl;
93  std::cout << "Merge To -> ";
94  PrintBbFrameInfo(mergeTo);
95  std::cout << "Merge From <- ";
96  PrintBbFrameInfo(mergeFrom);
97  std::cout << "[Merge Info Ends]" << std::endl;
98 }
99 
100 int
101 main(int argc, char* argv[])
102 {
103  // Enable some logs.
104  LogComponentEnable("sat-fwd-sys-test", LOG_INFO);
105 
106  // Spot-beam served by GW1
107  uint32_t beamId = 26;
108  uint32_t gwEndUsers = 10;
109 
110  uint32_t testCase = 0;
111  std::string trafficModel = "cbr";
112  double simLength(40.0); // in seconds
113  Time senderAppStartTime = Seconds(0.1);
114  bool traceFrameInfo = false;
115  bool traceMergeInfo = false;
116 
117  UintegerValue packetSize(128); // in bytes
118  TimeValue interval(MicroSeconds(50));
119  DataRateValue dataRate(DataRate(16000));
120 
122  auto simulationHelper = CreateObject<SimulationHelper>("example-fwd-system-test");
123  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
124 
125  // set default values for traffic model apps here
126  // attributes can be overridden by command line arguments when needed
127  Config::SetDefault("ns3::CbrApplication::PacketSize", packetSize);
128  Config::SetDefault("ns3::CbrApplication::Interval", interval);
129  Config::SetDefault("ns3::OnOffApplication::PacketSize", packetSize);
130  Config::SetDefault("ns3::OnOffApplication::DataRate", dataRate);
131  Config::SetDefault("ns3::OnOffApplication::OnTime",
132  StringValue("ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]"));
133  Config::SetDefault("ns3::OnOffApplication::OffTime",
134  StringValue("ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]"));
135 
136  Config::SetDefault("ns3::SatBbFrameConf::BbFrameHighOccupancyThreshold", DoubleValue(0.9));
137  Config::SetDefault("ns3::SatBbFrameConf::BbFrameLowOccupancyThreshold", DoubleValue(0.8));
138  Config::SetDefault("ns3::SatBbFrameConf::BBFrameUsageMode",
139  StringValue("ShortAndNormalFrames"));
140  Config::SetDefault("ns3::SatConf::FwdCarrierAllocatedBandwidth", DoubleValue(1.25e+07));
141 
142  // read command line parameters given by user
143  CommandLine cmd;
144  cmd.AddValue(
145  "testCase",
146  "Test case to execute. 0 = scheduler, ACM off, 1 = scheduler, ACM on, 2 = ACM one UT",
147  testCase);
148  cmd.AddValue("gwEndUsers", "Number of the GW end users", gwEndUsers);
149  cmd.AddValue("simLength", "Length of simulation", simLength);
150  cmd.AddValue("traceFrameInfo", "Trace (print) BB frame info", traceFrameInfo);
151  cmd.AddValue("traceMergeInfo", "Trace (print) BB frame merge info", traceMergeInfo);
152  cmd.AddValue("beamId", "Beam Id", beamId);
153  cmd.AddValue("trafficModel", "Traffic model: either 'cbr' or 'onoff'", trafficModel);
154  cmd.AddValue("senderAppStartTime", "Sender application (first) start time", senderAppStartTime);
155  cmd.Parse(argc, argv);
156 
157  if (trafficModel != "cbr" && trafficModel != "onoff")
158  {
159  NS_FATAL_ERROR("Invalid traffic model, use either 'cbr' or 'onoff'");
160  }
162  trafficModel == "cbr" ? SimulationHelper::CBR : SimulationHelper::ONOFF;
163 
164  simulationHelper->SetUtCountPerBeam(gwEndUsers);
165  simulationHelper->SetUserCountPerUt(1);
166  simulationHelper->SetSimulationTime(simLength);
167  simulationHelper->SetGwUserCount(gwEndUsers);
168  simulationHelper->SetBeamSet({beamId});
169 
174  switch (testCase)
175  {
176  case 0: // scheduler, ACM disabled
177  Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(false));
178  break;
179 
180  case 1: // scheduler, ACM enabled
181  Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(true));
182  break;
183 
184  case 2: // ACM enabled, one UT with one user, Markov + external fading
185  Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(true));
186  Config::SetDefault("ns3::SatBeamHelper::FadingModel", StringValue("FadingMarkov"));
187 
188  // Note, that the positions of the fading files do not necessarily match with the
189  // beam location, since this example is not using list position allocator!
190  Config::SetDefault("ns3::SatChannel::EnableExternalFadingInputTrace", BooleanValue(true));
191  Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtFwdDownIndexFileName",
192  StringValue("BeamId-1_256_UT_fading_fwddwn_trace_index.txt"));
193  Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtRtnUpIndexFileName",
194  StringValue("BeamId-1_256_UT_fading_rtnup_trace_index.txt"));
195 
196  gwEndUsers = 1;
197  break;
198 
199  default:
200  break;
201  }
202 
203  // Creating the reference system. Note, currently the satellite module supports
204  // only one reference system, which is named as "Scenario72". The string is utilized
205  // in mapping the scenario to the needed reference system configuration files. Arbitrary
206  // scenario name results in fatal error.
207  simulationHelper->CreateSatScenario();
208 
209  // connect BB frame TX traces on, if enabled
210  if (traceFrameInfo)
211  {
212  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatMac/BBFrameTxTrace",
213  MakeCallback(&PrintBbFrameInfo));
214  }
215 
216  // connect BB frame merge traces on, if enabled
217  if (traceMergeInfo)
218  {
219  Config::ConnectWithoutContext(
220  "/NodeList/*/DeviceList/*/SatMac/Scheduler/BBFrameContainer/BBFrameMergeTrace",
221  MakeCallback(&PrintBbFrameMergeInfo));
222  }
223 
227  simulationHelper->InstallTrafficModel(model,
230  senderAppStartTime,
231  Seconds(simLength),
232  MicroSeconds(20));
233 
234  simulationHelper->EnableProgressLogs();
235 
236  NS_LOG_INFO("--- sat-fwd-sys-test ---");
237  NS_LOG_INFO(" Packet size: " << packetSize.Get());
238  NS_LOG_INFO(" Interval (CBR): " << interval.Get().GetSeconds());
239  NS_LOG_INFO(" Data rate (OnOff): " << dataRate.Get());
240  NS_LOG_INFO(" Simulation length: " << simLength);
241  NS_LOG_INFO(" Number of GW end users: " << gwEndUsers);
242  NS_LOG_INFO(" ");
243 
247  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("sat-fwd-sys-test.xml"));
248  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
249  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
250  // ConfigStore outputConfig;
251  // outputConfig.ConfigureDefaults ();
252 
256  simulationHelper->RunSimulation();
257 
258  Simulator::Destroy();
259 
260  return 0;
261 }
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)