A Discrete-Event Network Simulator
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 
46 {
47 public:
49  virtual ~MobilityTraceTestCase ();
50 
51 private:
52  virtual void DoRun (void);
53 };
54 
56  :
57  TestCase ("Mobility Trace Test Case")
58 {
59 }
60 
62 {
63 }
64 
65 void
67 {
68  //***************************************************************************
69  // Create the new mobility trace.
70  //***************************************************************************
71 
72  NodeContainer sta;
73  sta.Create (4);
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 
118 {
119 public:
121 };
122 
124  : TestSuite ("mobility-trace", UNIT)
125 {
126  AddTestCase (new MobilityTraceTestCase, TestCase::QUICK);
127 }
128 
Manage ASCII trace files for device models.
Definition: trace-helper.h:161
Mobility Trace Test Suite.
Hold variables of type string.
Definition: string.h:41
A suite of tests to run.
Definition: test.h:1342
Mobility Trace Test Case.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we&#39;ll use to write the traced bits. ...
encapsulates test code
Definition: test.h:1155
mobility
Definition: third.py:108
AttributeValue implementation for Rectangle.
Definition: rectangle.h:97
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Hold an unsigned integer type.
Definition: uinteger.h:44
#define NS_ASCII_TEST_EXPECT_EQ(gotFilename, expectedFilename)
Test that a pair of new/reference ascii files are equal.
Definition: ascii-test.h:38
static MobilityTraceTestSuite mobilityTraceTestSuite
the test suite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Definition: test.cc:412
virtual void DoRun(void)
Implementation to actually run this TestCase.
Helper class used to assign positions and mobility models to nodes.
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:430
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition: test.cc:465
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
a 2d rectangle
Definition: rectangle.h:34