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
}
src
mobility
examples
main-grid-topology.cc
Generated on Fri Dec 21 2012 19:00:42 for ns-3 by
1.8.1.2