A Discrete-Event Network Simulator
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
23using namespace ns3;
24
25/**
26 * \ingroup mobility-test
27 *
28 * \brief Mobility Trace Test Case
29 */
30
32{
33 public:
35 ~MobilityTraceTestCase() override;
36
37 private:
38 void DoRun() override;
39};
40
42 : TestCase("Mobility Trace Test Case")
43{
44}
45
49
50void
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",
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));
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
110{
111 public:
113};
114
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 */
#define NS_ASCII_TEST_EXPECT_EQ(gotFilename, expectedFilename)
Test that a pair of new/reference ascii files are equal.
Definition ascii-test.h:27
Mobility Trace Test Case.
void DoRun() override
Implementation to actually run this TestCase.
Mobility Trace Test Suite.
Manage ASCII trace files for device models.
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:31
Helper class used to assign positions and mobility models to nodes.
static void EnableAsciiAll(Ptr< OutputStreamWrapper > stream)
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:24
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
encapsulates test code
Definition test.h:1050
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Definition test.cc:413
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition test.cc:432
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition test.cc:472
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Hold an unsigned integer type.
Definition uinteger.h:34
static MobilityTraceTestSuite mobilityTraceTestSuite
Static variable for test initialization.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.