A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
main-grid-topology.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2006,2007 INRIA
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*/
6
7
#include "ns3/core-module.h"
8
#include "ns3/mobility-module.h"
9
#include "ns3/network-module.h"
10
11
using namespace
ns3
;
12
13
int
14
main(
int
argc,
char
* argv[])
15
{
16
CommandLine
cmd
(__FILE__);
17
cmd
.Parse(argc, argv);
18
19
NodeContainer
nodes
;
20
21
// create an array of empty nodes for testing purposes
22
nodes
.
Create
(120);
23
24
MobilityHelper
mobility
;
25
// setup the grid itself: objects are laid out
26
// started from (-100,-100) with 20 objects per row,
27
// the x interval between each object is 5 meters
28
// and the y interval between each object is 20 meters
29
mobility
.SetPositionAllocator(
"ns3::GridPositionAllocator"
,
30
"MinX"
,
31
DoubleValue
(-100.0),
32
"MinY"
,
33
DoubleValue
(-100.0),
34
"DeltaX"
,
35
DoubleValue
(5.0),
36
"DeltaY"
,
37
DoubleValue
(20.0),
38
"GridWidth"
,
39
UintegerValue
(20),
40
"LayoutType"
,
41
StringValue
(
"RowFirst"
));
42
// each object will be attached a static position.
43
// i.e., once set by the "position allocator", the
44
// position will never change.
45
mobility
.SetMobilityModel(
"ns3::ConstantPositionMobilityModel"
);
46
47
// finalize the setup by attaching to each object
48
// in the input array a position and initializing
49
// this position with the calculated coordinates.
50
mobility
.Install(
nodes
);
51
52
// iterate our nodes and print their position.
53
for
(
auto
j =
nodes
.
Begin
(); j !=
nodes
.
End
(); ++j)
54
{
55
Ptr<Node>
object
= *j;
56
Ptr<MobilityModel>
position =
object
->GetObject<
MobilityModel
>();
57
NS_ASSERT
(position);
58
Vector pos = position->GetPosition();
59
std::cout <<
"x="
<< pos.x <<
", y="
<< pos.y <<
", z="
<< pos.z << std::endl;
60
}
61
62
Simulator::Destroy
();
63
return
0;
64
}
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition
double.h:31
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition
mobility-helper.h:33
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition
mobility-model.h:29
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::NodeContainer::End
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Definition
node-container.cc:55
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:73
ns3::NodeContainer::Begin
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
Definition
node-container.cc:49
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::StringValue
Hold variables of type string.
Definition
string.h:45
ns3::UintegerValue
Hold an unsigned integer type.
Definition
uinteger.h:34
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:55
nodes
NodeContainer nodes
Definition
lr-wpan-bootstrap.cc:43
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition
second.py:29
third.mobility
mobility
Definition
third.py:92
src
mobility
examples
main-grid-topology.cc
Generated on Fri Nov 8 2024 13:59:04 for ns-3 by
1.11.0