node position during simulation

922 views
Skip to first unread message

nabil torjemen

unread,
May 11, 2015, 3:51:55 PM5/11/15
to ns-3-...@googlegroups.com
Hi for all,
I'm trying to get the distance between two node during the simulation using the following code :
Ptr<MobilityModel> MAPP_position =  mesh.mesh_nodes.Get(3)-> GetObject<MobilityModel>();
Ptr<MobilityModel> mob_position =  epc.ueNodes.Get(1)-> GetObject<MobilityModel>();
 
distance
=sqrt(pow(MAPP_position->GetPosition().x-mob_position->GetPosition().x,2)+pow(MAPP_position->GetPosition().y-mob_position->GetPosition().y,2)+pow(MAPP_position->GetPosition().z-mob_position->GetPosition().z,2));
std
::cout<< distance <<" \n";

the output is only one value (defined by the first position of the nodes)  even the second node is moving.
It seems that I need to use the method schedule of the simulator to do it but I haven't understand how to use it.
Can your help me ?
best regards.

Konstantinos

unread,
May 11, 2015, 4:07:12 PM5/11/15
to ns-3-...@googlegroups.com, torj...@topnet.tn
Hi,

Indeed this will report the distance only once when you call this method.
Scheduling a periodic event has been discussed in the list several times and the principles are explained in the documentation.

In short, you need to create a method which basically will do the calculation/printing you have here:
distance=sqrt(pow(MAPP_position->GetPosition().x-mob_position->GetPosition().x,2)+pow(MAPP_position->GetPosition().y-mob_position->GetPosition().y,2)+pow(MAPP_position->GetPosition().z-mob_position->GetPosition().z,2));
std
::cout<< distance <<" \n";
and you will use Simulator::Schedule to call it periodically.


Regards,
K.

nabil torjemen

unread,
May 12, 2015, 2:35:57 PM5/12/15
to ns-3-...@googlegroups.com, torj...@topnet.tn
Hi,
Thanks for your reply.
I have already do it and it works fine.
However, the method schedule depend on time so and calculate the distance at the time specified by the first parameter. Can it be used to do the same thing just only when the nodes position change ?
I mean that the distance calculation will be only trigged when the nodes positions was changed.
Best regards.

Konstantinos

unread,
May 12, 2015, 3:03:17 PM5/12/15
to ns-3-...@googlegroups.com, torj...@topnet.tn
Yes, check the CourseChange trace source from the mobility model. 
This is fired when there is a change in the mobility model of the node (e.g. change in direction, speed, etc).
So, you can call your distance calculation when that trace source is fired.

There is an example in the tutorial showcasing the use of CourseChange.

nabil torjemen

unread,
May 12, 2015, 3:56:28 PM5/12/15
to ns-3-...@googlegroups.com
Hi,
the method connect use as input the path for one node or all nodes and the CourseChange function is used with on mobility model as input.
I have go the following change:
static void CourseChange (Ptr<const MobilityModel> mob_MAPP,Ptr<const MobilityModel> mob_Ue)
{
    float_t distance
= 0;
    distance
=sqrt(pow(mob_MAPP->GetPosition().x-mob_Ue->GetPosition().x,2)+pow(mob_MAPP->GetPosition().y-mob_Ue->GetPosition().y,2)+pow(mob_MAPP->GetPosition().z-mob_Ue->GetPosition().z,2));
    std
::cout<< distance<<" \n";
}

and then use connect method as below:
Config::Connect("/NodeList/*/$ns3::MobilityModel/CourseChange",MakeCallback(&CourseChange));

the fisrt part is the input for all nodes and the star can be changed with the ID of a specific nodes. However, I need just only to choose two of them. How the string should be changed ?
In other side, the use of two mobility model in the CourseChange method is it correct ?
Best regards.

Haider Alkafajy

