A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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;
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 layed 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::Vector3D::x
double x
Definition:
vector.h:49
ns3::Ptr< Node >
ns3::NodeContainer::Iterator
std::vector< Ptr< Node > >::const_iterator Iterator
Definition:
node-container.h:41
ns3::StringValue
hold variables of type string
Definition:
string.h:19
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::MobilityModel::GetPosition
Vector GetPosition(void) const
Definition:
mobility-model.cc:62
ns3::NodeContainer::End
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Definition:
node-container.cc:77
ns3::Vector3D
a 3d vector
Definition:
vector.h:31
first.nodes
tuple nodes
Definition:
first.py:25
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition:
mobility-model.h:39
main
int main(int argc, char *argv[])
Definition:
main-grid-topology.cc:26
ns3::MobilityHelper::Install
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Definition:
mobility-helper.cc:130
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:46
ns3::CommandLine
Parse command-line arguments.
Definition:
command-line.h:152
ns3::Simulator::Destroy
static void Destroy(void)
Definition:
simulator.cc:121
ns3::NodeContainer
keep track of a set of node pointers.
Definition:
node-container.h:38
ns3::NodeContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Definition:
node-container.cc:72
ns3::MobilityHelper::SetMobilityModel
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())
Definition:
mobility-helper.cc:79
ns3::Vector3D::y
double y
Definition:
vector.h:53
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition:
mobility-helper.h:42
ns3::CommandLine::Parse
void Parse(int argc, char *argv[])
Definition:
command-line.cc:104
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition:
node-container.cc:93
ns3::MobilityHelper::SetPositionAllocator
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Definition:
mobility-helper.cc:47
ns3::DoubleValue
Hold an floating point type.
Definition:
double.h:41
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Definition:
object.h:360
ns3::Vector3D::z
double z
Definition:
vector.h:57
src
mobility
examples
main-grid-topology.cc
Generated on Sun Apr 20 2014 11:14:58 for ns-3 by
1.8.6