A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
mobility-trace-test-suite.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Mitch Watrous (watrous@u.washington.edu)
7
*/
8
9
#include "ns3/ascii-test.h"
10
#include "ns3/double.h"
11
#include "ns3/mobility-helper.h"
12
#include "ns3/mobility-model.h"
13
#include "ns3/node-container.h"
14
#include "ns3/rectangle.h"
15
#include "ns3/simulator.h"
16
#include "ns3/string.h"
17
#include "ns3/test.h"
18
#include "ns3/trace-helper.h"
19
#include "ns3/uinteger.h"
20
21
#include <string>
22
23
using namespace
ns3
;
24
25
/**
26
* \ingroup mobility-test
27
*
28
* \brief Mobility Trace Test Case
29
*/
30
31
class
MobilityTraceTestCase
:
public
TestCase
32
{
33
public
:
34
MobilityTraceTestCase
();
35
~MobilityTraceTestCase
()
override
;
36
37
private
:
38
void
DoRun
()
override
;
39
};
40
41
MobilityTraceTestCase::MobilityTraceTestCase
()
42
:
TestCase
(
"Mobility Trace Test Case"
)
43
{
44
}
45
46
MobilityTraceTestCase::~MobilityTraceTestCase
()
47
{
48
}
49
50
void
51
MobilityTraceTestCase::DoRun
()
52
{
53
//***************************************************************************
54
// Create the new mobility trace.
55
//***************************************************************************
56
57
NodeContainer
sta;
58
sta.
Create
(4);
59
MobilityHelper
mobility;
60
mobility.SetPositionAllocator(
"ns3::GridPositionAllocator"
,
61
"MinX"
,
62
DoubleValue
(1.0),
63
"MinY"
,
64
DoubleValue
(1.0),
65
"DeltaX"
,
66
DoubleValue
(5.0),
67
"DeltaY"
,
68
DoubleValue
(5.0),
69
"GridWidth"
,
70
UintegerValue
(3),
71
"LayoutType"
,
72
StringValue
(
"RowFirst"
));
73
mobility.SetMobilityModel(
"ns3::RandomWalk2dMobilityModel"
,
74
"Mode"
,
75
StringValue
(
"Time"
),
76
"Time"
,
77
StringValue
(
"2s"
),
78
"Speed"
,
79
StringValue
(
"ns3::ConstantRandomVariable[Constant=1.0]"
),
80
"Bounds"
,
81
RectangleValue
(
Rectangle
(0.0, 20.0, 0.0, 20.0)));
82
mobility.Install(sta);
83
// Set mobility random number streams to fixed values
84
mobility.AssignStreams(sta, 0);
85
86
SetDataDir
(NS_TEST_SOURCEDIR);
87
std::string referenceMobilityFilePath =
CreateDataDirFilename
(
"mobility-trace-example.mob"
);
88
std::string testMobilityFilePath =
CreateTempDirFilename
(
"mobility-trace-test.mob"
);
89
90
AsciiTraceHelper
ascii;
91
MobilityHelper::EnableAsciiAll
(ascii.
CreateFileStream
(testMobilityFilePath));
92
Simulator::Stop
(
Seconds
(5.0));
93
Simulator::Run
();
94
Simulator::Destroy
();
95
96
//***************************************************************************
97
// Test the new mobility trace against the reference mobility trace.
98
//***************************************************************************
99
100
NS_ASCII_TEST_EXPECT_EQ
(testMobilityFilePath, referenceMobilityFilePath);
101
}
102
103
/**
104
* \ingroup mobility-test
105
*
106
* \brief Mobility Trace Test Suite
107
*/
108
109
class
MobilityTraceTestSuite
:
public
TestSuite
110
{
111
public
:
112
MobilityTraceTestSuite
();
113
};
114
115
MobilityTraceTestSuite::MobilityTraceTestSuite
()
116
:
TestSuite
(
"mobility-trace"
,
Type
::UNIT)
117
{
118
AddTestCase
(
new
MobilityTraceTestCase
, TestCase::Duration::QUICK);
119
}
120
121
/**
122
* \ingroup mobility-test
123
* Static variable for test initialization
124
*/
125
static
MobilityTraceTestSuite
mobilityTraceTestSuite
;
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:27
MobilityTraceTestCase
Mobility Trace Test Case.
Definition
mobility-trace-test-suite.cc:32
MobilityTraceTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
mobility-trace-test-suite.cc:51
MobilityTraceTestCase::~MobilityTraceTestCase
~MobilityTraceTestCase() override
Definition
mobility-trace-test-suite.cc:46
MobilityTraceTestCase::MobilityTraceTestCase
MobilityTraceTestCase()
Definition
mobility-trace-test-suite.cc:41
MobilityTraceTestSuite
Mobility Trace Test Suite.
Definition
mobility-trace-test-suite.cc:110
MobilityTraceTestSuite::MobilityTraceTestSuite
MobilityTraceTestSuite()
Definition
mobility-trace-test-suite.cc:115
ns3::AsciiTraceHelper
Manage ASCII trace files for device models.
Definition
trace-helper.h:163
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:182
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition
double.h:31
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition
mobility-helper.h:33
ns3::MobilityHelper::EnableAsciiAll
static void EnableAsciiAll(Ptr< OutputStreamWrapper > stream)
Definition
mobility-helper.cc:200
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
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:73
ns3::Rectangle
a 2d rectangle
Definition
rectangle.h:24
ns3::RectangleValue
Definition
rectangle.h:114
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition
simulator.cc:175
ns3::StringValue
Hold variables of type string.
Definition
string.h:45
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::CreateDataDirFilename
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Definition
test.cc:413
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestCase::CreateTempDirFilename
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition
test.cc:432
ns3::TestCase::SetDataDir
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition
test.cc:472
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::UintegerValue
Hold an unsigned integer type.
Definition
uinteger.h:34
mobilityTraceTestSuite
static MobilityTraceTestSuite mobilityTraceTestSuite
Static variable for test initialization.
Definition
mobility-trace-test-suite.cc:125
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1308
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
mobility
test
mobility-trace-test-suite.cc
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0