satellite-random-access-test.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 Ltd
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: Frans Laakso <frans.laakso@magister.fi>
19  */
20 
30 #include "../helper/satellite-helper.h"
31 #include "../utils/satellite-env-variables.h"
32 
33 #include "ns3/cbr-application.h"
34 #include "ns3/cbr-helper.h"
35 #include "ns3/config.h"
36 #include "ns3/enum.h"
37 #include "ns3/log.h"
38 #include "ns3/packet-sink-helper.h"
39 #include "ns3/packet-sink.h"
40 #include "ns3/simulator.h"
41 #include "ns3/singleton.h"
42 #include "ns3/string.h"
43 #include "ns3/test.h"
44 
45 using namespace ns3;
46 
61 class SatCrdsaTest1 : public TestCase
62 {
63  public:
64  SatCrdsaTest1();
65  virtual ~SatCrdsaTest1();
66 
67  private:
68  virtual void DoRun(void);
69 };
70 
71 // Add some help text to this case to describe what it is intended to test
73  : TestCase("'CRDSA, test 1' case tests successful transmission of UDP packets from UT "
74  "connected user to GW connected user in simple scenario using only CRDSA.")
75 {
76 }
77 
78 // This destructor does nothing but we include it as a reminder that
79 // the test case should clean up after itself
81 {
82 }
83 
84 //
85 // SatCrdsaTest1 TestCase implementation
86 //
87 void
89 {
90  // Set simulation output details
91  Singleton<SatEnvVariables>::Get()->DoInitialize();
92  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-random-access", "crdsa", true);
93 
94  // Create simple scenario
95 
96  // Configure a static error probability
97  SatPhyRxCarrierConf::ErrorModel em(SatPhyRxCarrierConf::EM_NONE);
98  Config::SetDefault("ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
99  Config::SetDefault("ns3::SatGwHelper::RtnLinkErrorModel", EnumValue(em));
100 
101  // Enable Random Access with RCS2 specification
102  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
103  EnumValue(SatEnums::RA_MODEL_RCS2_SPECIFICATION));
104 
105  // Set Random Access interference model
106  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
107  EnumValue(SatPhyRxCarrierConf::IF_PER_PACKET));
108 
109  // Set Random Access collision model
110  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
111  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
112 
113  // Disable periodic control slots
114  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(false));
115 
116  // Disable dynamic load control
117  Config::SetDefault("ns3::SatPhyRxCarrierConf::EnableRandomAccessDynamicLoadControl",
118  BooleanValue(false));
119  Config::SetDefault(
120  "ns3::SatPhyRxCarrierConf::RandomAccessAverageNormalizedOfferedLoadMeasurementWindowSize",
121  UintegerValue(10));
122 
123  // Set random access parameters (e.g. enable CRDSA)
124  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumUniquePayloadPerBlock",
125  UintegerValue(3));
126  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumConsecutiveBlockAccessed",
127  UintegerValue(6));
128  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MinimumIdleBlock",
129  UintegerValue(2));
130  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffTimeInMilliSeconds",
131  UintegerValue(250));
132  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffProbability",
133  UintegerValue(1));
134  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_HighLoadBackOffProbability",
135  UintegerValue(1));
136  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_NumberOfInstances",
137  UintegerValue(3));
138  Config::SetDefault(
139  "ns3::SatLowerLayerServiceConf::RaService0_AverageNormalizedOfferedLoadThreshold",
140  DoubleValue(0.5));
141  Config::SetDefault("ns3::SatLowerLayerServiceConf::DefaultControlRandomizationInterval",
142  TimeValue(MilliSeconds(100)));
143  Config::SetDefault("ns3::SatRandomAccessConf::CrdsaSignalingOverheadInBytes", UintegerValue(5));
144  Config::SetDefault("ns3::SatRandomAccessConf::SlottedAlohaSignalingOverheadInBytes",
145  UintegerValue(3));
146 
147  // Disable CRA and DA
148  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
149  BooleanValue(false));
150  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
151  BooleanValue(false));
152  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
153  BooleanValue(false));
154  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
155  BooleanValue(false));
156  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
157  BooleanValue(false));
158  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
159  BooleanValue(false));
160  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
161  BooleanValue(false));
162  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
163  BooleanValue(false));
164  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
165  BooleanValue(false));
166  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
167  BooleanValue(false));
168  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
169  BooleanValue(false));
170  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
171  BooleanValue(false));
172 
173  // Creating the reference system.
174  Ptr<SatHelper> helper = CreateObject<SatHelper>();
175  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
176 
177  // >>> Start of actual test using Simple scenario >>>
178 
179  NodeContainer gwUsers = helper->GetGwUsers();
180 
181  // Create the Cbr application to send UDP datagrams of size
182  // 512 bytes at a rate of 500 Kb/s (defaults), one packet send (interval 1s)
183  uint16_t port = 9; // Discard port (RFC 863)
184  CbrHelper cbr("ns3::UdpSocketFactory",
185  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
186  cbr.SetAttribute("Interval", StringValue("1s"));
187  cbr.SetAttribute("PacketSize", UintegerValue(64));
188 
189  ApplicationContainer utApps = cbr.Install(helper->GetUtUsers());
190  utApps.Start(Seconds(1.0));
191  utApps.Stop(Seconds(2.1));
192 
193  // Create a packet sink to receive these packets
194  PacketSinkHelper sink("ns3::UdpSocketFactory",
195  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
196 
197  ApplicationContainer gwApps = sink.Install(gwUsers);
198  gwApps.Start(Seconds(1.0));
199  gwApps.Stop(Seconds(10.0));
200 
201  Simulator::Stop(Seconds(11));
202  Simulator::Run();
203 
204  Simulator::Destroy();
205 
206  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(gwApps.Get(0));
207  Ptr<CbrApplication> sender = DynamicCast<CbrApplication>(utApps.Get(0));
208 
209  // here we check that results are as expected.
210  // * Sender has sent something
211  // * Receiver got all all data sent
212  NS_TEST_ASSERT_MSG_NE(sender->GetSent(), (uint32_t)0, "Nothing sent !");
213  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), sender->GetSent(), "Packets were lost !");
214 
215  Singleton<SatEnvVariables>::Get()->DoDispose();
216  // <<< End of actual test using Simple scenario <<<
217 }
218 
237 class SatSlottedAlohaTest1 : public TestCase
238 {
239  public:
241  virtual ~SatSlottedAlohaTest1();
242 
243  private:
244  virtual void DoRun(void);
245 };
246 
247 // Add some help text to this case to describe what it is intended to test
249  : TestCase("'Slotted ALOHA, test 1' case tests successful transmission of UDP packets from UT "
250  "connected user to GW connected user in simple scenario using Slotted ALOHA for "
251  "control messages and VBDC for data.")
252 {
253 }
254 
255 // This destructor does nothing but we include it as a reminder that
256 // the test case should clean up after itself
258 {
259 }
260 
261 //
262 // SatSlottedAlohaTest1 TestCase implementation
263 //
264 void
266 {
267  // Set simulation output details
268  Singleton<SatEnvVariables>::Get()->DoInitialize();
269  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-random-access",
270  "slottedAloha",
271  true);
272 
273  // Create simple scenario
274 
275  // Configure a static error probability
276  SatPhyRxCarrierConf::ErrorModel em(SatPhyRxCarrierConf::EM_NONE);
277  Config::SetDefault("ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
278  Config::SetDefault("ns3::SatGwHelper::RtnLinkErrorModel", EnumValue(em));
279 
280  // Enable Random Access with RCS2 specification
281  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel",
282  EnumValue(SatEnums::RA_MODEL_RCS2_SPECIFICATION));
283 
284  // Set Random Access interference model
285  Config::SetDefault("ns3::SatBeamHelper::RaInterferenceModel",
286  EnumValue(SatPhyRxCarrierConf::IF_PER_PACKET));
287 
288  // Set Random Access collision model
289  Config::SetDefault("ns3::SatBeamHelper::RaCollisionModel",
290  EnumValue(SatPhyRxCarrierConf::RA_COLLISION_CHECK_AGAINST_SINR));
291 
292  // Disable periodic control slots
293  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(false));
294 
295  // Disable dynamic load control
296  Config::SetDefault("ns3::SatPhyRxCarrierConf::EnableRandomAccessDynamicLoadControl",
297  BooleanValue(false));
298  Config::SetDefault(
299  "ns3::SatPhyRxCarrierConf::RandomAccessAverageNormalizedOfferedLoadMeasurementWindowSize",
300  UintegerValue(10));
301 
302  // Set random access parameters (e.g. enable Slotted ALOHA)
303  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumUniquePayloadPerBlock",
304  UintegerValue(3));
305  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MaximumConsecutiveBlockAccessed",
306  UintegerValue(6));
307  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_MinimumIdleBlock",
308  UintegerValue(2));
309  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffTimeInMilliSeconds",
310  UintegerValue(250));
311  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_BackOffProbability",
312  UintegerValue(1));
313  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_HighLoadBackOffProbability",
314  UintegerValue(1));
315  Config::SetDefault("ns3::SatLowerLayerServiceConf::RaService0_NumberOfInstances",
316  UintegerValue(1));
317  Config::SetDefault(
318  "ns3::SatLowerLayerServiceConf::RaService0_AverageNormalizedOfferedLoadThreshold",
319  DoubleValue(0.5));
320  Config::SetDefault("ns3::SatLowerLayerServiceConf::DefaultControlRandomizationInterval",
321  TimeValue(MilliSeconds(100)));
322  Config::SetDefault("ns3::SatRandomAccessConf::CrdsaSignalingOverheadInBytes", UintegerValue(5));
323  Config::SetDefault("ns3::SatRandomAccessConf::SlottedAlohaSignalingOverheadInBytes",
324  UintegerValue(3));
325 
326  // Disable CRA and DA
327  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
328  BooleanValue(false));
329  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
330  BooleanValue(false));
331  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
332  BooleanValue(false));
333  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
334  BooleanValue(false));
335  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
336  BooleanValue(false));
337  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
338  BooleanValue(false));
339  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
340  BooleanValue(false));
341  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
342  BooleanValue(false));
343  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
344  BooleanValue(false));
345  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
346  BooleanValue(false));
347  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
348  BooleanValue(false));
349  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
350  BooleanValue(true));
351 
352  // Creating the reference system.
353  Ptr<SatHelper> helper = CreateObject<SatHelper>();
354  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
355 
356  // >>> Start of actual test using Simple scenario >>>
357 
358  NodeContainer gwUsers = helper->GetGwUsers();
359 
360  // Create the Cbr application to send UDP datagrams of size
361  // 512 bytes at a rate of 500 Kb/s (defaults), one packet send (interval 1s)
362  uint16_t port = 9; // Discard port (RFC 863)
363  CbrHelper cbr("ns3::UdpSocketFactory",
364  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
365  cbr.SetAttribute("Interval", StringValue("1s"));
366  cbr.SetAttribute("PacketSize", UintegerValue(64));
367 
368  ApplicationContainer utApps = cbr.Install(helper->GetUtUsers());
369  utApps.Start(Seconds(1.0));
370  utApps.Stop(Seconds(2.1));
371 
372  // Create a packet sink to receive these packets
373  PacketSinkHelper sink("ns3::UdpSocketFactory",
374  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
375 
376  ApplicationContainer gwApps = sink.Install(gwUsers);
377  gwApps.Start(Seconds(1.0));
378  gwApps.Stop(Seconds(10.0));
379 
380  Simulator::Stop(Seconds(11));
381  Simulator::Run();
382 
383  Simulator::Destroy();
384 
385  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(gwApps.Get(0));
386  Ptr<CbrApplication> sender = DynamicCast<CbrApplication>(utApps.Get(0));
387 
388  // here we check that results are as expected.
389  // * Sender has sent something
390  // * Receiver got all all data sent
391  NS_TEST_ASSERT_MSG_NE(sender->GetSent(), (uint32_t)0, "Nothing sent !");
392  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), sender->GetSent(), "Packets were lost !");
393 
394  Singleton<SatEnvVariables>::Get()->DoDispose();
395  // <<< End of actual test using Simple scenario <<<
396 }
397 
398 // The TestSuite class names the TestSuite as sat-random-access-test, identifies what type of
399 // TestSuite (SYSTEM), and enables the TestCases to be run. Typically, only the constructor for
400 // this class must be defined
401 //
402 class SatRandomAccessTestSuite : public TestSuite
403 {
404  public:
406 };
407 
409  : TestSuite("sat-random-access-test", SYSTEM)
410 {
411  AddTestCase(new SatCrdsaTest1, TestCase::QUICK);
412 
413  AddTestCase(new SatSlottedAlohaTest1, TestCase::QUICK);
414 }
415 
416 // Allocate an instance of this TestSuite
'CRDSA, test 1' test case implementation.
virtual void DoRun(void)
'Slotted ALOHA, test 1' test case implementation.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatRandomAccessTestSuite satRandomAccessTestSuite