unread,
May 12, 2015, 11:50:50 PM5/12/15
to ns-3-...@googlegroups.com
Hi 
double dis;
dis = sqrt (mobility.GetDistanceSquaredBetween( node1,node2));

 it is simplest way to get distance between tow nodes. 

regards 

Haider 

nabil torjemen

unread,
May 14, 2015, 4:35:57 AM5/14/15
to ns-3-...@googlegroups.com
Hi for all,
I have write the following code based on the tutorial and example:
static void CourseChange (std::string context,Ptr<const MobilityModel> mob_Ue)
{
    std
::cout<< "position ="<< mob_Ue->GetPosition().x<<" \n";

}
  std
::ostringstream oss;
  oss  
<<"/NodeList/"<< epc.ueNodes.Get(0)->GetId()<<"/$ns3::MobilityModel/CourseChange";
 
Config::Connect(oss.str (),MakeCallback(&CourseChange));

The ouput is only the first position of the chosen node. what is the problem ?
In other side, to show the position of two node, should I add the path of the second node to oss paramater ?
Best regards.

nabil torjemen

unread,
May 14, 2015, 11:24:34 AM5/14/15
to ns-3-...@googlegroups.com
Hi ,
The first part of my last question is not yet resolved and I still get only the first position of the chosen node as output.
However, the second part is partially resolved: In fact, if I use two nodes belonging to the same Nodecontainer and Having the same mobility model (I'm using a trace file from Bonnmotion) using the following code, I get the initial position of the two nodes:

oss  <<"/NodeList/"<<epc.ueNodes.Get(0)->GetId()<<"|"<<epc.ueNodes.Get(1)->GetId()<<"/$ns3::MobilityModel/CourseChange";  

However, if I need to use a different two differents nodes from differents nodecontainer and having different mobility model ( the first one is from Bonnmotion trace file and the second using ConstantPositionMobilityModel), I get only the initial position of the first node:
oss  <<"/NodeList/"<<epc.ueNodes.Get(0)->GetId()<<"|"<<mesh.mesh_nodes.Get(3)->GetId()<<"/$ns3::MobilityModel/CourseChange";  

Can you tell me what is the issue ?
Best regards.

Konstantinos

unread,
May 14, 2015, 5:48:34 PM5/14/15
to ns-3-...@googlegroups.com, torj...@topnet.tn
Hi Nabil,

Please study the ns-3 documentation to understand how you can use trace sources.
The CourseChange trace source will fire each time the mobility of the node changes. If you use for example ConstantVelocity mobility model, it will only fire at the beginning once because it does not change something in the model. The node will move but with constant speed. If you change its speed, then it will fire.

Since the eNB is static and only the UEs move and you know where the eNB is, then what is the problem to 'hard code' that information when your callback is fired?

nabil torjemen

unread,
May 15, 2015, 6:28:36 AM5/15/15
to ns-3-...@googlegroups.com, torj...@topnet.tn
Hi Konstantinos,
Thanks for your reply.
Both the two problem was fixed.
the fisrt one, regarding the two mobility model: I will write the code including the Mesh AP position as it is static.
The second one, I get only the first position as the time of simualtion is shorter than the time used in Bonnmotion trace file. I have increase the simulation time and the Coursechange is now fired.
Thanks for your help.
Best regards.

caixiang2...@gmail.com

unread,
Jun 10, 2015, 3:51:05 AM6/10/15
to ns-3-...@googlegroups.com, torj...@topnet.tn
Hello:
        if I want to get node'position in L3(network layer),what should I do?

在 2015年5月12日星期二 UTC+8上午4:07:12,Konstantinos写道:

Tommaso Pecorella

unread,
Jun 10, 2015, 3:59:45 AM6/10/15
to ns-3-...@googlegroups.com, torj...@topnet.tn
Hi,

you need to study the manual. That could, indeed, help a lot. Of course, this is valid if you did already study the tutorial...

T.
Reply all
Reply to author
Forward
0 new messages