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 
38 //===========================================================================
39 // Class: MobilityTraceTestCase
40 //
41 //
42 // Test case.
43 //===========================================================================
44 
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 
110 //===========================================================================
111 // Class: MobilityTraceTestSuite
112 //
113 //
114 // Test suite.
115 //===========================================================================
116 
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
Hold variables of type string.
Definition: string.h:41
A suite of tests to run.
Definition: test.h:1333
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. ...
int64_t AssignStreams(NodeContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used by the mobility models (inc...
encapsulates test code
Definition: test.h:1147
AttributeValue implementation for Rectangle.
Definition: rectangle.h:97
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
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
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:411
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
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:429
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition: test.cc:464
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
a 2d rectangle
Definition: rectangle.h:34