samples/main-random-walk.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 17 Apr 2008 13:42:25 -0700
changeset 2965 4b28e9740e3b
parent 2753 1f03a5531746
child 2997 caf9d364c6fc
permissions -rw-r--r--
get rid of Attribute class. Use AttributeValue subclasses directly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1554
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
2726
8ed5f77da0da use auto-generated per-module headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2700
diff changeset
     3
#include "ns3/core-module.h"
8ed5f77da0da use auto-generated per-module headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2700
diff changeset
     4
#include "ns3/helper-module.h"
8ed5f77da0da use auto-generated per-module headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2700
diff changeset
     5
#include "ns3/mobility-module.h"
2753
1f03a5531746 fallout from gustavo's header inclusion policy change.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2726
diff changeset
     6
#include "ns3/simulator-module.h"
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     7
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     8
using namespace ns3;
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     9
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    10
static void 
1650
bcfb726651bb On course-change, print velocity in addition to position.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1649
diff changeset
    11
CourseChange (ns3::TraceContext const&, Ptr<const MobilityModel> mobility)
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    12
{
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
    13
  Vector pos = mobility->GetPosition ();
1818
fbdc8361dc77 GetSpeed -> GetVelocity
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1817
diff changeset
    14
  Vector vel = mobility->GetVelocity ();
1650
bcfb726651bb On course-change, print velocity in addition to position.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1649
diff changeset
    15
  std::cout << Simulator::Now () << ", model=" << mobility << ", POS: x=" << pos.x << ", y=" << pos.y
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
    16
            << ", z=" << pos.z << "; VEL:" << vel.x << ", y=" << vel.y
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
    17
            << ", z=" << vel.z << std::endl;
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    18
}
1554
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
int main (int argc, char *argv[])
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
{
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    22
  Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Mode", StringValue ("Time"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    23
  Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Time", StringValue ("2s"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    24
  Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Speed", StringValue ("Constant:1.0"));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    25
  Config::SetDefault ("ns3::RandomWalk2dMobilityModel::Bounds", StringValue ("0:200:0:100"));
1554
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2540
diff changeset
    27
  CommandLine cmd;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2540
diff changeset
    28
  cmd.Parse (argc, argv);
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    29
2700
c54fbae72e8f change signature of MobilityHelper::Layout and MobilityHelper::LayoutAll.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2614
diff changeset
    30
  NodeContainer c;
c54fbae72e8f change signature of MobilityHelper::Layout and MobilityHelper::LayoutAll.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2614
diff changeset
    31
  c.Create (100);
1612
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    32
2399
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    33
  MobilityHelper mobility;
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    34
  mobility.EnableNotifier ();
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2594
diff changeset
    35
  mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    36
                                 "X", StringValue ("100.0"),
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    37
                                 "Y", StringValue ("100.0"),
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    38
                                 "Rho", StringValue ("Uniform:0:30"));
2602
d9262bff6df2 add back support for introspected doxygen.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2594
diff changeset
    39
  mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    40
                             "Mode", StringValue ("Time"),
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    41
                             "Time", StringValue ("2s"),
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    42
                             "Speed", StringValue ("Constant:1.0"),
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    43
                             "Bounds", StringValue ("0:200:0:100"));
2700
c54fbae72e8f change signature of MobilityHelper::Layout and MobilityHelper::LayoutAll.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2614
diff changeset
    44
  mobility.LayoutAll ();
2614
5efb372326be more ns3:: prefix fixes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2602
diff changeset
    45
  Config::Connect ("/NodeList/*/$ns3::MobilityModelNotifier/CourseChange",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2753
diff changeset
    46
                   MakeCallback (&CourseChange));
1612
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    47
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    48
  Simulator::StopAt (Seconds (100.0));
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    49
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    50
  Simulator::Run ();
1554
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
  
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
  return 0;
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
}