how to get the position of a particular node in ns3 during simulation

3,153 views
Skip to first unread message

Naveen Sheoran

unread,
Jul 13, 2015, 5:12:04 AM7/13/15
to ns-3-...@googlegroups.com
Sir ,

I used the CourseChange in ns3 to locate the position during the simulation
void
CourseChange (std::string context, Ptr<const MobilityModel> model)
{
Vector position = model->GetPosition ();
NS_LOG_UNCOND (context <<
" x = " << position.x << ", y = " << position.y << " , z = " << position.z);
}
it gives me the result like this
/NodeList/9/$ns3::MobilityModel/CourseChange x = 1281.23, y = 1111.41 , z = 795.269
here the no of nodes were 10. So my doubt is that how I can recognize that it is the position of which one node   ?
So please suggest me that find out the position of a particular node ?

Regards
NAVEEN

Konstantinos

unread,
Jul 13, 2015, 5:20:23 AM7/13/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com
Hi Naveen,

Just check your output:
/NodeList/9/$ns3::MobilityModel/CourseChange x = 1281.23, y = 1111.41 , z = 795.269

This is the output for node_9, which is the 10th node, as ns-3 counts from zero.

K.

Naveen Sheoran

unread,
Jul 13, 2015, 7:14:42 AM7/13/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com
hello sir ,
in every node position output it shows the same.i.e. /NodeList/9/$ns3::MobilityModel/CourseChange x = 1281.23, y = 1111.41 , z = 795.269
OR it gives the position of only node 9.
so please suggest me to locate the position.
Regards
NAVEEN

Konstantinos

unread,
Jul 13, 2015, 7:27:05 AM7/13/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com
Your question is a bit unclear. 

If your output is always the same (in terms of context) then either
a) you have configured the trace path only on that node
b) only that node is changing its mobility. 

Without the complete code (attachment), I can't comment one the output.

K.

Naveen Sheoran

unread,
Jul 14, 2015, 1:41:35 AM7/14/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com
hello Sir ,
              the value of X ,Y,Z get change but it only contain the same before that i.e. node list 9.
During the simulation I have found that all the nodes are moving in xml file.
I am putting the code which I put  just below the inclusion of header file

NS_LOG_COMPONENT_DEFINE ("WifiSimpleAdhoc");

using namespace ns3;


void
CourseChange (std::string context, Ptr<const MobilityModel> model)
{
Vector position = model->GetPosition ();
NS_LOG_UNCOND (context <<
" x = " << position.x << ", y = " << position.y << " , z = " << position.z);
}

so now please suggest me.
Regards
NAVEEN

Naveen Sheoran

unread,
Jul 14, 2015, 2:19:21 AM7/14/15
to ns-3-...@googlegroups.com


On Tuesday, July 14, 2015 at 11:11:35 AM UTC+5:30, Naveen Sheoran wrote:
hello Sir ,
              the value of X ,Y,Z get change but it only contain the same before that i.e. node list 9.
During the simulation I have found that all the nodes are moving in xml file.
I am putting the code which I put  just below the inclusion of header file

NS_LOG_COMPONENT_DEFINE ("WifiSimpleAdhoc");

using namespace ns3;

void
CourseChange (std::string context, Ptr<const MobilityModel> model)
{
Vector position = model->GetPosition ();
NS_LOG_UNCOND (context <<
" x = " << position.x << ", y = " << position.y << " , z = " << position.z);
}
 and before the simulation stop
    std::ostringstream oss;
    oss <<"/NodeList/" << c.Get (numNodes - 1)->GetId () <<"/$ns3::MobilityModel/CourseChange";
    Config::Connect (oss.str (), MakeCallback (&CourseChange));

Konstantinos

unread,
Jul 14, 2015, 5:31:16 AM7/14/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com
As I mentioned in my previous replay, there could be two reasons for your error and your problem is explained in the first.

Your config path is configured only to track the 9th node.
If you do not understand why, is simply because you just copy/paste code from others without knowing what you do.
For more explanation, please refer to the tutorial https://www.nsnam.org/docs/tutorial/html/tracing.html#config-paths

Naveen Sheoran

unread,
Jul 14, 2015, 7:48:09 AM7/14/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com
hello Sir,
as I informed you that I did not paste the code from any where.When previously you suggested me then I read it throughly and implemented in my program. I used the GetId () function to get the id of the particular node  but it did not works.
Secondly it did not capture the the position of 9th node because in the above code we have that (nwifi-1) because of that . it shows the node list 9.
so I requested you that please tell me that how I can implement the GetId() so that I can get the location of the particular node. It is not implemented on 9th node.

so if you wish then please suggest me

Regards
NAVEEN

Konstantinos

unread,
Jul 14, 2015, 8:06:56 AM7/14/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com
I can understand that English is not your first language, neither it is mine. 
This causes miscommunication in certain cases. Still I am not able to understand what is the problem and what do you want to achieve.


On Tuesday, July 14, 2015 at 12:48:09 PM UTC+1, Naveen Sheoran wrote:
hello Sir,
as I informed you that I did not paste the code from any where.When previously you suggested me then I read it throughly and implemented in my program. I used the GetId () function to get the id of the particular node  but it did not works.

What does not work? The GetId() method? 
 
Secondly it did not capture the the position of 9th node because in the above code we have that (nwifi-1) because of that . it shows the node list 9.
so I requested you that please tell me that how I can implement the GetId() so that I can get the location of the particular node. It is not implemented on 9th node.


Your code captures the mobility changes only for a single node. 
eg.
oss <<"/NodeList/" << 6 <<"/$ns3::MobilityModel/CourseChange"; <--- this will give the mobility changes of the 6th node
oss <<"/NodeList/" << 0 <<"/$ns3::MobilityModel/CourseChange"; <--- this will give the mobility changes of the 0th node.

In your code, that node ID is given by " c.Get (numNodes - 1)->GetId () ". You said that numNodes is 10, so numNodes-1 = 9 and you get the ID for that node. And the output confirms that you see the position of that node. If you want to get the position of a different node, then you need to change which node you want to see. You can see ALL the nodes if you like by using the wildcard '*'.

Naveen Sheoran

unread,
Jul 15, 2015, 1:21:34 AM7/15/15
to ns-3-...@googlegroups.com, naveenshe...@gmail.com
hello sir ,
I used the same code which I wrote above .
in that code I used the c.(numnode-1)->GetId()
sir I did not find the wildcard. can you please elaborate me how I can use it ?
Regards
NAVEEN
Reply all
Reply to author
Forward
0 new messages