satellite-control-msg-container-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: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
27 // Include a header file from your module to test.
28 #include "../model/satellite-control-message.h"
29 #include "../utils/satellite-env-variables.h"
30 
31 #include "ns3/boolean.h"
32 #include "ns3/config.h"
33 #include "ns3/log.h"
34 #include "ns3/simulator.h"
35 #include "ns3/singleton.h"
36 #include "ns3/string.h"
37 #include "ns3/test.h"
38 #include "ns3/timer.h"
39 
40 using namespace ns3;
41 
42 class SatCtrlMsgContBaseTestCase : public TestCase
43 {
44  public:
46  : TestCase("")
47  {
48  }
49 
50  SatCtrlMsgContBaseTestCase(std::string info)
51  : TestCase(info)
52  {
53  }
54 
56  {
57  }
58 
59  // add message to container
60  void AddMessage(Ptr<SatControlMessage> msg);
61 
62  // get message.
63  void GetMessage(uint32_t msgId);
64 
65  protected:
66  virtual void DoRun(void) = 0;
67  Ptr<SatControlMsgContainer> m_container;
68  std::vector<Ptr<SatControlMessage>> m_msgsRead;
69 
70  private:
71  std::vector<uint32_t> m_recvIds;
72 };
73 
74 void
75 SatCtrlMsgContBaseTestCase::AddMessage(Ptr<SatControlMessage> msg)
76 {
77  uint32_t sendId = m_container->ReserveIdAndStore(msg);
78  uint32_t recvId = m_container->Send(sendId);
79 
80  m_recvIds.push_back(recvId);
81 }
82 
83 void
85 {
86  m_msgsRead.push_back(m_container->Read(msgId));
87 }
88 
107 {
108  public:
111  "Test satellite control message container with flag deletedOnRead set.")
112  {
113  }
114 
116  {
117  }
118 
119  protected:
120  virtual void DoRun(void);
121 };
122 
123 void
125 {
126  // Set simulation output details
127  Singleton<SatEnvVariables>::Get()->DoInitialize();
128  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-ctrl-msg-container-unit",
129  "delon",
130  true);
131 
132  // create container with store time 100 ms and flag deletedOnRead set
133  m_container = Create<SatControlMsgContainer>(Seconds(0.10), true);
134  Ptr<SatControlMessage> crMsg = Create<SatCrMessage>();
135  Ptr<SatControlMessage> tbtpMsg = Create<SatTbtpMessage>();
136 
137  // simulate message additions
138  Simulator::Schedule(Seconds(0.09),
140  this,
141  crMsg); // id 0
142  Simulator::Schedule(Seconds(0.20),
144  this,
145  tbtpMsg); // id 1
146  Simulator::Schedule(Seconds(0.31),
148  this,
149  tbtpMsg); // id 2
150  Simulator::Schedule(Seconds(0.40),
152  this,
153  crMsg); // id 3
154 
155  // simulate get operations
156  Simulator::Schedule(Seconds(0.10),
158  this,
159  0); // crMsg expected
160  Simulator::Schedule(Seconds(0.21),
162  this,
163  1); // tbtpMsg expected
164  Simulator::Schedule(Seconds(0.35),
166  this,
167  2); // tbtpMsg expected
168  Simulator::Schedule(Seconds(0.43),
170  this,
171  3); // crMsg expected
172 
173  Simulator::Run();
174 
175  // After simulation check that messages are what expected
176 
177  // ref messages created successfully
178  NS_TEST_ASSERT_MSG_EQ((crMsg == NULL), false, "CR message creation failed");
179  NS_TEST_ASSERT_MSG_EQ((tbtpMsg == NULL), false, "TBTP message failed");
180 
181  // container content correct at points messages got
182  NS_TEST_ASSERT_MSG_EQ((m_msgsRead[0] == crMsg), true, "first message incorrect");
183  NS_TEST_ASSERT_MSG_EQ((m_msgsRead[1] == tbtpMsg), true, "second message incorrect");
184  NS_TEST_ASSERT_MSG_EQ((m_msgsRead[2] == tbtpMsg), true, "third message incorrect");
185  NS_TEST_ASSERT_MSG_EQ((m_msgsRead[3] == crMsg), true, "fourth message incorrect");
186 
187  Simulator::Destroy();
188 
189  Singleton<SatEnvVariables>::Get()->DoDispose();
190 }
191 
210 {
211  public:
214  "Test satellite control message container with flag deletedOnRead NOT set.")
215  {
216  }
217 
219  {
220  }
221 
222  protected:
223  virtual void DoRun(void);
224 };
225 
226 void
228 {
229  // Set simulation output details
230  Singleton<SatEnvVariables>::Get()->DoInitialize();
231  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-ctrl-msg-container-unit",
232  "deloff",
233  true);
234 
235  // create container with store time 100 ms and flag deletedOnRead NOT set
236  m_container = Create<SatControlMsgContainer>(Seconds(0.10), false);
237  Ptr<SatControlMessage> crMsg = Create<SatCrMessage>();
238  Ptr<SatControlMessage> tbtpMsg = Create<SatTbtpMessage>();
239 
240  // simulate message additions
241  Simulator::Schedule(Seconds(0.09),
243  this,
244  crMsg); // id 0
245  Simulator::Schedule(Seconds(0.20),
247  this,
248  tbtpMsg); // id 1
249  Simulator::Schedule(Seconds(0.31),
251  this,
252  tbtpMsg); // id 2
253  Simulator::Schedule(Seconds(0.40),
255  this,
256  crMsg); // id 3
257 
258  // simulate get operations
259  Simulator::Schedule(Seconds(0.10),
261  this,
262  0); // crMsg expected
263  Simulator::Schedule(Seconds(0.21),
265  this,
266  1); // tbtpMsg expected
267  Simulator::Schedule(Seconds(0.40),
269  this,
270  2); // tbtpMsg expected
271  Simulator::Schedule(Seconds(0.49),
273  this,
274  3); // crMsg expected
275 
276  Simulator::Run();
277 
278  // After simulation check that messages are what expected
279 
280  // ref messages created successfully
281  NS_TEST_ASSERT_MSG_EQ((crMsg == NULL), false, "CR message creation failed");
282  NS_TEST_ASSERT_MSG_EQ((tbtpMsg == NULL), false, "TBTP message failed");
283 
284  // container content correct at points messages got
285  NS_TEST_ASSERT_MSG_EQ((m_msgsRead[0] == crMsg), true, "first message incorrect");
286  NS_TEST_ASSERT_MSG_EQ((m_msgsRead[1] == tbtpMsg), true, "second message incorrect");
287  NS_TEST_ASSERT_MSG_EQ((m_msgsRead[2] == tbtpMsg), true, "third message incorrect");
288  NS_TEST_ASSERT_MSG_EQ((m_msgsRead[3] == crMsg), true, "fourth message incorrect");
289 
290  Simulator::Destroy();
291 
292  Singleton<SatEnvVariables>::Get()->DoDispose();
293 }
294 
299 class SatCtrlMsgContainerTestSuite : public TestSuite
300 {
301  public:
303 };
304 
306  : TestSuite("sat-ctrl-msg-container-unit-test", UNIT)
307 {
308  AddTestCase(new SatCtrlMsgContDelOnTestCase, TestCase::QUICK);
309  AddTestCase(new SatCtrlMsgContDelOffTestCase, TestCase::QUICK);
310 }
311 
312 // Do allocate an instance of this TestSuite
virtual void DoRun(void)=0
void AddMessage(Ptr< SatControlMessage > msg)
std::vector< Ptr< SatControlMessage > > m_msgsRead
Test case to unit test satellite control message container with flag deletedOnRead not set.
Test case to unit test satellite control message container with flag deletedOnRead set.
Test suite for Satellite control message container unit test cases.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatCtrlMsgContainerTestSuite satCtrlMsgContUnit