satellite-periodic-control-message-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 
64 class SatPeriodicControlMessageTest1 : public TestCase
65 {
66  public:
69 
70  private:
71  virtual void DoRun(void);
72 };
73 
74 // Add some help text to this case to describe what it is intended to test
76  : TestCase("'Periodic control message, test 1' case tests successful transmission of UDP "
77  "packets from UT connected user to GW connected user in simple scenario with "
78  "periodic control messages.")
79 {
80 }
81 
82 // This destructor does nothing but we include it as a reminder that
83 // the test case should clean up after itself
85 {
86 }
87 
88 //
89 // SatPeriodicControlMessageTest1 TestCase implementation
90 //
91 void
93 {
94  // Set simulation output details
95  Singleton<SatEnvVariables>::Get()->DoInitialize();
96  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-periodic-control-message",
97  "",
98  true);
99 
100  // Create simple scenario
101 
102  // Configure a static error probability
103  SatPhyRxCarrierConf::ErrorModel em(SatPhyRxCarrierConf::EM_NONE);
104  Config::SetDefault("ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
105  Config::SetDefault("ns3::SatGwHelper::RtnLinkErrorModel", EnumValue(em));
106 
107  // Disable Random Access
108  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_OFF));
109 
110  // Enable periodic control slots
111  Config::SetDefault("ns3::SatBeamScheduler::ControlSlotsEnabled", BooleanValue(true));
112 
113  // Enable CRA and disable DA
114  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
115  BooleanValue(false));
116  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
117  BooleanValue(false));
118  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
119  BooleanValue(false));
120  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
121  BooleanValue(false));
122  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
123  BooleanValue(false));
124  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
125  BooleanValue(false));
126  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
127  BooleanValue(false));
128  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
129  BooleanValue(false));
130  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
131  BooleanValue(false));
132  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
133  BooleanValue(false));
134  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
135  BooleanValue(false));
136  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
137  BooleanValue(true));
138 
139  // Creating the reference system.
140  Ptr<SatHelper> helper = CreateObject<SatHelper>();
141  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
142 
143  // >>> Start of actual test using Simple scenario >>>
144 
145  NodeContainer gwUsers = helper->GetGwUsers();
146 
147  // Create the Cbr application to send UDP datagrams of size
148  // 512 bytes at a rate of 500 Kb/s (defaults), one packet send (interval 1s)
149  uint16_t port = 9; // Discard port (RFC 863)
150  CbrHelper cbr("ns3::UdpSocketFactory",
151  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
152  cbr.SetAttribute("Interval", StringValue("1s"));
153 
154  ApplicationContainer utApps = cbr.Install(helper->GetUtUsers());
155  utApps.Start(Seconds(1.0));
156  utApps.Stop(Seconds(2.1));
157 
158  // Create a packet sink to receive these packets
159  PacketSinkHelper sink("ns3::UdpSocketFactory",
160  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
161 
162  ApplicationContainer gwApps = sink.Install(gwUsers);
163  gwApps.Start(Seconds(1.0));
164  gwApps.Stop(Seconds(10.0));
165 
166  Simulator::Stop(Seconds(11));
167  Simulator::Run();
168 
169  Simulator::Destroy();
170 
171  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(gwApps.Get(0));
172  Ptr<CbrApplication> sender = DynamicCast<CbrApplication>(utApps.Get(0));
173 
174  // here we check that results are as expected.
175  // * Sender has sent something
176  // * Receiver got all data sent
177  NS_TEST_ASSERT_MSG_NE(sender->GetSent(), (uint32_t)0, "Nothing sent !");
178  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), sender->GetSent(), "Packets were lost !");
179 
180  Singleton<SatEnvVariables>::Get()->DoDispose();
181  // <<< End of actual test using Simple scenario <<<
182 }
183 
184 // The TestSuite class names the TestSuite as sat-periodic-control-message-test, identifies what
185 // type of TestSuite (SYSTEM), and enables the TestCases to be run. Typically, only the constructor
186 // for this class must be defined
187 //
188 class SatPeriodicControlMessageTestSuite : public TestSuite
189 {
190  public:
192 };
193 
195  : TestSuite("sat-periodic-control-message-test", SYSTEM)
196 {
197  AddTestCase(new SatPeriodicControlMessageTest1, TestCase::QUICK);
198 }
199 
200 // Allocate an instance of this TestSuite
'Periodic control message, test 1' test case implementation.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatPeriodicControlMessageTestSuite satPeriodicControlMessageTestSuite