Files
unison/samples/main-grid-topology.cc

55 lines
1.8 KiB
C++
Raw Normal View History

2007-07-23 15:53:54 +02:00
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2008-03-24 13:57:26 -07:00
#include "ns3/core-module.h"
#include "ns3/helper-module.h"
#include "ns3/mobility-module.h"
2007-07-23 15:53:54 +02:00
using namespace ns3;
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
2007-07-23 15:53:54 +02:00
NodeContainer nodes;
2007-07-23 15:53:54 +02:00
// create an array of empty nodes for testing purposes
nodes.Create (120);
2007-07-23 15:53:54 +02:00
MobilityHelper mobility;
2007-07-23 15:53:54 +02:00
// setup the grid itself: objects are layed out
// started from (-100,-100) with 20 objects per row,
// the x interval between each object is 5 meters
// and the y interval between each object is 20 meters
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (-100.0),
"MinY", DoubleValue (-100.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (20.0),
"GridWidth", UintegerValue (20),
"LayoutType", StringValue ("RowFirst"));
2007-07-23 15:53:54 +02:00
// each object will be attached a static position.
// i.e., once set by the "position allocator", the
// position will never change.
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
2007-07-23 15:53:54 +02:00
// finalize the setup by attaching to each object
// in the input array a position and initializing
// this position with the calculated coordinates.
2008-04-13 15:46:17 -07:00
mobility.Install (nodes);
2007-07-23 15:53:54 +02:00
// iterate our nodes and print their position.
for (NodeContainer::Iterator j = nodes.Begin ();
j != nodes.End (); ++j)
2007-07-23 15:53:54 +02:00
{
Ptr<Node> object = *j;
2008-01-31 22:11:03 +01:00
Ptr<MobilityModel> position = object->GetObject<MobilityModel> ();
2007-07-23 15:53:54 +02:00
NS_ASSERT (position != 0);
2007-11-08 12:33:30 +01:00
Vector pos = position->GetPosition ();
2007-07-23 15:53:54 +02:00
std::cout << "x=" << pos.x << ", y=" << pos.y << ", z=" << pos.z << std::endl;
}
return 0;
}