satellite-cra-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 SatCraTest1 : public TestCase
62 {
63  public:
64  SatCraTest1();
65  virtual ~SatCraTest1();
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("'CRA, test 1' case tests successful transmission of UDP packets from UT connected "
74  "user to GW connected user in simple scenario with only CRA enabled.")
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 // SatCraTest1 TestCase implementation
86 //
87 void
89 {
90  // Set simulation output details
91  Singleton<SatEnvVariables>::Get()->DoInitialize();
92  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-cra", "", 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  // Disable Random Access
102  Config::SetDefault("ns3::SatBeamHelper::RandomAccessModel", EnumValue(SatEnums::RA_MODEL_OFF));
103 
104  // Enable CRA and disable DA
105  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
106  BooleanValue(false));
107  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
108  BooleanValue(false));
109  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
110  BooleanValue(false));
111  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
112  BooleanValue(true));
113  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
114  BooleanValue(false));
115  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
116  BooleanValue(false));
117  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
118  BooleanValue(false));
119  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
120  BooleanValue(false));
121  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
122  BooleanValue(false));
123  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
124  BooleanValue(false));
125  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
126  BooleanValue(false));
127  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
128  BooleanValue(false));
129 
130  // Creating the reference system.
131  Ptr<SatHelper> helper = CreateObject<SatHelper>();
132  helper->CreatePredefinedScenario(SatHelper::SIMPLE);
133 
134  // >>> Start of actual test using Simple scenario >>>
135 
136  NodeContainer gwUsers = helper->GetGwUsers();
137 
138  // Create the Cbr application to send UDP datagrams of size
139  // 512 bytes at a rate of 500 Kb/s (defaults), one packet send (interval 1s)
140  uint16_t port = 9; // Discard port (RFC 863)
141  CbrHelper cbr("ns3::UdpSocketFactory",
142  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
143  cbr.SetAttribute("Interval", StringValue("1s"));
144 
145  ApplicationContainer utApps = cbr.Install(helper->GetUtUsers());
146  utApps.Start(Seconds(1.0));
147  utApps.Stop(Seconds(2.1));
148 
149  // Create a packet sink to receive these packets
150  PacketSinkHelper sink("ns3::UdpSocketFactory",
151  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
152 
153  ApplicationContainer gwApps = sink.Install(gwUsers);
154  gwApps.Start(Seconds(1.0));
155  gwApps.Stop(Seconds(3.0));
156 
157  Simulator::Stop(Seconds(11));
158  Simulator::Run();
159 
160  Simulator::Destroy();
161 
162  Ptr<PacketSink> receiver = DynamicCast<PacketSink>(gwApps.Get(0));
163  Ptr<CbrApplication> sender = DynamicCast<CbrApplication>(utApps.Get(0));
164 
165  // here we check that results are as expected.
166  // * Sender has sent something
167  // * Receiver got all all data sent
168  NS_TEST_ASSERT_MSG_NE(sender->GetSent(), (uint32_t)0, "Nothing sent !");
169  NS_TEST_ASSERT_MSG_EQ(receiver->GetTotalRx(), sender->GetSent(), "Packets were lost !");
170 
171  Singleton<SatEnvVariables>::Get()->DoDispose();
172 
173  // <<< End of actual test using Simple scenario <<<
174 }
175 
176 // The TestSuite class names the TestSuite as sat-cra-test, identifies what type of TestSuite
177 // (SYSTEM), and enables the TestCases to be run. Typically, only the constructor for this class
178 // must be defined
179 //
180 class SatCraTestSuite : public TestSuite
181 {
182  public:
183  SatCraTestSuite();
184 };
185 
187  : TestSuite("sat-cra-test", SYSTEM)
188 {
189  AddTestCase(new SatCraTest1, TestCase::QUICK);
190 }
191 
192 // Allocate an instance of this TestSuite
'CRA, test 1' test case implementation.
virtual ~SatCraTest1()
virtual void DoRun(void)
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatCraTestSuite satCraTestSuite