How to get velocity

296 views
Skip to first unread message

PavBas

unread,
May 1, 2012, 1:43:20 AM5/1/12
to ns-3-users
Hello, i am new to ns3 and i am trying to implement a protocol for
vanets. I use sumo to generate tracefiles. I successfully read and
load them to my simulation. What i want to do is get the velocity
parameter but not in my main function but in my_protocol.cc(where my
protocol source code is) file so to do some mathematic staff. Can
anyone help? Thank you for your time.

Konstantinos

unread,
May 1, 2012, 5:30:56 AM5/1/12
to ns-3-...@googlegroups.com
Hi,

In order to get velocity as well as position information for a node, you have to get a pointer to the mobility model installed on that node.

So, assuming you have a pointer to the node itself
Ptr<Node> mynode;

You have just to do a simple get
Ptr <MobilityModel> mymobility = mynode -> GetObject<MobilityModel>();
Vector myvelocity = mymobility -> GetVelocity() ;
Vector myposition = mymobilty -> GetPosition() ;

Regards,
Konstantinos

PavBas

unread,
May 1, 2012, 11:38:39 AM5/1/12
to ns-3-users
Thanks very much for your quick answer. That's what i needed it works
perfectly.
Thanks again.

H. Amr

unread,
May 17, 2014, 5:34:42 AM5/17/14
to ns-3-...@googlegroups.com

Hello, i am new to ns3 and i am trying to implement a protocol for
manets, can you help me please what i want to do to get the velocity
parameter but in my_protocol.cc.
can you help me give me an example pleaaase
Best regards

Tommaso Pecorella

unread,
May 17, 2014, 6:07:10 AM5/17/14
to ns-3-...@googlegroups.com
Hi,

the example was already in this thread. What part of it it's obscure to you?

H. Amr

unread,
May 17, 2014, 7:06:10 AM5/17/14
to ns-3-...@googlegroups.com
Hi,
the problem is how can i have a pointer to the node itself ?
Best regards

Tommaso Pecorella

unread,
May 17, 2014, 7:15:23 AM5/17/14
to ns-3-...@googlegroups.com
I'm confused...

you said "I am trying to implement a protocol". As a consequence, I'd assume that you are implementing it.
if this is true, you should be able to set the node pointer during the protocol instantiation or just after. After all, it's your protocol, and you are responsible for its implementation, its internal and so on.
Isn't it ?

Please, don't tell that you didn't check how the protocol will be aggregated to the node... because this would be hilarious.

T

H. Amr

unread,
May 17, 2014, 7:25:34 AM5/17/14
to ns-3-...@googlegroups.com
Hi,
i'm sorry i used the OLSR protocol but i want make some modifications in " olsr-routing-protocol.cc" mostly in the" mprcomputation" function:

for (NeighborSet::const_iterator neighbor = m_state.GetNeighbors ().begin ();
       neighbor != m_state.GetNeighbors ().end (); neighbor++)
    {
Ptr<Node> node=*neighbor; //my ERROR
Ptr<MobilityModel> mymodel=node->.GetObject<MobilityModel>();
Vector v= mymodel->GetPosition();
      if (neighbor->status == NeighborTuple::STATUS_SYM) // I think that we need this check
        {
          N.push_back (*neighbor);
        }
    }
Thanks
Best regards
Reply all
Reply to author
Forward
0 new messages