Loading...
Searching...
No Matches
satellite-gse-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
26
29
30#include "ns3/callback.h"
31#include "ns3/log.h"
32#include "ns3/packet.h"
33#include "ns3/ptr.h"
34#include "ns3/random-variable-stream.h"
35#include "ns3/singleton.h"
36#include "ns3/test.h"
37
38#include <vector>
39
40using namespace ns3;
41
55class SatGseTestCase : public TestCase
56{
57 public:
59 virtual ~SatGseTestCase();
60
67 void Receive(Ptr<Packet> p, Mac48Address source, Mac48Address dest);
68
69 private:
70 virtual void DoRun(void);
71
75 std::vector<uint32_t> m_sentPacketSizes;
76
80 std::vector<uint32_t> m_rcvdPacketSizes;
81};
82
84 : TestCase("Test GSE.")
85{
86}
87
91
92void
94{
95 // Set simulation output details
96 SatEnvVariables::GetInstance()->DoInitialize();
97 SatEnvVariables::GetInstance()->SetOutputVariables("test-sat-gse", "", true);
98
99 Mac48Address source = Mac48Address::Allocate();
100 Mac48Address dest = Mac48Address::Allocate();
101
102 uint8_t flowId(0);
103 Ptr<SatQueue> queue = CreateObject<SatQueue>(flowId);
104 Ptr<SatGenericStreamEncapsulator> gse =
105 CreateObject<SatGenericStreamEncapsulator>(source, dest, source, dest, flowId);
106 gse->SetQueue(queue);
107
108 // Create a receive callback to Receive method of this class.
109 gse->SetReceiveCallback(MakeCallback(&SatGseTestCase::Receive, this));
110
111 // Random variable for sent packet sizes and tx opportunities
112 Ptr<UniformRandomVariable> unif = CreateObject<UniformRandomVariable>();
113
114 // Number of created packets. Note, that the LLC implements a maximum buffer
115 // size, thus the number of enqued packets cannot be much higher than this.
116 uint32_t numPackets(70);
117
118 // Create packets and push them to GSE
119 for (uint32_t i = 0; i < numPackets; ++i)
120 {
121 uint32_t packetSize = unif->GetInteger(3, 10000);
122 Ptr<Packet> packet = Create<Packet>(packetSize);
123 m_sentPacketSizes.push_back(packetSize);
124 gse->EnquePdu(packet, dest);
125 }
126
131
132 uint32_t bytesLeft(1);
133 uint32_t nextMinTxO(0);
134 uint32_t numFrames(15);
135 uint32_t frameBytes(50000);
136 for (uint32_t b = 0; b < numFrames; ++b)
137 {
138 uint32_t txOpp(frameBytes);
139 while (bytesLeft > 0)
140 {
141 Ptr<Packet> p = gse->NotifyTxOpportunity(txOpp, bytesLeft, nextMinTxO);
142 if (!p)
143 {
144 break;
145 }
146 txOpp -= p->GetSize();
147 gse->ReceivePdu(p);
148 }
149 }
153 NS_TEST_ASSERT_MSG_EQ(m_sentPacketSizes.size(),
154 m_rcvdPacketSizes.size(),
155 "All sent packets are not received");
156
157 Simulator::Destroy();
158
159 SatEnvVariables::GetInstance()->DoDispose();
160}
161
162void
163SatGseTestCase::Receive(Ptr<Packet> p, Mac48Address source, Mac48Address dest)
164{
165 uint32_t rcvdPacketSize = p->GetSize();
166 m_rcvdPacketSizes.push_back(rcvdPacketSize);
167 uint32_t numRcvdPackets = m_rcvdPacketSizes.size();
168
173 NS_TEST_ASSERT_MSG_EQ(m_sentPacketSizes[numRcvdPackets - 1],
174 m_rcvdPacketSizes[numRcvdPackets - 1],
175 "Wrong size packet received");
176}
177
182class SatGseTraceSuite : public TestSuite
183{
184 public:
186};
187
189 : TestSuite("sat-gse-test", Type::UNIT)
190{
191 AddTestCase(new SatGseTestCase, TestCase::Duration::QUICK);
192}
193
194// Do allocate an instance of this TestSuite
Generic Stream Encapsulation (GSE) test case implementation.
std::vector< uint32_t > m_rcvdPacketSizes
Received packet sizes.
std::vector< uint32_t > m_sentPacketSizes
Sent packet sizes.
virtual void DoRun(void)
void Receive(Ptr< Packet > p, Mac48Address source, Mac48Address dest)
Receive packet and check that it is of correct size.
Test suite for GSE.
static Ptr< SatEnvVariables > GetInstance()
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatGseTraceSuite SatGseTestSuite