Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

What Language Does Ns3 Use

             Most significantly, the user programs in network simulator 3 are written through both the C++ and python programming languages.

            So, let’s see the sample code for C++ in network simulator for your reference.

  • WiFi configurations
wifi.SetStandard(WIFI_STANDARD_80211n);
ssid = Ssid("ns380211n_5GHZ");
dataRate = "HtMcs0";
freq = 5170 + (bw / 2); // so as to have 5180/5190 for 20/40 dataStartTime = MicroSeconds(1000);
if (bw != 20 && bw != 40)
{
std::cout << "Bandwidth is not compatible with standard" << std::endl;
return 1;
}
  • Add commnadline paramters
CommandLine cmd(__FILE__);
cmd.AddValue("standard",
"OFDM-based Wi-Fi standard [11a, 11p_10MHZ, 11p_5MHZ, 11n_2_4GHZ, 11n_5GHZ, 11ac, "
"11ax_2_4GHZ, 11ax_5GHZ]", standard);
cmd.AddValue("bw", "Bandwidth (consistent with standard, in MHz)", bw);
cmd.AddValue("txPower", "Transmit power (dBm)", pow);
cmd.AddValue("verbose",
"Display log messages for
WifiSpectrumValueHelper and SpectrumWifiPhy", verbose);
cmd.Parse(argc, argv);
  • Include header files
#include "ns3/command-line.h"
#include "ns3/gnuplot.h"
#include "ns3/mobility-helper.h"
#include "ns3/spectrum-analyzer-helper.h"
#include "ns3/spectrum-channel.h"
#include "ns3/spectrum-helper.h"
#include "ns3/spectrum-wifi-helper.h"
#include "ns3/ssid.h"
#include "ns3/string.h"

             On the other hand, we have highlighted some sample codes based on Python in network simulator 3.

  • Ping6 application to send ICMPv6 echo request from n0 to n1
print("Application")
packetSize = 1024
maxPacketCount = 5
interPacketInterval = ns.Seconds(1.) ping6 = ns.Ping6Helper()
ping6.SetLocal(i1.GetAddress(0, 1))
ping6.SetRemote(i2.GetAddress(1, 1))
ping6.SetAttribute("MaxPackets",
ns.UintegerValue(maxPacketCount)) ping6.SetAttribute("Interval",
ns.TimeValue(interPacketInterval)) ping6.SetAttribute("PacketSize",
ns.UintegerValue(packetSize)) apps = ping6.Install(ns.NodeContainer(net1.Get(0)))
apps.Start(ns.Seconds(2.0))
apps.Stop(ns.Seconds(20.0))
  • Assign IPv6 addresses for all nodes
print("Addressing")
ipv6 = ns.Ipv6AddressHelper()
ipv6.SetBase(ns.Ipv6Address("2001:1::"), ns.Ipv6Prefix(64))
i1 = ipv6.Assign(d1)
i1.SetForwarding(1, True)
i1.SetDefaultRouteInAllNodes(1)
ipv6.SetBase(ns.Ipv6Address("2001:2::"),
ns.Ipv6Prefix(64))
i2 = ipv6.Assign(d2)
i2.SetForwarding(0, True)
i2.SetDefaultRouteInAllNodes(0)
  • Sample code for node creation
print("Create nodes")
all = ns.NodeContainer(3)
net1 = ns.NodeContainer()
net1.Add(all.Get(0))
net1.Add(all.Get(1))
net2 = ns.NodeContainer()
net2.Add(all.Get(1))
net2.Add(all.Get(2))

            The research scholars can reach us to clarify their doubts and to acquire the appropriate research knowledge.