While starting to learn ns-3, most of us find it very difficult to understand. Particularly, if the student already knows to use ns-2 or Omnet++ then it will even become much harder for him to understand/grasp what ns-3 really is. The student’s or scholar’s preconceived expectation in a simulator will make him misunderstand ns-3. Another major obstacle/misconception in using ns-3 is the way in which python is frequently used along with C++. (Thank Mr Tom Henderson for recent news regarding the removal of python bindings -because it will reduce some of these obstacles )
Of course, the ns-3 Documentations and Manual pages are providing explanations for each and every aspect of this wonderful simulator. But they are huge and their hugeness itself makes it impossible to grasp the very fine, basic aspects of this simulator.
Often, the developer of ns-3 also generously provide answers to the questions or students/learners of ns-3 through the official ns-3 user group. Even with this kind of help and support, it still, it makes impossible for someone to learn and understand ns-3.
This article tries to explain why it is ambiguously hard to understand ns-3 and an ns-3 simulation (I mean, in most cases, even the student can not express the reason for his poor understanding/misunderstanding on ns-3).
How ns-3 is different from most of the other simulators?In most of the popular simulators (except ns-3), the simulator will be a different entity and the simulation script that the user will write for that simulator will be a separate entity. While running the simulation script, the simulator will just run/interpret the lines that the user created.
For example,
If a researcher needs to add a new protocol/application agent (for example in the case of ns-2), then they will write code for that protocol/application agent, by adopting the standards of the core simulator and compiling the core simulator itself with the added new protocol/application agent model. After that, a user can use that new object within their simulations. The simulation script can be modified as per the requirement and can be run without recompiling the core simulator code.
So in other simulators, the simulator will interpret/run the simulation script.
So there will be only one “main()” function through which the core simulator starts running and start interpreting/running the simulation script. No other C++ code module will have “main()” function.
The Organization of ns-2 Simulator and an ns-3 SimulationA. The ns-2 Way of Doing Simulation and Analysisa. The Simulator
The following explains psuedo code explain’s simulator ns-2’s architecture :
The ns-2 Simulator (made up of C++ and TCL Object)
A Typical User-level Simulation Code (made up of TCL)
//Initializing some common simulation parameters
//Creating simulation Object
//Initializing event trace logs and nam Trace ouput
//Configuring Nodes and Protocols
//Setting traffic Flows
//Tunning the simulation
A Typical Trace Analysis Script
ns-3’s way is entirely different. Here, the simulation script that we write in C++ will itself become a separate simulator because it will have the “main()” function. In other words, each and every simulation script that we write under ns-3 will become a separate simulator. So whenever we need to change a single line in our simulation script (C++ code), then we need to recompile our simulator.
a. The Simulation ModulesThe following is the way in which the ns-3 modules and other modules can be visualized. Here, there is no module with a main() function. One model can inherit from another and may use the functionalities of another module.
A Typical ns-3 Simulation Script (made up of ns-3 Standard c++ Code). Here, it is the gate way of start of a ns-3 simulation.
1) We can use the default logging functionality of ns-3 protocol agents /models to log different events of simulation in a text file and then do Trace Analysis just like in the case of ns-2. Like analyzing the trace logs separately using a scripting language (using scripting languages/(advance filters from UNIX perspective) such as tcl, awk, perl, shell etc.,). This approach mostly fails or will not be reliable because of the standards (non-standards) in triggering event logs by different ns-3 protocol agents /models. Further, such creation of logs by a particular protocol agent may differ from one ns-3 version to another. (my articles “Event Trace File Generation in a ns-3 Simulation” and “Trace Analysis of ns-3 Ascii Traces using TraceMetrics Tool – An elementary Trace Analysis Solution for ns-3“ are dealing with this kind of tracking and analysis.)
Trace Analysis of TCP Flows Under ns-3 MANET/ FANET/ VANET/ WSN Scenario” uses this approach)
ns-3 is nothing but a collection of C++ objects of Protocols/Application Agents and the simulation core modules. So the separate code of all of these objects of Protocols/Application Agents and the simulation core modules, will not have “main()” function. So ns-3 is technically a collection of Network Simulation objects – not a simulator by itself. (please correct me if I am wrong)
So, simply, the simulation script (the C++ code) that we write will have the main() function, which will be the gateway/starting point of the simulator. So, simply, after compiling our code, using all other referred/used modules of ns-3(including the core simulator modules), our code itself gets compiled and will become a new simulator. (please correct me if I am wrong)
Technically, what we conventionally call ns-3 is not at all a simulator by itself. The simulation script that we write itself will become a custom simulator. So each and every simulation script that we write will become a separate, custom network simulator. (please correct me if I am wrong)
Why ns-3 simulation run faster than most of the simulators?The main reason is; the simulation code is not interpreted by any other entity. The simulation code itself is the simulator. So it will run at the native speed of the hardware and software – just like other running executable code/process of the operating system.
Another important reason is: While writing the ns-3 simulation script, we will only add the C++ objects of Protocols/Application Agents that are needed for that particular simulation. So, the final compiled version of the simulator (compiled version of our code) will only have the used/referred modules. So, each final compiled version of the simulator (compiled version of our code) will be smaller in size and the size may vary according to the number of used/referred C++ objects of Protocols/Application Agents in each simulation scripts (our main c++ simulation code)
Other obstacles in front of Understanding ns-3
The more advanced way of handling C++ objects/functions/constants/variables makes it even harder to understand or grasp a typical ns-3 simulation model and even a simple ns-3 simulation script.
Even though some of these kinds of advanced C++ conventions are taught during an object-oriented programming classroom, here and there, they are not commonly practised in programming; at least by a student or an amateur programmer.
For example, the following line will set the default WifiMacQueue delay
Of course, there may a good reason for doing like this from the Object-Oriented Programming Point of View. But these kinds of long, explicit references in declarations simply make it impossible to grasp what actually we are doing here(and where). Further, if a typo mistake is made anywhere in this line the compiler will raise an error message in a “foreign language” which will not be at all inhuman readable form. It may advise you to use gdb to trace that error – then again the gdb will raise another error message in another “foreign language” which will not also be at all inhuman readable form. (Please think about a poor learner who is trying to learn ns-3 here)
What restricts the developers to using simple conventions/declarations like the following? In this case, understanding the line and even tracking an error may be an easy task for a human.
Of course, this kind of declaration may lead to some errors/problems from an Object-Oriented Programming Point of View. But will be a more human-understandable way of doing things in a computer programme.
To understand it further, I hereby give another example :
An XML way of handling data may be easy for a machine to handle and parse data. But definitely, the same XML format data will not be good for human understanding.
So, from this perspective, an ns-3 simulation script is more friendly towards a machine-readable form. Definitely not friendly towards a human-readable form.
While developing a huge system like ns-3 using Object-Oriented Programming techniques, the level of attraction and hierarchy of organizing/doing things should hide the complex things behind the scene from the end-user (the ns-3 simulation writer/student/researcher). The interfaces that are provided to handle the objects and change the properties of the objects should be human-understandable forms. But according to my view, from the first day of development itself, the developers ignored this point and now the ns-3 becomes a huge, complex machine only understandable form.
Once I heard that Unix was originally developed by programmers for programmers.
Just like that, I think, ns-3 was developed by brilliant developers for brilliant developers.
But I think, changing the way ns-3 does these kinds of things can not be altered/rectified now – because, ns-3 become huge with all kinds of these complexities. Just expressing my feelings/disabilities that’s all.
Solution(?):And I think, using ns-3 within an IDE like Eclipse or QTCreator may hide some of this complexity. But, definitely, it also will make a user not to understand what is really happening in a particular line of code.
(Final Note: My scope is not offending the generous developers who are sacrificing their precious time on the development and maintenance of ns-3 – just telling my opinion from my idiotic point of view -that’s all)
Charles Pandian.
--
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/daefd1f9-9661-402c-aa92-7231e0074806n%40googlegroups.com.
Dear all,
I am trying to make a post/article on "What Makes ns-3 a Complex Thing to Understand and Use? "The following is the thing that I discussed in that article/post.
(Sorry. I could not format this text here - to see formatted text use the above link)
Please share your insights to improve and incorporate things in that article. I think it may be useful for newcomers to understand ns-3.
Please share your experience so that I may fulfil the scope of that post/article
Charles Pandian
-------------------------------------------
What Makes ns-3 a Complex Thing to Understand and Use?Article Written by: CharlesPandian November 23, 2021 | Edit ThisWhile starting to learn ns-3, most of us find it very difficult to understand. Particularly, if the student already knows to use ns-2 or Omnet++ then it will even become much harder for him to understand/grasp what ns-3 really is. The student’s or scholar’s preconceived expectation in a simulator will make him misunderstand ns-3. Another major obstacle/misconception in using ns-3 is the way in which python is frequently used along with C++. (Thank Mr Tom Henderson for recent news regarding the removal of python bindings -because it will reduce some of these obstacles )
Of course, the ns-3 Documentations and Manual pages are providing explanations for each and every aspect of this wonderful simulator. But they are huge and their hugeness itself makes it impossible to grasp the very fine, basic aspects of this simulator.
Often, the developer of ns-3 also generously provide answers to the questions or students/learners of ns-3 through the official ns-3 user group. Even with this kind of help and support, it still, it makes impossible for someone to learn and understand ns-3.
This article tries to explain why it is ambiguously hard to understand ns-3 and an ns-3 simulation (I mean, in most cases, even the student can not express the reason for his poor understanding/misunderstanding on ns-3).
How ns-3 is different from most of the other simulators?In most of the popular simulators (except ns-3), the simulator will be a different entity and the simulation script that the user will write for that simulator will be a separate entity. While running the simulation script, the simulator will just run/interpret the lines that the user created.
For example,
- Under ns-2, the simulation will be presented in the form of TCL script and the core simulator which is made up of C++ and TCL objects will simply interpret the lines of the TCL simulation script.
- Under Omnet ++, the simulation script will be a custom format text file (not like any programming language) core simulator which is made up of C++ objects will simply interpret the lines of the simulation script.
- Even most of the non-free simulators are following the same ideology (Simulator is different from simulation script)
Many simulators have a high-level modeling language, and a GUI
for simulation composition. ns-3 did not preclude adding this,
but the decision early on was to just code directly into C++,
assuming that typical users would need to know C++ anyway to
modify or write new models. A GUI or high-level language could be
added on top of ns-3, and it would be very helpful to new users or
those less skilled with C++; the problem is that this is a lot of
work to develop and maintain.
If a researcher needs to add a new protocol/application agent (for example in the case of ns-2), then they will write code for that protocol/application agent, by adopting the standards of the core simulator and compiling the core simulator itself with the added new protocol/application agent model. After that, a user can use that new object within their simulations. The simulation script can be modified as per the requirement and can be run without recompiling the core simulator code.
So in other simulators, the simulator will interpret/run the simulation script.
It is not hard to use ns-3 command-line arguments to avoid
recompiling the program when conducting a large simulation
campaign, though.
Further, as a standard, the trace analysis done by another independent script, it can be run again and again (with little modification during trial and error) without even disturbing or running the simulation code.The ns-3 Way of Doing Simulation and Analysisns-3’s way is entirely different. Here, the simulation script that we write in C++ will itself become a separate simulator because it will have the “main()” function. In other words, each and every simulation script that we write under ns-3 will become a separate simulator. So whenever we need to change a single line in our simulation script (C++ code), then we need to recompile our simulator.
Please keep in mind that the simulator is really a set of shared libraries that are less frequently compiled. I am not sure that calling every simulation script a separate 'simulator' is a helpful way to put it.
One may do trace analysis in the following ways :1) We can use the default logging functionality of ns-3 protocol agents /models to log different events of simulation in a text file and then do Trace Analysis just like in the case of ns-2. Like analyzing the trace logs separately using a scripting language (using scripting languages/(advance filters from UNIX perspective) such as tcl, awk, perl, shell etc.,). This approach mostly fails or will not be reliable because of the standards (non-standards) in triggering event logs by different ns-3 protocol agents /models. Further, such creation of logs by a particular protocol agent may differ from one ns-3 version to another. (my articles “Event Trace File Generation in a ns-3 Simulation” and “Trace Analysis of ns-3 Ascii Traces using TraceMetrics Tool – An elementary Trace Analysis Solution for ns-3“ are dealing with this kind of tracking and analysis.)
2) We can generate tcpdump format trace outputs while running a simulation, and later we may do trace analysis using tcpdump analysers such as “Wireshark”. This approach also will not be useful in most cases of a scholarly research-level simulation – because, in such cases, the trace analysis should be done on the output trace files of several batch runs of the simulation. So applying Wireshark based trace analysis on that huge number of separate trace files will become a meaningless operation. So, this kind of approach of trace analysis will be useful in understanding an event from a single run of simulation – for example while teaching something in classroom/lab or finding a critical event that may be causing unexpected behaviour in a simulation.3) The most reliable way of doing trace analysis on a batch of ns-3 simulations is using the FlowMonitor facility of ns-3. Further, that cal also is done more than one way.i) The most often used way is: using FlowMonitor inside the ns-3 simulation, and iterating FlowMonitor::FlowStats with a for loop and calculate and to log throughput, delay etc., using different parameters of FlowMonitor::FlowStats. Again, this will need additional scripting to collect and parse output from the logged outputs of several batch runs of the simulation.ii) Another way using FlowMonitor is: to instruct the FlowMonitor to log all the events in an XML file and we may later do trace analysis on such XML flow monitor log files. This way is much suitable for doing scholarly research. (my article ”Trace Analysis of TCP Flows Under ns-3 MANET/ FANET/ VANET/ WSN Scenario” uses this approach)
iii) There may be some other technique to use FlowMonitor inside a simulation and using the XML file of FlowMonitor outside the simulation – I do not know – the researcher may explore it as per their need of analysis of the ouputs of batch runs of the simulation.So, what is ns-3 now?ns-3 is nothing but a collection of C++ objects of Protocols/Application Agents and the simulation core modules. So the separate code of all of these objects of Protocols/Application Agents and the simulation core modules, will not have “main()” function. So ns-3 is technically a collection of Network Simulation objects – not a simulator by itself. (please correct me if I am wrong)
ns-3 is a set of simulation libraries that can be linked to many
simulation programs that configure the scenario, run the
simulation, and perform any necessary post-processing. I think
you can clearly call ns-3 a simulator; I don't think people would
object to that term.
So, simply, the simulation script (the C++ code) that we write will have the main() function, which will be the gateway/starting point of the simulator. So, simply, after compiling our code, using all other referred/used modules of ns-3(including the core simulator modules), our code itself gets compiled and will become a new simulator. (please correct me if I am wrong)
Technically, what we conventionally call ns-3 is not at all a simulator by itself. The simulation script that we write itself will become a custom simulator. So each and every simulation script that we write will become a separate, custom network simulator. (please correct me if I am wrong)
Why ns-3 simulation run faster than most of the simulators?The main reason is; the simulation code is not interpreted by any other entity. The simulation code itself is the simulator. So it will run at the native speed of the hardware and software – just like other running executable code/process of the operating system.
Another important reason is: While writing the ns-3 simulation script, we will only add the C++ objects of Protocols/Application Agents that are needed for that particular simulation. So, the final compiled version of the simulator (compiled version of our code) will only have the used/referred modules. So, each final compiled version of the simulator (compiled version of our code) will be smaller in size and the size may vary according to the number of used/referred C++ objects of Protocols/Application Agents in each simulation scripts (our main c++ simulation code)
Other obstacles in front of Understanding ns-3The more advanced way of handling C++ objects/functions/constants/variables makes it even harder to understand or grasp a typical ns-3 simulation model and even a simple ns-3 simulation script.
Even though some of these kinds of advanced C++ conventions are taught during an object-oriented programming classroom, here and there, they are not commonly practised in programming; at least by a student or an amateur programmer.
For example, the following line will set the default WifiMacQueue delay
Config::SetDefault(“ns3::WifiMacQueue::MaxDelay”, TimeValue(Seconds(WifiMacQueueMaxDelay)));
Of course, there may a good reason for doing like this from the Object-Oriented Programming Point of View. But these kinds of long, explicit references in declarations simply make it impossible to grasp what actually we are doing here(and where). Further, if a typo mistake is made anywhere in this line the compiler will raise an error message in a “foreign language” which will not be at all inhuman readable form. It may advise you to use gdb to trace that error – then again the gdb will raise another error message in another “foreign language” which will not also be at all inhuman readable form. (Please think about a poor learner who is trying to learn ns-3 here).
This is a consequence of the low-level C++ that users need to
deal with. However, most typos are easily deduced and fixed, in
my experience.
What restricts the developers to using simple conventions/declarations like the following? In this case, understanding the line and even tracking an error may be an easy task for a human.
WifiMacQueue->MaxDelay=10
or
WifiMacQueue.MaxDelay=10
or even
WifiMacQueue.SetMaxDelay(10)Of course, this kind of declaration may lead to some errors/problems from an Object-Oriented Programming Point of View. But will be a more human-understandable way of doing things in a computer programme.
I agree, but as Gabriel pointed out, you can do this with similar syntax already if you just need to change the value on a single queue. But of course, '10' is imprecise, so you need units, and then you need to parse the strings like 'ms' that make up the units, and for various reasons we found that it was much more solid to encode time in integers within an ns3::Time class, leading to the use of time objects. This means that you can, in fact, write:
wifiMacQueue->SetMaxDelay (MilliSeconds (10));
which is close to what you are suggesting.
I think that there is a facility that provides more friendly syntax for the default values, which is the ConfigStore subsystem:
https://www.nsnam.org/docs/release/3.35/manual/html/attributes.html#configstore
To understand it further, I hereby give another example :
An XML way of handling data may be easy for a machine to handle and parse data. But definitely, the same XML format data will not be good for human understanding.
So, from this perspective, an ns-3 simulation script is more friendly towards a machine-readable form. Definitely not friendly towards a human-readable form.
While developing a huge system like ns-3 using Object-Oriented Programming techniques, the level of attraction and hierarchy of organizing/doing things should hide the complex things behind the scene from the end-user (the ns-3 simulation writer/student/researcher). The interfaces that are provided to handle the objects and change the properties of the objects should be human-understandable forms. But according to my view, from the first day of development itself, the developers ignored this point and now the ns-3 becomes a huge, complex machine only understandable form.
Once I heard that Unix was originally developed by programmers for programmers.
Just like that, I think, ns-3 was developed by brilliant developers for brilliant developers.
I would phrase it as 'ns-3 was developed by and for power users'; specifically, people who are inclined to do networking research. That is definitely true. The idea was that at some point, more could be added on top of the low level, command-line API to make it simpler for more beginning students, and a GUI can be provided, etc.
The other key thing to remember is that ns-3 is fully open source
and contribution driven; there is no company behind it.
Therefore, things get done by virtue of what is contributed, not
what any maintainer is told to work on. We are on the verge of
adding CMake build system because a contributor (Gabriel) showed
up with the patches and perseverance to get it done-- no one asked
him to do this work (as far as I know). The main contributors of
ns-3 are generally people who work on networking research either
in academia or industry. Therefore, the type of code
contributions reflect this, and we acknowledge that it could be
easier to use if contributors had more time to focus on usability
and more examples, etc. We also seldom get example programs
contributed from the community; we are usually trying to come up
with (basic) examples ourselves.
But I think, changing the way ns-3 does these kinds of things can not be altered/rectified now – because, ns-3 become huge with all kinds of these complexities. Just expressing my feelings/disabilities that’s all.
Solution(?):And I think, using ns-3 within an IDE like Eclipse or QTCreator may hide some of this complexity. But, definitely, it also will make a user not to understand what is really happening in a particular line of code.
(Final Note: My scope is not offending the generous developers who are sacrificing their precious time on the development and maintenance of ns-3 – just telling my opinion from my idiotic point of view -that’s all)
I take no offense at what you wrote. In fact, I welcome feedback on the usability of ns-3, and it is a concern of mine-- I actually plan to be focusing more on usability once some of my current efforts wrap up. I wish more people gave us constructive criticism or suggestions for improvements.
- Tom
--Charles Pandian.
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/8a2baab6-2005-4ce0-8b39-ccc30d84201cn%40googlegroups.com.
Btw, the complexity is (also) because the codebase is very large, and it must be as efficient as possible - you don't want your simulations to last forever...
On the bright side (for real) writing a script should be fairly easy. It's when you have to modify a model that things become... complicated. However, the trick in this case is: learn by copying. Don't try to understand everything at once, sometimes you have to trust the fact that it will work. After a while you'll discover why it works.
And if this can make you feel better, I think that parts of the code are pure black magic. I trust that they work, and I don't even dare to touch them.
--
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/05cbc315-1b36-4af8-9025-306d5b0112a8n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/b5e310b2-55a8-407c-9a9a-2af0cd214156n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/c3d099b5-81ea-0813-05a4-8a81738c7449%40tomh.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/99d745ae-1de4-4f31-8558-a394733de31an%40googlegroups.com.