diff --git a/samples/main-ns2-mob.cc b/samples/main-ns2-mob.cc new file mode 100644 index 000000000..349e42f79 --- /dev/null +++ b/samples/main-ns2-mob.cc @@ -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 + +using namespace ns3; + +static void +CourseChange (std::ostream *os, std::string foo, Ptr 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; +} diff --git a/samples/ns2-mob.tr b/samples/ns2-mob.tr new file mode 100644 index 000000000..b45e39cb2 --- /dev/null +++ b/samples/ns2-mob.tr @@ -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"