Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Implementing Wireless Topology and Power Adaption in ns3
1. Ground to ns3
and
Implementing wireless topology
(Power Adaption) in ns3 plus
visualization in Network Animator
JAWAD ALI
UNIVERSITY OF ENGINEERING AND TECHNOLOGY PESHAWAR
2. Topics Covered
Introduction to ns3 and its comparison with ns2
Finding required modules for coding
Finding sample code
Understanding the code
Checking ns3 core-module.h
Adding animation interface to the code
Compiling and running simulation using NetAnim
Understanding the results from trace file
3. Introduction to ns3 and its comparison
with ns2
Ns3 is just like traditional network simulators and optimization softwares besides its ready to
modify codes and open source licensing
The drawback of ns3 as well as ns2 is that we can’t see the Graphical User Interface (GUI) while
building a project. All we can do is comment the c++ and otcl codes for its understanding. The
topology is defined in c++ in ns3
Ns2 uses traditional otcl and c++ language for its coding on the other hand ns3 uses object
oriented c++, gcc and python. Ns2 always needs otcl for its scripting and c++ for its core
In ns3, everything is c++. You should find it easy if you are good at OOP and c++
Ns2 only supports nam while ns3 supports both nam and PyViz for visualization
Overhead of connecting otcl with c++ in ns2 is removed in ns3, increasing simulation speed
Packet consists of a single portion in ns3 with metadata attached. Payload portion on the ns2
packet is this removed by defining packet as a single object.
4. Finding required modules for coding
Networking follows standards and these standards are kept in certain header files called modules
in ns3
For example, if want to initialize a node. You must initialize it as an object of the class called
nodecontainer that is defined in the network-module.h of ns3.
The same network module is responsible for addressing such as ipv4 addressing scheme.
The internet-module.h knows upd and tcp protocol schemes and one should use it in any
TCP/UDP based communication network.
Assigning applications to a node is done by referring to applicationcontainer, defined in
applications-module.h
Visualization needs network animator module and node topology formation needs a topology
module (e.g. point-to-point.h)
All of the above modules combined by core-module.h library that is responsible for the core work.
5. Finding sample code
For a pro in ns3, it is easy to figure out which module he/she is going to need if the scenario is
drawn on a rough page.
For example: Communication of a node with another node will require a topology defining
module, node formatter module, payload calculation module, application, visualization module
and core module.
For novice, it should be even a big deal to find a library. Though a library has to be known for its
classes and functions which is even a higher difficulty.
Therefore, it is a good programming practice to use already implemented codes and modify
according to our needs
Ns2 has a lot of online libraries as compared to ns3 but you need to understand otcl before any
modification in those ns2 based codes
Ns3 has a variety of user manuals and implemented codes given in ~/source/ns-3-dev/examples/
that are ready to use and to modify. One can easily find the desired sample code by roaming
through those examples
6. Understanding the code
After finding the closest sample code in the library, one needs to understand it.
Online help and documentation of each example is available so we should be
using that.
It is a good practice that one should first know about the scenario implemented in
the example code before roaming through the defined classes and objects called
by the developer of the code
7. Checking the ns3 core-module.h
Create a simple text file naming test1 in scratch directory of ns-3-dev with suffix .cc and
write the following code in it
#include <core-module.h>
using namespace std;
Int main (arg, arg )
{
cout<<“testing ns3 in terminal”;
Return 0;
}
Open terminal and type: cd source/ns-3-dev followed by ./waf –run test1
If you get the statement after you have written in console out. This most likely mean that
your core-module is working fine.
8. Adding Animation Interface to the code
#include "ns3/netanim-module.h“ header has to be included for enabling animation
generation in the compiling code
Also, before
Simulation::Run();
include
AnimationInterface anim ("animation.xml"); //or any other distinct fie name
9. Power Adaption (Compiling and running simulation
using NetAnim)
The simulation consists of 4 Nodes. Of which, 2 nodes are mobile access points
while 2 are Stations (STA#)
• The APs generates UDP traffic with a CBR of 54 Mbps to the STAs.
• The APs use any power and rate control mechanism, and the STAs use only * Minstrel
rate control.
• The STAs can be configured to be at any distance from the APs.
# A station in networking is a device that follows 802.11 protocol
10. Code to run in the terminal
./waf --run "power-adaptation-interference --manager=ns3::AparfWifiManager --
outputFileName=aparf”
Changing STAs position
./waf --run "power-adaptation-interference --manager=ns3::AparfWifiManager --
outputFileName=aparf --STA1_x=5 --STA2_x=205“
To enable the log of rate and power changes
export NS_LOG=PowerAdaptationInterference=level_info
11. Animation Interface in NetAnim
Type ./NetAnim after exploring netanim directory in the terminal
Open the directory from where you have run the ./waf commands
Locate animation stored as .xml file
Open and run
Animation Interface consists of 3 tabs
Animator
Stat
Packet