In general, there are several programming languages which are used for the implementation process. In particular, Ns3 is mainly using two significant languages such as C++ and python.
Additionally, the fundamental packages are required to start the process in Ns3 along with its installation and they are implemented through the following commands.
apt install g++ python3 cmake ninja-build git
apt install g++ python3
apt install g++ python2
python3 -m pip install –user cppyy
apt install gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3
apt install g++ python3 python3-dev pkg-config sqlite3 cmake
Now, let’s look into the sample codes based on python. In the following, we have highlighted the sample codes for the process that are mentioned below.
- Node creation
- Application creation
- Simulation implementation
Sample code for node creation process in python
nodes = ns.network.NodeContainer()
nodes.Create(2)
Sample code for to create applications in python
serverApps = echoServer.Install(nodes.Get(1))
serverApps.Start(ns.core.Seconds(1.0))
serverApps.Stop(ns.core.Seconds(10.0))
echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
echoClient.SetAttribute(“MaxPackets”, ns.core.UintegerValue(1))
echoClient.SetAttribute(“Interval”, ns.core.TimeValue(ns.core.Seconds (1.0)))
echoClient.SetAttribute(“PacketSize”, ns.core.UintegerValue(1024))
clientApps = echoClient.Install(nodes.Get(0))
clientApps.Start(ns.core.Seconds(2.0))
clientApps.Stop(ns.core.Seconds(10.0))
Sample code for simulation implementation in python
ns.core.Simulator.Run()
Consequently, we can implement the simulation in main file through the utilization of below mentioned command.
cd /home/research/ns-allinone-3.26/ns-3.26
./waf shell
python scratch/MainFile.py
On the other hand, we have an alternative process for the implementation of .cc main file. For your reference, we have highlighted that process in the following with the sample code in .cc.
Next, we have implemented the .cc based main file through executing the following command.
sudo ./waf –run Main –vis
Finally, the result acquired through this process has been depicted in the following screen.
If you want to know more information about the sorts of Ns3 implementation then contact us to grab some innovative knowledge in this process.