A Discrete-Event Network Simulator
API
 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 
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 
70  return 0;
71 }
double x
x coordinate of vector
Definition: vector.h:49
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
hold variables of type string
Definition: string.h:18
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
Vector GetPosition(void) const
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
a 3d vector
Definition: vector.h:31
tuple nodes
Definition: first.py:25
Keep track of the current position and velocity of an object.
int main(int argc, char *argv[])
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Hold an unsigned integer type.
Definition: uinteger.h:46
Parse command-line arguments.
Definition: command-line.h:177
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
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())
double y
y coordinate of vector
Definition: vector.h:53
Helper class used to assign positions and mobility models to nodes.
void Parse(int argc, char *argv[])
Parse the program arguments.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Hold a floating point type.
Definition: double.h:41
Ptr< T > GetObject(void) const
Definition: object.h:362
double z
z coordinate of vector
Definition: vector.h:57