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 #include "ns3/core-module.h"
4 #include "ns3/network-module.h"
5 #include "ns3/mobility-module.h"
6 
7 
8 using namespace ns3;
9 
10 int main (int argc, char *argv[])
11 {
12  CommandLine cmd;
13  cmd.Parse (argc, argv);
14 
15  NodeContainer nodes;
16 
17  // create an array of empty nodes for testing purposes
18  nodes.Create (120);
19 
20  MobilityHelper mobility;
21  // setup the grid itself: objects are layed out
22  // started from (-100,-100) with 20 objects per row,
23  // the x interval between each object is 5 meters
24  // and the y interval between each object is 20 meters
25  mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
26  "MinX", DoubleValue (-100.0),
27  "MinY", DoubleValue (-100.0),
28  "DeltaX", DoubleValue (5.0),
29  "DeltaY", DoubleValue (20.0),
30  "GridWidth", UintegerValue (20),
31  "LayoutType", StringValue ("RowFirst"));
32  // each object will be attached a static position.
33  // i.e., once set by the "position allocator", the
34  // position will never change.
35  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
36 
37  // finalize the setup by attaching to each object
38  // in the input array a position and initializing
39  // this position with the calculated coordinates.
40  mobility.Install (nodes);
41 
42  // iterate our nodes and print their position.
43  for (NodeContainer::Iterator j = nodes.Begin ();
44  j != nodes.End (); ++j)
45  {
46  Ptr<Node> object = *j;
47  Ptr<MobilityModel> position = object->GetObject<MobilityModel> ();
48  NS_ASSERT (position != 0);
49  Vector pos = position->GetPosition ();
50  std::cout << "x=" << pos.x << ", y=" << pos.y << ", z=" << pos.z << std::endl;
51  }
52 
54  return 0;
55 }