add ns2 mobility sample.

This commit is contained in:
Mathieu Lacage
2008-10-24 12:29:39 +02:00
parent 7a923ef2bd
commit d8dad149da
2 changed files with 44 additions and 0 deletions

37
samples/main-ns2-mob.cc Normal file
View File

@@ -0,0 +1,37 @@
#include "ns3/core-module.h"
#include "ns3/mobility-module.h"
#include "ns3/simulator-module.h"
#include "ns3/helper-module.h"
#include "ns3/mobility-module.h"
#include <iostream>
using namespace ns3;
static void
CourseChange (std::ostream *os, std::string foo, Ptr<const MobilityModel> mobility)
{
Vector pos = mobility->GetPosition ();
Vector vel = mobility->GetVelocity ();
*os << Simulator::Now () << " POS: x=" << pos.x << ", y=" << pos.y
<< ", z=" << pos.z << "; VEL:" << vel.x << ", y=" << vel.y
<< ", z=" << vel.z << std::endl;
}
int main (int argc, char *argv[])
{
Ns2MobilityHelper mobility(argv[1]);
std::ofstream os;
os.open (argv[2]);
NodeContainer stas;
stas.Create (1);
mobility.Install ();
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
MakeBoundCallback (&CourseChange, &os));
Simulator::Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}

7
samples/ns2-mob.tr Normal file
View File

@@ -0,0 +1,7 @@
$node_(0) set X_ 0.0
$node_(0) set Y_ 25.0
$node_(0) set Z_ 0.0
$ns_ at 3.0 "$node_(0) setdest 25 0 0"
$ns_ at 4.8 "$node_(0) setdest 0 0 0"
$ns_ at 5.0 "$node_(0) setdest 25 0 0"