satellite-request-manager-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: Jani Puttonen <jani.puttonen@magister.fi>
19  */
20 
29 #include "../model/satellite-control-message.h"
30 #include "../model/satellite-queue.h"
31 #include "../model/satellite-request-manager.h"
32 #include "../utils/satellite-env-variables.h"
33 
34 #include "ns3/boolean.h"
35 #include "ns3/config.h"
36 #include "ns3/log.h"
37 #include "ns3/simulator.h"
38 #include "ns3/singleton.h"
39 #include "ns3/test.h"
40 
41 using namespace ns3;
42 
48 class SatBaseTestCase : public TestCase
49 {
50  public:
52  virtual ~SatBaseTestCase();
53 
61  bool SendControlMsg(Ptr<SatControlMessage> msg, const Address& dest);
62 
69  SatQueue::QueueStats_t GetQueueStatistics(bool reset);
70 
75  bool ControlMsgTxPossible() const;
76 
77  private:
78  virtual void DoRun(void);
79 
83  std::vector<Ptr<SatCrMessage>> m_rcvdCapacityRequests;
84 };
85 
87  : TestCase("Test satellite request manager.")
88 {
89 }
90 
92 {
93 }
94 
95 void
97 {
98  // Set simulation output details
99  Singleton<SatEnvVariables>::Get()->DoInitialize();
100  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-rm", "", true);
101 
102  // Base test case tests that no Capacity Requests are generated when CRA, RBDC
103  // and VBDC are disabled for all lower layer service RC indices.
104  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_ConstantAssignmentProvided",
105  BooleanValue(false));
106  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_ConstantAssignmentProvided",
107  BooleanValue(false));
108  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_ConstantAssignmentProvided",
109  BooleanValue(false));
110  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_ConstantAssignmentProvided",
111  BooleanValue(false));
112  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_RbdcAllowed",
113  BooleanValue(false));
114  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_RbdcAllowed",
115  BooleanValue(false));
116  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_RbdcAllowed",
117  BooleanValue(false));
118  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_RbdcAllowed",
119  BooleanValue(false));
120  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService0_VolumeAllowed",
121  BooleanValue(false));
122  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService1_VolumeAllowed",
123  BooleanValue(false));
124  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService2_VolumeAllowed",
125  BooleanValue(false));
126  Config::SetDefault("ns3::SatLowerLayerServiceConf::DaService3_VolumeAllowed",
127  BooleanValue(false));
128 
129  Ptr<SatLowerLayerServiceConf> llsConf = CreateObject<SatLowerLayerServiceConf>();
130 
131  Time superFrameDuration(MilliSeconds(100));
132 
133  // Create and initialize request manager
134  Ptr<SatNodeInfo> nodeInfo = Create<SatNodeInfo>(SatEnums::NT_UT, 0, Mac48Address::Allocate());
135  Ptr<SatRequestManager> rm = CreateObject<SatRequestManager>();
136  rm->SetNodeInfo(nodeInfo);
137  rm->Initialize(llsConf, superFrameDuration);
138 
139  rm->SetCtrlMsgTxPossibleCallback(MakeCallback(&SatBaseTestCase::ControlMsgTxPossible, this));
140 
141  // Set send control message callback
142  rm->SetCtrlMsgCallback(MakeCallback(&SatBaseTestCase::SendControlMsg, this));
143 
144  // Set queue statistics callbacks
145  Callback<SatQueue::QueueStats_t, bool> cb =
146  MakeCallback(&SatBaseTestCase::GetQueueStatistics, this);
147  for (uint8_t rc = 0; rc < llsConf->GetDaServiceCount(); ++rc)
148  {
149  rm->AddQueueCallback(rc, cb);
150  }
151 
152  Simulator::Stop(Seconds(10));
153  Simulator::Run();
154 
155  NS_TEST_ASSERT_MSG_EQ(m_rcvdCapacityRequests.empty(), true, "Capacity requests received!");
156 
157  Simulator::Destroy();
158 
159  Singleton<SatEnvVariables>::Get()->DoDispose();
160 }
161 
162 bool
163 SatBaseTestCase::SendControlMsg(Ptr<SatControlMessage> msg, const Address& dest)
164 {
165  if (msg->GetMsgType() == SatControlMsgTag::SAT_CR_CTRL_MSG)
166  {
167  Ptr<SatCrMessage> cr = DynamicCast<SatCrMessage>(msg);
168  if (cr == NULL)
169  {
170  NS_FATAL_ERROR("Dynamic cast to CR message failed!");
171  }
172  m_rcvdCapacityRequests.push_back(cr);
173  }
174  else
175  {
176  // Also CNo reports arrive here
177  }
178  return true;
179 }
180 
183 {
184  SatQueue::QueueStats_t queueStats;
185 
186  queueStats.m_incomingRateKbps = 10;
187  queueStats.m_outgoingRateKbps = 10;
188  queueStats.m_volumeInBytes = 10;
189  queueStats.m_volumeOutBytes = 10;
190  queueStats.m_queueSizeBytes = 10;
191 
192  return queueStats;
193 }
194 
195 bool
197 {
198  return true;
199 }
200 
204 class SatRequestManagerTestSuite : public TestSuite
205 {
206  public:
208 };
209 
211  : TestSuite("sat-rm-test", UNIT)
212 {
213  AddTestCase(new SatBaseTestCase, TestCase::QUICK);
214 }
215 
216 // Do allocate an instance of this TestSuite
Test case to unit test the UT request manager.
std::vector< Ptr< SatCrMessage > > m_rcvdCapacityRequests
Received CRs.
bool SendControlMsg(Ptr< SatControlMessage > msg, const Address &dest)
Send control message called with a callback from request manager.
SatQueue::QueueStats_t GetQueueStatistics(bool reset)
Get queue statistics for request manager.
bool ControlMsgTxPossible() const
Check whether a control message transmission is possible.
Test suite for Satellite Request Manager unit test cases.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatRequestManagerTestSuite satRmTestSuite
QueueStats_t definition for passing queue related statistics to any interested modules.