A Discrete-Event Network Simulator
API
mobility-trace-test-suite.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mitch Watrous (watrous@u.washington.edu)
18  */
19 
20 #include "ns3/ascii-test.h"
21 #include "ns3/double.h"
22 #include "ns3/mobility-helper.h"
23 #include "ns3/mobility-model.h"
24 #include "ns3/node-container.h"
25 #include "ns3/rectangle.h"
26 #include "ns3/simulator.h"
27 #include "ns3/string.h"
28 #include "ns3/test.h"
29 #include "ns3/trace-helper.h"
30 #include "ns3/uinteger.h"
31 
32 #include <string>
33 
34 using namespace ns3;
35 
43 {
44  public:
46  ~MobilityTraceTestCase() override;
47 
48  private:
49  void DoRun() override;
50 };
51 
53  : TestCase("Mobility Trace Test Case")
54 {
55 }
56 
58 {
59 }
60 
61 void
63 {
64  //***************************************************************************
65  // Create the new mobility trace.
66  //***************************************************************************
67 
68  NodeContainer sta;
69  sta.Create(4);
71  mobility.SetPositionAllocator("ns3::GridPositionAllocator",
72  "MinX",
73  DoubleValue(1.0),
74  "MinY",
75  DoubleValue(1.0),
76  "DeltaX",
77  DoubleValue(5.0),
78  "DeltaY",
79  DoubleValue(5.0),
80  "GridWidth",
81  UintegerValue(3),
82  "LayoutType",
83  StringValue("RowFirst"));
84  mobility.SetMobilityModel("ns3::RandomWalk2dMobilityModel",
85  "Mode",
86  StringValue("Time"),
87  "Time",
88  StringValue("2s"),
89  "Speed",
90  StringValue("ns3::ConstantRandomVariable[Constant=1.0]"),
91  "Bounds",
92  RectangleValue(Rectangle(0.0, 20.0, 0.0, 20.0)));
93  mobility.Install(sta);
94  // Set mobility random number streams to fixed values
95  mobility.AssignStreams(sta, 0);
96 
97  SetDataDir(NS_TEST_SOURCEDIR);
98  std::string referenceMobilityFilePath = CreateDataDirFilename("mobility-trace-example.mob");
99  std::string testMobilityFilePath = CreateTempDirFilename("mobility-trace-test.mob");
100 
101  AsciiTraceHelper ascii;
102  MobilityHelper::EnableAsciiAll(ascii.CreateFileStream(testMobilityFilePath));
103  Simulator::Stop(Seconds(5.0));
104  Simulator::Run();
105  Simulator::Destroy();
106 
107  //***************************************************************************
108  // Test the new mobility trace against the reference mobility trace.
109  //***************************************************************************
110 
111  NS_ASCII_TEST_EXPECT_EQ(testMobilityFilePath, referenceMobilityFilePath);
112 }
113 
121 {
122  public:
124 };
125 
127  : TestSuite("mobility-trace", UNIT)
128 {
129  AddTestCase(new MobilityTraceTestCase, TestCase::QUICK);
130 }
131 
#define NS_ASCII_TEST_EXPECT_EQ(gotFilename, expectedFilename)
Test that a pair of new/reference ascii files are equal.
Definition: ascii-test.h:38
Mobility Trace Test Case.
void DoRun() override
Implementation to actually run this TestCase.
Mobility Trace Test Suite.
Manage ASCII trace files for device models.
Definition: trace-helper.h:174
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.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Helper class used to assign positions and mobility models to nodes.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
a 2d rectangle
Definition: rectangle.h:35
Hold variables of type string.
Definition: string.h:56
encapsulates test code
Definition: test.h:1060
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Definition: test.cc:419
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:438
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition: test.cc:478
A suite of tests to run.
Definition: test.h:1256
Hold an unsigned integer type.
Definition: uinteger.h:45
static MobilityTraceTestSuite mobilityTraceTestSuite
Static variable for test initialization.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mobility
Definition: third.py:105