Adding your own mobility modules to NS3 3.30.1.

211 views
Skip to first unread message

Hubert Ropa

unread,
Feb 5, 2020, 3:01:42 AM2/5/20
to ns-3-users
Hello everyone,

I know it may sound like a stupid question, but I'm trying to create custom mobility model for a project of mine. I decided not to alternate existing models with my code, however when once I implemented it I got stuck with error concerning my model not being found in typeid.cc.2.o. The file is encrypted so I cannot access it for now.

My question is: Does any manual/tutorial for creating own models from scratch exists? (I tried to find any references but were unable to). If not, shall I just go and tweak with already deployed models and adjust them the way I want? 

Does any of you had the same problem and was able to cope with it?

Thanks for all the answers.

Cheers,
Hubert

Message has been deleted

Adil Alsuhaim

unread,
Feb 5, 2020, 11:20:39 AM2/5/20
to ns-3-users
It's not a stupid question, I actually just did it. 

Create a C++ class with .h & .cc extension, and make sure your class is a subclass of ns3::MobilityModel so that it can be used with ns3. You also want to make sure that in your class you create proper GetTypeId and NS_OBJECT_ENSURE_REGISTERED. You can refer to the ns3::ConstantAccelerationMobilityModel for an example.

To use your code, you can place it in the same directory as your project, say under scratch directory you have HubertProject directory, so your files should look like
./scratch
    ./HubertProject
         hubert-main.cc
         custom-mobility-model.h
         custom-mobility-model.cc
And you can run it as follows
./waf --run HubertProject

Now you should be able to use it. I have created a class named LongitudinalVehicularMobilityModel
MobilityHelper mob;
mob.SetMobilityModel("ns3::LongitudinalVehicularMobilityModel");
mob.Install(nodes);

Note the ns3:: part means your class was enclosed between namespace ns3 { ... }

Cheers!

Hubert Ropa

unread,
Feb 6, 2020, 2:41:29 AM2/6/20
to ns-3-users
Thanks a lot!

I will check that as soon as I'm back home today and update a result here! Hope everything will work as expected!

Cheers,
Hubert

Hassam Mughal

unread,
Apr 16, 2020, 11:36:04 AM4/16/20
to ns-3-users

ABDULJABBAR ALSHARIF

unread,
Apr 16, 2020, 2:15:07 PM4/16/20
to ns-3-...@googlegroups.com
Sally comment 

But i have questions here possible not use ns3 headers I main as you said creating our class and save to scratch and executed. 

On Wed, 5 Feb 2020, 21:40 Adil Alsuhaim, <aal...@g.clemson.edu> wrote:
No, it doesn't sound silly. I actually just implemented my own mobility model in ns3. 

I did it by creating a C++ class (.cc) & (.h) files. The C++ class is a subclass of ns3::MobilityModel so that it can be installed to nodes. You really do need your class to be a subclass of ns3::MobilityModel (or a descendant of it) and implement the pure virtual function that it has.

For my work, the C++ class is part of a module library I am working on. But you can place it in scratch if you need to. Say your project is HubertProject, then under the "scratch" directory create a directory and call it HubertProject, and place your code (the file with main function in it) and the classes you implement there

 ./scratch
     ./HubertProject
         hubert-main.cc
         custom-mobility-model.h
         custom-mobility-model.cc

and run it
./waf --run HubertProject

I am not sure about your error, but it seems to be caused because you didn't create the type the ns3 way. Just look into any existing ns3 mobility class, say ns3::ConstantAccelerationMobilityModel, you need to do something similar with the GetTypeId & GetInstanceTypeId function but with your new class name


--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/27d58bd4-bf80-4c51-b565-36a5ee53f38a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages