A Discrete-Event Network Simulator
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
11using namespace ns3;
12
13int
14main(int argc, char* argv[])
15{
16 CommandLine cmd(__FILE__);
17 cmd.Parse(argc, argv);
18
20
21 // create an array of empty nodes for testing purposes
22 nodes.Create(120);
23
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
63 return 0;
64}
Parse command-line arguments.
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.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
Hold variables of type string.
Definition string.h:45
Hold an unsigned integer type.
Definition uinteger.h:34
#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
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mobility
Definition third.py:92