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  uint32_t packetSize(128); // in bytes
118  Time interval(MicroSeconds(50));
119  DataRate dataRate(DataRate(16000));
120 
122  auto simulationHelper = CreateObject<SimulationHelper>("example-fwd-system-test");
123  Config::SetDefault("ns3::SatEnvVariables::EnableSimulationOutputOverwrite", BooleanValue(true));
124 
125  Config::SetDefault("ns3::SatBbFrameConf::BbFrameHighOccupancyThreshold", DoubleValue(0.9));
126  Config::SetDefault("ns3::SatBbFrameConf::BbFrameLowOccupancyThreshold", DoubleValue(0.8));
127  Config::SetDefault("ns3::SatBbFrameConf::BBFrameUsageMode",
128  StringValue("ShortAndNormalFrames"));
129  Config::SetDefault("ns3::SatConf::FwdCarrierAllocatedBandwidth", DoubleValue(1.25e+07));
130 
131  // read command line parameters given by user
132  CommandLine cmd;
133  cmd.AddValue(
134  "testCase",
135  "Test case to execute. 0 = scheduler, ACM off, 1 = scheduler, ACM on, 2 = ACM one UT",
136  testCase);
137  cmd.AddValue("gwEndUsers", "Number of the GW end users", gwEndUsers);
138  cmd.AddValue("simLength", "Length of simulation", simLength);
139  cmd.AddValue("traceFrameInfo", "Trace (print) BB frame info", traceFrameInfo);
140  cmd.AddValue("traceMergeInfo", "Trace (print) BB frame merge info", traceMergeInfo);
141  cmd.AddValue("beamId", "Beam Id", beamId);
142  cmd.AddValue("trafficModel", "Traffic model: either 'cbr' or 'onoff'", trafficModel);
143  cmd.AddValue("senderAppStartTime", "Sender application (first) start time", senderAppStartTime);
144  cmd.Parse(argc, argv);
145 
146  if (trafficModel != "cbr" && trafficModel != "onoff")
147  {
148  NS_FATAL_ERROR("Invalid traffic model, use either 'cbr' or 'onoff'");
149  }
150 
151  simulationHelper->SetUtCountPerBeam(gwEndUsers);
152  simulationHelper->SetUserCountPerUt(1);
153  simulationHelper->SetSimulationTime(simLength);
154  simulationHelper->SetGwUserCount(gwEndUsers);
155  simulationHelper->SetBeamSet({beamId});
156 
161  switch (testCase)
162  {
163  case 0: // scheduler, ACM disabled
164  Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(false));
165  break;
166 
167  case 1: // scheduler, ACM enabled
168  Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(true));
169  break;
170 
171  case 2: // ACM enabled, one UT with one user, Markov + external fading
172  Config::SetDefault("ns3::SatBbFrameConf::AcmEnabled", BooleanValue(true));
173  Config::SetDefault("ns3::SatBeamHelper::FadingModel", StringValue("FadingMarkov"));
174 
175  // Note, that the positions of the fading files do not necessarily match with the
176  // beam location, since this example is not using list position allocator!
177  Config::SetDefault("ns3::SatChannel::EnableExternalFadingInputTrace", BooleanValue(true));
178  Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtFwdDownIndexFileName",
179  StringValue("BeamId-1_256_UT_fading_fwddwn_trace_index.txt"));
180  Config::SetDefault("ns3::SatFadingExternalInputTraceContainer::UtRtnUpIndexFileName",
181  StringValue("BeamId-1_256_UT_fading_rtnup_trace_index.txt"));
182 
183  gwEndUsers = 1;
184  break;
185 
186  default:
187  break;
188  }
189 
190  simulationHelper->LoadScenario("geo-33E");
191 
192  // Creating the reference system.
193  simulationHelper->CreateSatScenario();
194 
195  // connect BB frame TX traces on, if enabled
196  if (traceFrameInfo)
197  {
198  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/SatMac/BBFrameTxTrace",
199  MakeCallback(&PrintBbFrameInfo));
200  }
201 
202  // connect BB frame merge traces on, if enabled
203  if (traceMergeInfo)
204  {
205  Config::ConnectWithoutContext(
206  "/NodeList/*/DeviceList/*/SatMac/Scheduler/BBFrameContainer/BBFrameMergeTrace",
207  MakeCallback(&PrintBbFrameMergeInfo));
208  }
209 
213  if (trafficModel == "cbr")
214  {
215  simulationHelper->GetTrafficHelper()->AddCbrTraffic(
218  interval,
219  packetSize,
220  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
221  Singleton<SatTopology>::Get()->GetUtUserNodes(),
222  senderAppStartTime,
223  Seconds(simLength),
224  MicroSeconds(20));
225  }
226  else
227  {
228  simulationHelper->GetTrafficHelper()->AddOnOffTraffic(
231  dataRate,
232  packetSize,
233  NodeContainer(Singleton<SatTopology>::Get()->GetGwUserNode(0)),
234  Singleton<SatTopology>::Get()->GetUtUserNodes(),
235  "ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]",
236  "ns3::ExponentialRandomVariable[Mean=1.0|Bound=0.0]",
237  senderAppStartTime,
238  Seconds(simLength),
239  MicroSeconds(20));
240  }
241 
242  simulationHelper->EnableProgressLogs();
243 
244  NS_LOG_INFO("--- sat-fwd-sys-test ---");
245  NS_LOG_INFO(" Packet size: " << packetSize);
246  NS_LOG_INFO(" Interval (CBR): " << interval.GetSeconds());
247  NS_LOG_INFO(" Data rate (OnOff): " << dataRate);
248  NS_LOG_INFO(" Simulation length: " << simLength);
249  NS_LOG_INFO(" Number of GW end users: " << gwEndUsers);
250  NS_LOG_INFO(" ");
251 
255  // Config::SetDefault ("ns3::ConfigStore::Filename", StringValue ("sat-fwd-sys-test.xml"));
256  // Config::SetDefault ("ns3::ConfigStore::FileFormat", StringValue ("Xml"));
257  // Config::SetDefault ("ns3::ConfigStore::Mode", StringValue ("Save"));
258  // ConfigStore outputConfig;
259  // outputConfig.ConfigureDefaults ();
260 
264  simulationHelper->RunSimulation();
265 
266  Simulator::Destroy();
267 
268  return 0;
269 }
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)