A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
drop-tail-queue-test-suite.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 University of Washington
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
19
#include "ns3/test.h"
20
#include "ns3/drop-tail-queue.h"
21
#include "ns3/uinteger.h"
22
23
using namespace
ns3;
24
25
class
DropTailQueueTestCase
:
public
TestCase
26
{
27
public
:
28
DropTailQueueTestCase
();
29
virtual
void
DoRun (
void
);
30
};
31
32
DropTailQueueTestCase::DropTailQueueTestCase
()
33
:
TestCase
(
"Sanity check on the drop tail queue implementation"
)
34
{
35
}
36
void
37
DropTailQueueTestCase::DoRun
(
void
)
38
{
39
Ptr<DropTailQueue>
queue = CreateObject<DropTailQueue> ();
40
NS_TEST_EXPECT_MSG_EQ
(queue->
SetAttributeFailSafe
(
"MaxPackets"
,
UintegerValue
(3)),
true
,
41
"Verify that we can actually set the attribute"
);
42
43
Ptr<Packet>
p1, p2, p3, p4;
44
p1 = Create<Packet> ();
45
p2 = Create<Packet> ();
46
p3 = Create<Packet> ();
47
p4 = Create<Packet> ();
48
49
NS_TEST_EXPECT_MSG_EQ
(queue->
GetNPackets
(), 0,
"There should be no packets in there"
);
50
queue->
Enqueue
(p1);
51
NS_TEST_EXPECT_MSG_EQ
(queue->
GetNPackets
(), 1,
"There should be one packet in there"
);
52
queue->
Enqueue
(p2);
53
NS_TEST_EXPECT_MSG_EQ
(queue->
GetNPackets
(), 2,
"There should be two packets in there"
);
54
queue->
Enqueue
(p3);
55
NS_TEST_EXPECT_MSG_EQ
(queue->
GetNPackets
(), 3,
"There should be three packets in there"
);
56
queue->
Enqueue
(p4);
// will be dropped
57
NS_TEST_EXPECT_MSG_EQ
(queue->
GetNPackets
(), 3,
"There should be still three packets in there"
);
58
59
Ptr<Packet>
p;
60
61
p = queue->
Dequeue
();
62
NS_TEST_EXPECT_MSG_EQ
((p != 0),
true
,
"I want to remove the first packet"
);
63
NS_TEST_EXPECT_MSG_EQ
(queue->
GetNPackets
(), 2,
"There should be two packets in there"
);
64
NS_TEST_EXPECT_MSG_EQ
(p->GetUid (), p1->GetUid (),
"was this the first packet ?"
);
65
66
p = queue->
Dequeue
();
67
NS_TEST_EXPECT_MSG_EQ
((p != 0),
true
,
"I want to remove the second packet"
);
68
NS_TEST_EXPECT_MSG_EQ
(queue->
GetNPackets
(), 1,
"There should be one packet in there"
);
69
NS_TEST_EXPECT_MSG_EQ
(p->GetUid (), p2->GetUid (),
"Was this the second packet ?"
);
70
71
p = queue->
Dequeue
();
72
NS_TEST_EXPECT_MSG_EQ
((p != 0),
true
,
"I want to remove the third packet"
);
73
NS_TEST_EXPECT_MSG_EQ
(queue->
GetNPackets
(), 0,
"There should be no packets in there"
);
74
NS_TEST_EXPECT_MSG_EQ
(p->GetUid (), p3->GetUid (),
"Was this the third packet ?"
);
75
76
p = queue->
Dequeue
();
77
NS_TEST_EXPECT_MSG_EQ
((p == 0),
true
,
"There are really no packets in there"
);
78
}
79
80
static
class
DropTailQueueTestSuite
:
public
TestSuite
81
{
82
public
:
83
DropTailQueueTestSuite
()
84
:
TestSuite
(
"drop-tail-queue"
,
UNIT
)
85
{
86
AddTestCase
(
new
DropTailQueueTestCase
(), TestCase::QUICK);
87
}
88
}
g_dropTailQueueTestSuite
;
DropTailQueueTestSuite
Definition:
drop-tail-queue-test-suite.cc:80
ns3::Ptr
smart pointer class similar to boost::intrusive_ptr
Definition:
ptr.h:59
ns3::Queue::Enqueue
bool Enqueue(Ptr< Packet > p)
Place a packet into the rear of the Queue.
Definition:
queue.cc:63
g_dropTailQueueTestSuite
DropTailQueueTestSuite g_dropTailQueueTestSuite
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
ns3::ObjectBase::SetAttributeFailSafe
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Definition:
object-base.cc:181
ns3::TestCase
encapsulates test code
Definition:
test.h:849
DropTailQueueTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
drop-tail-queue-test-suite.cc:37
DropTailQueueTestCase::DropTailQueueTestCase
DropTailQueueTestCase()
Definition:
drop-tail-queue-test-suite.cc:32
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:46
NS_TEST_EXPECT_MSG_EQ
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition:
test.h:244
ns3::Queue::Dequeue
Ptr< Packet > Dequeue(void)
Remove a packet from the front of the Queue.
Definition:
queue.cc:87
ns3::Queue::GetNPackets
uint32_t GetNPackets(void) const
Definition:
queue.cc:126
DropTailQueueTestCase
Definition:
drop-tail-queue-test-suite.cc:25
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:173
ns3::TestSuite::UNIT
This test suite implements a Unit Test.
Definition:
test.h:1035
DropTailQueueTestSuite::DropTailQueueTestSuite
DropTailQueueTestSuite()
Definition:
drop-tail-queue-test-suite.cc:83
src
network
test
drop-tail-queue-test-suite.cc
Generated on Sat Apr 19 2014 14:07:05 for ns-3 by
1.8.6