A Discrete-Event Network Simulator
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 
32 
33  // create an array of empty nodes for testing purposes
34  nodes.Create (120);
35 
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 
70  return 0;
71 }
Parse command-line arguments.
Definition: command-line.h:229
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
Vector GetPosition(void) const
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
Hold variables of type string.
Definition: string.h:41
Hold an unsigned integer type.
Definition: uinteger.h:44
#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
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:35
mobility
Definition: third.py:108