A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
main-grid-topology.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2006,2007 INRIA
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
19
#include "ns3/core-module.h"
20
#include "ns3/network-module.h"
21
#include "ns3/mobility-module.h"
22
23
24
using namespace
ns3
;
25
26
int
main (
int
argc,
char
*argv[])
27
{
28
CommandLine
cmd
(__FILE__);
29
cmd
.Parse (argc, argv);
30
31
NodeContainer
nodes
;
32
33
// create an array of empty nodes for testing purposes
34
nodes
.Create (120);
35
36
MobilityHelper
mobility
;
37
// setup the grid itself: objects are laid out
38
// started from (-100,-100) with 20 objects per row,
39
// the x interval between each object is 5 meters
40
// and the y interval between each object is 20 meters
41
mobility
.SetPositionAllocator (
"ns3::GridPositionAllocator"
,
42
"MinX"
,
DoubleValue
(-100.0),
43
"MinY"
,
DoubleValue
(-100.0),
44
"DeltaX"
,
DoubleValue
(5.0),
45
"DeltaY"
,
DoubleValue
(20.0),
46
"GridWidth"
,
UintegerValue
(20),
47
"LayoutType"
,
StringValue
(
"RowFirst"
));
48
// each object will be attached a static position.
49
// i.e., once set by the "position allocator", the
50
// position will never change.
51
mobility
.SetMobilityModel (
"ns3::ConstantPositionMobilityModel"
);
52
53
// finalize the setup by attaching to each object
54
// in the input array a position and initializing
55
// this position with the calculated coordinates.
56
mobility
.Install (
nodes
);
57
58
// iterate our nodes and print their position.
59
for
(
NodeContainer::Iterator
j =
nodes
.Begin ();
60
j !=
nodes
.End (); ++j)
61
{
62
Ptr<Node>
object
= *j;
63
Ptr<MobilityModel>
position =
object
->
GetObject
<
MobilityModel
> ();
64
NS_ASSERT
(position != 0);
65
Vector pos = position->
GetPosition
();
66
std::cout <<
"x="
<< pos.x <<
", y="
<< pos.y <<
", z="
<< pos.z << std::endl;
67
}
68
69
Simulator::Destroy
();
70
return
0;
71
}
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:229
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition:
double.h:41
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition:
mobility-helper.h:43
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition:
mobility-model.h:40
ns3::MobilityModel::GetPosition
Vector GetPosition(void) const
Definition:
mobility-model.cc:64
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:39
ns3::NodeContainer::Iterator
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Definition:
node-container.h:42
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition:
object.h:470
ns3::Ptr< Node >
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:136
ns3::StringValue
Hold variables of type string.
Definition:
string.h:41
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:44
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition:
assert.h:67
first.nodes
nodes
Definition:
first.py:32
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition:
second.py:35
third.mobility
mobility
Definition:
third.py:108
src
mobility
examples
main-grid-topology.cc
Generated on Tue Feb 6 2024 19:21:24 for ns-3 by
1.9.1