author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Tue, 06 Nov 2007 15:05:56 +0100 | |
changeset 2081 | 434742b27b1e |
parent 1650 | bcfb726651bb |
child 1816 | d7c9b9da78f4 |
permissions | -rw-r--r-- |
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" |
1578
c06feb6d1f51
PositionSetNotifier -> MobilityModelNotifier
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1558
diff
changeset
|
7 |
#include "ns3/mobility-model-notifier.h" |
1612
0981e5bb0cec
get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1583
diff
changeset
|
8 |
#include "ns3/random-topology.h" |
1555
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
9 |
#include "ns3/default-value.h" |
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
10 |
#include "ns3/command-line.h" |
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
11 |
#include "ns3/simulator.h" |
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
12 |
#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
|
13 |
#include "ns3/node.h" |
fe121fa40765
Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1645
diff
changeset
|
14 |
#include "ns3/node-list.h" |
1555
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
15 |
|
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
16 |
using namespace ns3; |
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
17 |
|
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
18 |
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
|
19 |
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
|
20 |
{ |
1650
bcfb726651bb
On course-change, print velocity in addition to position.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1649
diff
changeset
|
21 |
Position pos = mobility->Get (); |
bcfb726651bb
On course-change, print velocity in addition to position.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1649
diff
changeset
|
22 |
Speed vel = mobility->GetSpeed (); |
bcfb726651bb
On course-change, print velocity in addition to position.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1649
diff
changeset
|
23 |
std::cout << Simulator::Now () << ", model=" << mobility << ", POS: x=" << pos.x << ", y=" << pos.y |
bcfb726651bb
On course-change, print velocity in addition to position.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1649
diff
changeset
|
24 |
<< ", z=" << pos.z << "; VEL:" << vel.dx << ", y=" << vel.dy |
bcfb726651bb
On course-change, print velocity in addition to position.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1649
diff
changeset
|
25 |
<< ", z=" << vel.dz << std::endl; |
1555
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
26 |
} |
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
|
27 |
|
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 |
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
|
29 |
{ |
1645
7411d6e0f82a
Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1612
diff
changeset
|
30 |
DefaultValue::Bind ("RandomWalk2dMode", "Time"); |
7411d6e0f82a
Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1612
diff
changeset
|
31 |
DefaultValue::Bind ("RandomWalk2dTime", "2s"); |
7411d6e0f82a
Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1612
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
|
1645
7411d6e0f82a
Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1612
diff
changeset
|
35 |
DefaultValue::Bind ("RandomDiscPositionX", "100"); |
7411d6e0f82a
Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1612
diff
changeset
|
36 |
DefaultValue::Bind ("RandomDiscPositionY", "50"); |
7411d6e0f82a
Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1612
diff
changeset
|
37 |
DefaultValue::Bind ("RandomDiscPositionRho", "Uniform:0:30"); |
1612
0981e5bb0cec
get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1583
diff
changeset
|
38 |
|
1645
7411d6e0f82a
Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1612
diff
changeset
|
39 |
DefaultValue::Bind ("RandomTopologyPositionType", "RandomDiscPosition"); |
7411d6e0f82a
Update random mobility sample to new API
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1612
diff
changeset
|
40 |
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
|
41 |
|
1555
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
42 |
CommandLine::Parse (argc, argv); |
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
43 |
|
1612
0981e5bb0cec
get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1583
diff
changeset
|
44 |
RandomTopology topology; |
1555
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
45 |
|
1612
0981e5bb0cec
get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1583
diff
changeset
|
46 |
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
|
47 |
{ |
1649
fe121fa40765
Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1645
diff
changeset
|
48 |
Ptr<Node> node = Create<Node> (); |
fe121fa40765
Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1645
diff
changeset
|
49 |
node->AddInterface (Create<MobilityModelNotifier> ()); |
1612
0981e5bb0cec
get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1583
diff
changeset
|
50 |
} |
0981e5bb0cec
get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1583
diff
changeset
|
51 |
|
1649
fe121fa40765
Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1645
diff
changeset
|
52 |
topology.Layout (NodeList::Begin (), NodeList::End ()); |
fe121fa40765
Create real nodes, not just mobility models.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
1645
diff
changeset
|
53 |
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
|
54 |
MakeCallback (&CourseChange)); |
1612
0981e5bb0cec
get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1583
diff
changeset
|
55 |
|
0981e5bb0cec
get rid of old buggy random walk model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1583
diff
changeset
|
56 |
Simulator::StopAt (Seconds (100.0)); |
1555
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
57 |
|
d3e9007db75b
improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1554
diff
changeset
|
58 |
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
|
59 |
|
76e781c120bb
rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
60 |
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
|
61 |
} |