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

How To Implement Networking in NS3

Read some of the few steps that we have shared for Implement Networking in NS3, contact us for simulation in your work.

Step-by-Step Guide to Implement Networking in ns-3

Install ns-3:

    • Download ns-3 which is available in the official website: ns-3
    • Extract the file which was downloaded.
    • Install necessary dependencies (you can refer to the ns-3 tutorial for specific commands for your OS).
    • Compile ns-3 :

 ./build.py

            Create a Simple Simulation Script:

  • Create a new script file, e.g., simple-network.cc.

Include Necessary Headers:

                        #include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

Set Up the Network Topology:

  • Define the main function and set up the logging:

int main (int argc, char *argv[])

{

  LogComponentEnable (“UdpEchoClientApplication”, LOG_LEVEL_INFO);

  LogComponentEnable (“UdpEchoServerApplication”, LOG_LEVEL_INFO);

Create nodes:

NodeContainer nodes;

nodes.Create (2);

Set up the point-to-point link:

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

NetDeviceContainer devices;

devices = pointToPoint.Install (nodes);

Install the Internet stack:

InternetStackHelper stack;

stack.Install (nodes);

Assign IP addresses:

Ipv4AddressHelper address;

address.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign (devices);

            Install Applications:

  • Set up a UDP echo server on one node:

UdpEchoServerHelper echoServer (9);

 

ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

Set up a UDP echo client on the other node:

UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);

echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

            Run the Simulation:

  • Define the simulation stop time and start the simulator:

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

            Compile and Run the Script:

  • Save the script and compile, then run the script.

./waf build

./waf –run simple-network

Example Script (simple-network.cc):

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main (int argc, char *argv[])

{

  LogComponentEnable (“UdpEchoClientApplication”, LOG_LEVEL_INFO);

  LogComponentEnable (“UdpEchoServerApplication”, LOG_LEVEL_INFO);

  NodeContainer nodes;

  nodes.Create (2);

  PointToPointHelper pointToPoint;

  pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

  pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

  NetDeviceContainer devices;

  devices = pointToPoint.Install (nodes);

  InternetStackHelper stack;

  stack.Install (nodes);

  Ipv4AddressHelper address;

  address.SetBase (“10.1.1.0”, “255.255.255.0”);

  Ipv4InterfaceContainer interfaces = address.Assign (devices);

  UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));

  serverApps.Start (Seconds (1.0));

  serverApps.Stop (Seconds (10.0));

 

  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);

  echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));

  echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

  echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));

  clientApps.Start (Seconds (2.0));

  clientApps.Stop (Seconds (10.0));

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main (int argc, char *argv[])

{

  LogComponentEnable (“UdpEchoClientApplication”, LOG_LEVEL_INFO);

  LogComponentEnable (“UdpEchoServerApplication”, LOG_LEVEL_INFO);

 

  NodeContainer nodes;

  nodes.Create (2);

  PointToPointHelper pointToPoint;

  pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

  pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

  NetDeviceContainer devices;

  devices = pointToPoint.Install (nodes);

  InternetStackHelper stack;

  stack.Install (nodes);

  Ipv4AddressHelper address;

  address.SetBase (“10.1.1.0”, “255.255.255.0”);

  Ipv4InterfaceContainer interfaces = address.Assign (devices);

  UdpEchoServerHelper echoServer (9);

  ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));

  serverApps.Start (Seconds (1.0));

  serverApps.Stop (Seconds (10.0));

  UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);

  echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));

  echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

  echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

  ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));

  clientApps.Start (Seconds (2.0));

  clientApps.Stop (Seconds (10.0));

 

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

We follow all the necessary Step-by-Step Guide to Implement Networking in ns-3 in the above way for effective installation,  stay in touch with us for best coding and implementation support.