How to customize my own protocol in NS3?

58 views
Skip to first unread message

Nick Jay

unread,
Oct 7, 2024, 10:13:31 AM10/7/24
to ns-3-users
I want to design my own protocol to substitute csma in ns3. I have checked the codes of csma in file "src/csma/model" and all I found is defined functions such as backoff.cc. So should I need to design my own file with the same construction as file "csma"?
The second question is which module, script or  the main function of this simulator loads the functions defined in the "csma" file to simulate the media access control of the whole network. I didn't find any script that controls the whole simulation. Can anyone help me, thank you!
Message has been deleted

Raouane Dehimi

unread,
Oct 9, 2024, 5:53:45 AM10/9/24
to ns-3-users
what the version u have is it old 
because there 3 not just the backoff.cc add to that 3 header files either u have problem in downloading or u are using old version .
for the second question there example file in csma that u can use as refer to create your own simulation.

Tommaso Pecorella

unread,
Oct 9, 2024, 6:00:49 PM10/9/24
to ns-3-users
Sorry, it looks like my previous message was lost.

I'm assuming that you're using a recent ns-3 version, like ns-3-dev or ns-3-42 (FYI ns-3-43 is about to be released).
I'm also assuming that you're familiar with C++ and object oriented coding.

Depending on the amount of changes you plan to do you might extend the csma class or make a new module altogether (see "Creating a new model" in the manual - https://www.nsnam.org/docs/manual/html/new-models.html).

About the class defined in backoff.cc / backoff.h (the class is named Backoff), it is used in a single member variable inside CsmaNetDevice: "Backoff m_backoff;". Its functions do the rest (basically calculating the backoff time). You can explore the CsmaNetDeive code to find where the variable is used and how.

About how the class/functions are used... it's a bit too complex to explain in a single post, but it's explained in the tutorial and manual, check them: https://www.nsnam.org/documentation/
Let me just summarize that if you define a new module, and the module defines a new NetDevice subclass, making it "work" should be as easy as installing a CsmaNetDevice in a node, just like in the examples in the tutorial.

If the above explanation looks incomprehensible to you, I'd suggest to start reading the tutorial and the manual, and then things will be more understandable.
Reply all
Reply to author
Forward
0 new messages