Setting node position in Python

130 views
Skip to first unread message

Oz Kilic

unread,
Jun 28, 2023, 10:52:14 AM6/28/23
to ns-3-users
Hello, I am trying to manually set the positions of nodes with a scheduled function. The problem is this is not covered in the example Python scripts and I could not manage to obtain the mobility model from the node. 

I understand that I need to implement this in Python:

node->GetObject<MobilityModel>()->SetPosition(vector);

I searched the Internet and found some answers that suggest this:

node.GetObject(ns3.MobilityModel.GetTypeId()).SetPosition(vector)

Applying this to my case, I try this:

node.GetObject(ns.ConstantPositionMobilityModel().GetTypeId()).SetPosition(vector)

I get the following error (I tried both inside and outside the scheduled event function):

Traceback (most recent call last):
  File "/path/to/file/sim_test1.py", line 240, in <module>
    ns.core.Simulator.Run()
TypeError: static void ns3::Simulator::Run() =>
    TypeError: Template method resolution failed:
  Failed to instantiate "GetObject(ns3::TypeId&)"
  Failed to instantiate "GetObject(ns3::TypeId*)"
  Failed to instantiate "GetObject(ns3::TypeId)"
Error: tcpip::Socket::recvAndCheck @ recv: peer shutdown
Quitting (on error).


The examples I could find were very old, so I assume they are out-of-date? Am I doing something wrong? Could you show me the correct way to access the mobility model? Thank you very much.

Gabriel Ferreira

unread,
Jun 28, 2023, 1:55:49 PM6/28/23
to ns-3-users
Here are a few examples on how to setup mobility through Python. 
I'm planning to update the docs with these kinds of documents for the next release cycle.

https://github.com/Gabrielcarvfer/Redes-de-Computadores-UnB/blob/master/060_topologia_de_rede_e_mobilidade.ipynb

Oz Kilic

unread,
Jun 28, 2023, 3:02:34 PM6/28/23
to ns-3-users
Dear Mr. Ferreira,

Thank you so much for sharing this! It works now.

Sincerely,

Oz Kilic

Reply all
Reply to author
Forward
0 new messages