satellite-performance-memory-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 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: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
31 #include "../helper/satellite-helper.h"
32 #include "../utils/satellite-env-variables.h"
33 
34 #include "ns3/cbr-application.h"
35 #include "ns3/cbr-helper.h"
36 #include "ns3/config.h"
37 #include "ns3/enum.h"
38 #include "ns3/log.h"
39 #include "ns3/packet-sink-helper.h"
40 #include "ns3/packet-sink.h"
41 #include "ns3/simulator.h"
42 #include "ns3/singleton.h"
43 #include "ns3/string.h"
44 #include "ns3/test.h"
45 
46 using namespace ns3;
47 
68 class Pm1 : public TestCase
69 {
70  public:
71  Pm1();
72  virtual ~Pm1();
73 
74  private:
75  virtual void DoRun(void);
76 };
77 
78 // Add some help text to this case to describe what it is intended to test
80  : TestCase("'Performance and memory tracking' tests servers as follow-up test for performance "
81  "and memory usage.")
82 {
83 }
84 
85 // This destructor does nothing but we include it as a reminder that
86 // the test case should clean up after itself
88 {
89 }
90 
91 //
92 // Pm1 TestCase implementation
93 //
94 void
96 {
97  // Set simulation output details
98  Singleton<SatEnvVariables>::Get()->DoInitialize();
99  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-perf-mem", "", true);
100 
101  // Create simple scenario
102 
103  // Configure a static error probability
104  SatPhyRxCarrierConf::ErrorModel em(SatPhyRxCarrierConf::EM_NONE);
105  Config::SetDefault("ns3::SatUtHelper::FwdLinkErrorModel", EnumValue(em));
106  Config::SetDefault("ns3::SatGwHelper::RtnLinkErrorModel", EnumValue(em));
107 
108  // Creating the reference system.
109  Ptr<SatHelper> helper = CreateObject<SatHelper>();
110  helper->CreatePredefinedScenario(SatHelper::FULL);
111 
112  NodeContainer gwUsers = helper->GetGwUsers();
113  NodeContainer utUsers = helper->GetUtUsers();
114 
115  uint16_t port = 9; // Discard port (RFC 863)
116  CbrHelper cbr("ns3::UdpSocketFactory",
117  Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port)));
118  cbr.SetAttribute("Interval", StringValue("0.8s"));
119 
120  // Create a packet sink to receive packet and a Cbr to sent packet in UT
121  PacketSinkHelper sink("ns3::UdpSocketFactory",
122  Address(InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port)));
123 
124  ApplicationContainer utApps = sink.Install(utUsers.Get(0));
125  utApps.Add(cbr.Install(utUsers.Get(0)));
126  utApps.Start(Seconds(1.0));
127  utApps.Stop(Seconds(2.5));
128 
129  // Create a packet sink to receive packet and a Cbr to sent packet in GW
130  sink.SetAttribute(
131  "Local",
132  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(gwUsers.Get(0)), port))));
133  cbr.SetAttribute(
134  "Remote",
135  AddressValue(Address(InetSocketAddress(helper->GetUserAddress(utUsers.Get(0)), port))));
136 
137  ApplicationContainer gwApps = sink.Install(gwUsers.Get(0));
138  gwApps.Add(cbr.Install(gwUsers.Get(0)));
139 
140  gwApps.Start(Seconds(1.0));
141  gwApps.Stop(Seconds(2.5));
142 
143  Simulator::Stop(Seconds(2.5));
144  Simulator::Run();
145 
146  Simulator::Destroy();
147 
148  Ptr<PacketSink> utReceiver = DynamicCast<PacketSink>(utApps.Get(0));
149  Ptr<CbrApplication> utSender = DynamicCast<CbrApplication>(utApps.Get(1));
150 
151  Ptr<PacketSink> gwReceiver = DynamicCast<PacketSink>(gwApps.Get(0));
152  Ptr<CbrApplication> gwSender = DynamicCast<CbrApplication>(gwApps.Get(1));
153 
154  // here we check that results are as expected.
155  // * Sender has sent something
156  // * Receiver got all all data sent
157  NS_TEST_ASSERT_MSG_NE(utSender->GetSent(), (uint32_t)0, "Nothing sent by UT user!");
158  NS_TEST_ASSERT_MSG_EQ(gwReceiver->GetTotalRx(),
159  utSender->GetSent(),
160  "Packets were lost between UT and GW!");
161 
162  NS_TEST_ASSERT_MSG_NE(gwSender->GetSent(), (uint32_t)0, "Nothing sent by GW user!");
163  NS_TEST_ASSERT_MSG_EQ(utReceiver->GetTotalRx(),
164  gwSender->GetSent(),
165  "Packets were lost between GW and UT!");
166 
167  Singleton<SatEnvVariables>::Get()->DoDispose();
168  // <<< End of actual test using Simple scenario <<<
169 }
170 
171 // The TestSuite class names the TestSuite as sat-perf-mem, identifies what type of TestSuite
172 // (SYSTEM), and enables the TestCases to be run. Typically, only the constructor for this class
173 // must be defined
174 //
175 class PerfMemTestSuite : public TestSuite
176 {
177  public:
179 };
180 
182  : TestSuite("sat-perf-mem", SYSTEM)
183 {
184  // add pm-1 case to suite sat-perf-mem
185  AddTestCase(new Pm1, TestCase::QUICK);
186 }
187 
188 // Allocate an instance of this TestSuite
'Performance and memory tracking' test case implementation, id: pm-1 / TN4.
virtual void DoRun(void)
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static PerfMemTestSuite perfMemSuite