A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
mobility-trace-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) 2012 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
* Author: Mitch Watrous (watrous@u.washington.edu)
19
*/
20
21
#include <string>
22
23
#include "ns3/ascii-test.h"
24
#include "ns3/trace-helper.h"
25
#include "ns3/double.h"
26
#include "ns3/uinteger.h"
27
#include "ns3/string.h"
28
#include "ns3/simulator.h"
29
#include "ns3/rectangle.h"
30
#include "ns3/mobility-model.h"
31
#include "ns3/mobility-helper.h"
32
#include "ns3/node-container.h"
33
#include "ns3/test.h"
34
35
using namespace
ns3
;
36
37
45
class
MobilityTraceTestCase
:
public
TestCase
46
{
47
public
:
48
MobilityTraceTestCase
();
49
virtual
~
MobilityTraceTestCase
();
50
51
private
:
52
virtual
void
DoRun (
void
);
53
};
54
55
MobilityTraceTestCase::MobilityTraceTestCase
()
56
:
57
TestCase
(
"Mobility Trace Test Case"
)
58
{
59
}
60
61
MobilityTraceTestCase::~MobilityTraceTestCase
()
62
{
63
}
64
65
void
66
MobilityTraceTestCase::DoRun
(
void
)
67
{
68
//***************************************************************************
69
// Create the new mobility trace.
70
//***************************************************************************
71
72
NodeContainer
sta;
73
sta.
Create
(4);
74
MobilityHelper
mobility
;
75
mobility
.SetPositionAllocator (
"ns3::GridPositionAllocator"
,
76
"MinX"
,
DoubleValue
(1.0),
77
"MinY"
,
DoubleValue
(1.0),
78
"DeltaX"
,
DoubleValue
(5.0),
79
"DeltaY"
,
DoubleValue
(5.0),
80
"GridWidth"
,
UintegerValue
(3),
81
"LayoutType"
,
StringValue
(
"RowFirst"
));
82
mobility
.SetMobilityModel (
"ns3::RandomWalk2dMobilityModel"
,
83
"Mode"
,
StringValue
(
"Time"
),
84
"Time"
,
StringValue
(
"2s"
),
85
"Speed"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1.0]"
),
86
"Bounds"
,
RectangleValue
(
Rectangle
(0.0, 20.0, 0.0, 20.0)));
87
mobility
.Install (sta);
88
// Set mobility random number streams to fixed values
89
mobility
.AssignStreams (sta, 0);
90
91
SetDataDir
(NS_TEST_SOURCEDIR);
92
std::string referenceMobilityFilePath =
CreateDataDirFilename
(
"mobility-trace-example.mob"
);
93
std::string testMobilityFilePath =
CreateTempDirFilename
(
"mobility-trace-test.mob"
);
94
95
AsciiTraceHelper
ascii;
96
MobilityHelper::EnableAsciiAll (ascii.
CreateFileStream
(testMobilityFilePath));
97
Simulator::Stop (
Seconds
(5.0));
98
Simulator::Run ();
99
Simulator::Destroy ();
100
101
102
//***************************************************************************
103
// Test the new mobility trace against the reference mobility trace.
104
//***************************************************************************
105
106
NS_ASCII_TEST_EXPECT_EQ
(testMobilityFilePath, referenceMobilityFilePath);
107
}
108
109
117
class
MobilityTraceTestSuite
:
public
TestSuite
118
{
119
public
:
120
MobilityTraceTestSuite
();
121
};
122
123
MobilityTraceTestSuite::MobilityTraceTestSuite
()
124
:
TestSuite
(
"mobility-trace"
, UNIT)
125
{
126
AddTestCase
(
new
MobilityTraceTestCase
, TestCase::QUICK);
127
}
128
129
static
MobilityTraceTestSuite
mobilityTraceTestSuite
;
ns3::TestCase::SetDataDir
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition:
test.cc:465
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
MobilityTraceTestCase
Mobility Trace Test Case.
Definition:
mobility-trace-test-suite.cc:46
NS_ASCII_TEST_EXPECT_EQ
#define NS_ASCII_TEST_EXPECT_EQ(gotFilename, expectedFilename)
Test that a pair of new/reference ascii files are equal.
Definition:
ascii-test.h:38
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::RectangleValue
AttributeValue implementation for Rectangle.
Definition:
rectangle.h:97
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition:
double.h:41
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition:
node-container.cc:98
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
MobilityTraceTestCase::~MobilityTraceTestCase
virtual ~MobilityTraceTestCase()
Definition:
mobility-trace-test-suite.cc:61
ns3::AsciiTraceHelper::CreateFileStream
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Definition:
trace-helper.cc:191
ns3::Rectangle
a 2d rectangle
Definition:
rectangle.h:35
MobilityTraceTestSuite
Mobility Trace Test Suite.
Definition:
mobility-trace-test-suite.cc:118
ns3::StringValue
Hold variables of type string.
Definition:
string.h:41
ns3::AsciiTraceHelper
Manage ASCII trace files for device models.
Definition:
trace-helper.h:163
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
MobilityTraceTestCase::MobilityTraceTestCase
MobilityTraceTestCase()
Definition:
mobility-trace-test-suite.cc:55
ns3::TestCase::CreateDataDirFilename
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Definition:
test.cc:412
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1289
mobilityTraceTestSuite
static MobilityTraceTestSuite mobilityTraceTestSuite
the test suite
Definition:
mobility-trace-test-suite.cc:129
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:39
MobilityTraceTestSuite::MobilityTraceTestSuite
MobilityTraceTestSuite()
Definition:
mobility-trace-test-suite.cc:123
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:44
MobilityTraceTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
mobility-trace-test-suite.cc:66
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition:
mobility-helper.h:43
third.mobility
mobility
Definition:
third.py:108
ns3::TestCase::CreateTempDirFilename
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition:
test.cc:430
src
mobility
test
mobility-trace-test-suite.cc
Generated on Fri Oct 1 2021 17:03:27 for ns-3 by
1.8.20