satellite-rle-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 
27 #include "../model/satellite-queue.h"
28 #include "../model/satellite-return-link-encapsulator.h"
29 #include "../utils/satellite-env-variables.h"
30 
31 #include "ns3/callback.h"
32 #include "ns3/log.h"
33 #include "ns3/packet.h"
34 #include "ns3/ptr.h"
35 #include "ns3/random-variable-stream.h"
36 #include "ns3/singleton.h"
37 #include "ns3/test.h"
38 
39 #include <vector>
40 
41 using namespace ns3;
42 
56 class SatRleTestCase : public TestCase
57 {
58  public:
60  virtual ~SatRleTestCase();
61 
68  void Receive(Ptr<Packet> p, Mac48Address source, Mac48Address dest);
69 
70  private:
71  virtual void DoRun(void);
72 
76  std::vector<uint32_t> m_sentPacketSizes;
77 
81  std::vector<uint32_t> m_rcvdPacketSizes;
82 };
83 
85  : TestCase("Test RLE.")
86 {
87 }
88 
90 {
91 }
92 
93 void
95 {
96  // Set simulation output details
97  Singleton<SatEnvVariables>::Get()->DoInitialize();
98  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-sat-rle", "", true);
99 
100  Mac48Address source = Mac48Address::Allocate();
101  Mac48Address dest = Mac48Address::Allocate();
102 
103  uint8_t rcIndex(0);
104  Ptr<SatQueue> queue = CreateObject<SatQueue>(rcIndex);
105  Ptr<SatReturnLinkEncapsulator> rle =
106  CreateObject<SatReturnLinkEncapsulator>(source, dest, source, dest, rcIndex);
107  rle->SetQueue(queue);
108 
109  // Create a receive callback to Receive method of this class.
110  rle->SetReceiveCallback(MakeCallback(&SatRleTestCase::Receive, this));
111 
112  // Random variable for sent packet sizes and tx opportunities
113  Ptr<UniformRandomVariable> unif = CreateObject<UniformRandomVariable>();
114 
115  // Number of created packets
116  uint32_t numPackets(100);
117 
118  // Create packets and push them to RLE
119  for (uint32_t i = 0; i < numPackets; ++i)
120  {
121  uint32_t packetSize = unif->GetInteger(3, 1500);
122  Ptr<Packet> packet = Create<Packet>(packetSize);
123  m_sentPacketSizes.push_back(packetSize);
124  rle->EnquePdu(packet, dest);
125  }
126 
131  uint32_t nextMinTxO(0);
132  uint32_t bytesLeft(1);
133  while (bytesLeft > 0)
134  {
135  Ptr<Packet> p = rle->NotifyTxOpportunity(unif->GetInteger(3, 1500), bytesLeft, nextMinTxO);
136  rle->ReceivePdu(p);
137  }
138 
142  NS_TEST_ASSERT_MSG_EQ(m_sentPacketSizes.size(),
143  m_rcvdPacketSizes.size(),
144  "All sent packets are not received");
145 
146  Simulator::Destroy();
147 
148  Singleton<SatEnvVariables>::Get()->DoDispose();
149 }
150 
151 void
152 SatRleTestCase::Receive(Ptr<Packet> p, Mac48Address source, Mac48Address dest)
153 {
154  uint32_t rcvdPacketSize = p->GetSize();
155  m_rcvdPacketSizes.push_back(rcvdPacketSize);
156  uint32_t numRcvdPackets = m_rcvdPacketSizes.size();
157 
162  NS_TEST_ASSERT_MSG_EQ(m_sentPacketSizes[numRcvdPackets - 1],
163  m_rcvdPacketSizes[numRcvdPackets - 1],
164  "Wrong size packet received");
165 }
166 
171 class SatRleTraceSuite : public TestSuite
172 {
173  public:
175 };
176 
178  : TestSuite("sat-rle-test", UNIT)
179 {
180  AddTestCase(new SatRleTestCase, TestCase::QUICK);
181 }
182 
183 // Do allocate an instance of this TestSuite
Return Link Encapsulation (RLE) test case implementation.
std::vector< uint32_t > m_sentPacketSizes
Sent packet sizes.
void Receive(Ptr< Packet > p, Mac48Address source, Mac48Address dest)
Receive packet and check that it is of correct size.
virtual ~SatRleTestCase()
std::vector< uint32_t > m_rcvdPacketSizes
Received packet sizes.
virtual void DoRun(void)
Test suite for RLE.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatRleTraceSuite SatRleTestSuite