samples/main-random-walk.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 27 Feb 2008 21:41:34 +0100
changeset 2502 50d0da37f02f
parent 2402 0950067d70a2
child 2540 4e9ba43f7b9e
permissions -rw-r--r--
introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
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
1612
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
     3
#include <vector>
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
     4
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     5
#include "ns3/ptr.h"
1580
0d2cf8839aee position.h -> mobility-model.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1579
diff changeset
     6
#include "ns3/mobility-model.h"
2399
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
     7
#include "ns3/position-allocator.h"
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     8
#include "ns3/default-value.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     9
#include "ns3/command-line.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    10
#include "ns3/simulator.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    11
#include "ns3/nstime.h"
1649
fe121fa40765 Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1645
diff changeset
    12
#include "ns3/node.h"
fe121fa40765 Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1645
diff changeset
    13
#include "ns3/node-list.h"
2399
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    14
#include "ns3/mobility-helper.h"
2502
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    15
#include "ns3/string.h"
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    16
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    17
using namespace ns3;
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    18
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    19
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
    20
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
    21
{
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
    22
  Vector pos = mobility->GetPosition ();
1818
fbdc8361dc77 GetSpeed -> GetVelocity
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1817
diff changeset
    23
  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
    24
  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
    25
            << ", 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
    26
            << ", z=" << vel.z << std::endl;
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    27
}
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
    28
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
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
    30
{
1645
7411d6e0f82a Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1612
diff changeset
    31
  DefaultValue::Bind ("RandomWalk2dMode", "Time");
7411d6e0f82a Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1612
diff changeset
    32
  DefaultValue::Bind ("RandomWalk2dTime", "2s");
7411d6e0f82a Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1612
diff changeset
    33
  DefaultValue::Bind ("RandomWalk2dSpeed", "Constant:1.0");
7411d6e0f82a Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1612
diff changeset
    34
  DefaultValue::Bind ("RandomWalk2dBounds", "0:200:0:100");
1612
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    35
1645
7411d6e0f82a Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1612
diff changeset
    36
  DefaultValue::Bind ("RandomTopologyMobilityType", "RandomWalk2dMobilityModel");
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
    37
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    38
  CommandLine::Parse (argc, argv);
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    39
1612
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    40
  for (uint32_t i = 0; i < 100; i++)
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    41
    {
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1818
diff changeset
    42
      Ptr<Node> node = CreateObject<Node> ();
1612
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    43
    }
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    44
2399
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    45
  MobilityHelper mobility;
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    46
  mobility.EnableNotifier ();
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    47
  mobility.SetPositionAllocator ("RandomDiscPositionAllocator",
2502
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    48
                                 "X", String ("100.0"),
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    49
                                 "Y", String ("100.0"),
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    50
                                 "Rho", String ("Uniform:0:30"));
2399
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    51
  mobility.SetMobilityModel ("RandomWalk2dMobilityModel",
2502
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    52
                             "Mode", String ("Time"),
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    53
                             "Time", String ("2s"),
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    54
                             "Speed", String ("Constant:1.0"),
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2402
diff changeset
    55
                             "Bounds", String ("0:200:0:100"));
2399
fd9d94d518d2 convert Mobility subsystem to Value framework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2230
diff changeset
    56
  mobility.Layout (NodeList::Begin (), NodeList::End ());
1649
fe121fa40765 Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1645
diff changeset
    57
  NodeList::Connect ("/nodes/*/$MobilityModelNotifier/course-change", 
fe121fa40765 Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1645
diff changeset
    58
                     MakeCallback (&CourseChange));
1612
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    59
0981e5bb0cec get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1583
diff changeset
    60
  Simulator::StopAt (Seconds (100.0));
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    61
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    62
  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
    63
  
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
  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
    65
}