NS3 PYTHON SIMULATION

              We are here to provide the complete research assistance based on the functions of network simulator 3 in python.

Sample Ns3 Python Code

               As a start, we have highlighted some sample python code for your reference with its specifications.

  • Packet transmission
echoServer = ns.applications.UdpEchoServerHelper(9)
serverApps = echoServer.Install(csmaNodes.Get(nCsma))
serverApps.Start(ns.core.Seconds(1.0))
serverApps.Stop(ns.core.Seconds(10.0))
echoClient = ns.applications.UdpEchoClientHelper(csmaInterfaces.GetAddress(nCsma), 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(wifiStaNodes.Get (nWifi - 1))
clientApps.Start(ns.core.Seconds(2.0))
clientApps.Stop(ns.core.Seconds(10.0))
  • IP configuration
address = ns.internet.Ipv4AddressHelper()
address.SetBase(ns.network.Ipv4Address("10.1.1.0"),
ns.network.Ipv4Mask("255.255.255.0"))
p2pInterfaces = address.Assign(p2pDevices)
address.SetBase(ns.network.Ipv4Address("10.1.2.0"),
ns.network.Ipv4Mask("255.255.255.0"))
csmaInterfaces = address.Assign(csmaDevices)
address.SetBase(ns.network.Ipv4Address("10.1.3.0"),
ns.network.Ipv4Mask("255.255.255.0"))
address.Assign(staDevices)
address.Assign(apDevices)
  • Point to point configuration
p2pNodes = ns.network.NodeContainer()
p2pNodes.Create(2)
pointToPoint = ns.point_to_point.PointToPointHelper()
pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps"))
pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms"))
p2pDevices = pointToPoint.Install(p2pNodes)
  • Import packages
import ns.core
import ns.network
import ns.point_to_point
import ns.applications
import ns.wifi
import ns.mobility
import ns.csma
import ns.internet
import sys

Configure Python Code

         Then, we have to configure the python code through the implementation of the below mentioned commands.

cd /home/research/ns-allinone-3.28/ns-3.28
sudo ./waf configure
Configuration of Python Code

Execute Python Code

          At that moment, we have to implement the python code for the implementation of the below mentioned commands. Additionally, the results are also highlighted.

cd /home/research/ns-allinone-3.28/ns-3.28
sudo ./waf --pyrun scratch/PythonMain.py
Implementation of Python Code in Ns3

             To this end, we are ready to give suggestion on the stage where you face some difficulties and required assistance for your research.