Experiment 1 AIM: Introduction To Discrete Event Simulation Tools Ns2/s3, Omnet++ and Installation of Ns3
Experiment 1 AIM: Introduction To Discrete Event Simulation Tools Ns2/s3, Omnet++ and Installation of Ns3
Om Dwivedi 1
(III) NS3 (Network Simulator 3): -
ns-3 is a discrete-event network simulator for Internet systems, targeted primarily for research
and educational use. ns-3 is free, open-source software, licensed under the GNU GPLv2
license, and maintained by a worldwide community.
Ns3 is designed to provide open, scalable network simulation platform, network research and
education. In short, ns-3 provides examples of how packet data networks workand create, and
provide a simulation engine for users to perform simulation tests. Some of the reasons for this
use ns-3 covers to do the most difficult or impossible lessons to do with real programs, learning
program behave in a highly controlled environment, capable of reproducing, and learning how
networks work. Users will see that the available model set in ns-3 focuses on comparing how
Internet protocols and networks work, but ns-3 is not limited in online systems; few users use
ns-3 to create non-internet systems.
Many simulation tools are available for network simulation research. Below are a few
distinguishing features of ns-3 in contrast in other tools.
· NS-3 is designed as a collection of libraries that can be integrated with other external software
libraries. While some simulations provide users with a single, integrated user interface area
where all operations are performed, ns-3 is modular above this. Several external animators and
data analysis tools and visual tools can be used with ns-3. However, users should expect work
on command line and C ++ and / or Python software development tools.
· NS-3 is mainly used for Linux or macOS programs, although BSD support is available
· Windows systems and frameworks that can generate Linux code, such as Windows
Subsystem for Linux, or Cygwin. Native Windows Visual Studio is not currently supported
even though the engineer is working in future support. Windows users can use the Linux virtual
machine.
· NS-3 is not a software product officially supported by any company. Ns3 support is best done
at the ns-3 user forum
Ns-3 is built using C++ and Python with scripting capability. The ns library is wrapped by
Python thanks to the pybindgen library which delegates the parsing of the ns C++ headers to
castxml and pygccxml to automatically generate the corresponding C++ binding glue. These
automatically generated C++ files are finally compiled into the ns Python module to allow
users to interact with the C++ ns models and core through Python scripts. The ns simulator
features an integrated attribute-based system to manage default and per-instance values for
simulation parameters.
When network cards are enabled in the devices, we add different parameters in the channels
(i.e., real world path used to send data) which are data-rate, packet size, etc. Now we use
Application to generate traffic and send the packets using these applications.
Om Dwivedi 2
(IV) Difference between NS3 and NS2: -
Om Dwivedi 3
(VI) Difference between Emulator and Simulator: -
Om Dwivedi 4
(VIII) Installing NetAnim Animation Simulator
Execute the following commands in the terminal
yum install qt4-devel
cd netanim-3.105
make clean
qmake-qt4 NetAnim.pro
make
./NetAnim
Node Container
!!!Net Device Container
!!!Ipv4 Interface
Container !!!Application
Container
Helper Classes
!!!Point to Point
Helper !!!Internet
Stack Helper !!!Ipv4
Address Helper
Om Dwivedi 5
(X) Topology in Ns3
Om Dwivedi 6
EXPERIMENT 2
CODE:
#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"
#include "ns3/netanim-module.h"
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[]) {
Time::SetResolution (Time::NS);
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;
Om Dwivedi 7
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
Om Dwivedi 8
Fig 2.2 Terminal Output-2
Om Dwivedi 9
EXPERIMENT 3
CODE:
#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"
#include "ns3/netanim-module.h"
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse(argc, argv);
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create(3);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes.Get(0),nodes.Get(1));
NetDeviceContainer devices1;
devices1 = pointToPoint.Install (nodes.Get(2),nodes.Get(1));
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4AddressHelper address1;
address1.SetBase ("10.5.1.0", "255.255.255.0");
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
Om Dwivedi 10
UdpEchoServerHelper echoServer(9);
AnimationInterface anim("threePoint.xml");
anim.SetConstantPosition(nodes.Get(0),5,10);
anim.SetConstantPosition(nodes.Get(1),10,25);
anim.SetConstantPosition(nodes.Get(2),15,25);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
Om Dwivedi 11
Fig 3.2 NetAnim Graphical Simulation Output
Om Dwivedi 12
EXPERIMENT 4
CODE:
#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"
#include "ns3/netanim-module.h"
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[]) {
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (4);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes.Get(0),nodes.Get(1));
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign (devices);
PointToPointHelper pointToPoint1;
pointToPoint1.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint1.SetChannelAttribute ("Delay", StringValue ("2ms")); devices
= pointToPoint1.Install (nodes.Get(1),nodes.Get(2)); address.SetBase
("10.1.2.0", "255.255.255.0");
interfaces = address.Assign (devices);
PointToPointHelper pointToPoint2;
pointToPoint2.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint2.SetChannelAttribute ("Delay", StringValue ("2ms")); devices
= pointToPoint2.Install (nodes.Get(2),nodes.Get(3)); address.SetBase
("10.1.3.0", "255.255.255.0");
interfaces = address.Assign (devices);
Om Dwivedi 13
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
AnimationInterface anim("anim33.xml");
anim.SetConstantPosition(nodes.Get(0),1,2);
anim.SetConstantPosition(nodes.Get(1),15,15);
anim.SetConstantPosition(nodes.Get(2),10,30);
anim.SetConstantPosition(nodes.Get(3),50,15);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
Om Dwivedi 14
Fig 4.2 NetAnim Graphical Simulation Output
Om Dwivedi 15
EXPERIMENT 5
CODE:
#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"
#include "ns3/netanim-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[]) {
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (5);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes.Get(0),nodes.Get(1));
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
PointToPointHelper pointToPoint2;
pointToPoint2.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint2.SetChannelAttribute ("Delay", StringValue ("2ms")); devices
= pointToPoint2.Install (nodes.Get(2),nodes.Get(3)); address.SetBase
("10.1.3.0", "255.255.255.0");
interfaces = address.Assign (devices);
PointToPointHelper pointToPoint3;
pointToPoint3.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
Om Dwivedi 16
pointToPoint3.SetChannelAttribute ("Delay", StringValue ("2ms"));
devices = pointToPoint3.Install (nodes.Get(3),nodes.Get(4));
address.SetBase ("10.1.4.0", "255.255.255.0");
interfaces = address.Assign (devices);
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (4));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
AnimationInterface anim("anim33.xml");
anim.SetConstantPosition(nodes.Get(0),1,2);
anim.SetConstantPosition(nodes.Get(1),15,15);
anim.SetConstantPosition(nodes.Get(2),10,30);
anim.SetConstantPosition(nodes.Get(3),50,15);
anim.SetConstantPosition(nodes.Get(4),60,0);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
Om Dwivedi 17
Fig 5.2 NetAnim Graphical Simulation Output
Om Dwivedi 18
EXPERIMENT 6
CODE:
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h" #include
"ns3/ipv4-global-routing-helper.h" #include
"ns3/netanim-module.h"
// Default Network
Topology //
// 10.1.1.0
// n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN 10.1.2.0
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
int
main (int argc, char *argv[]) {
bool verbose = true;
uint32_t nCsma = 3;
CommandLine cmd;
cmd.AddValue ("nCsma", "Number of \"extra\" CSMA nodes/devices",
nCsma);
cmd.AddValue ("verbose", "Tell echo applications to log if true",
verbose);
cmd.Parse (argc,argv);
if (verbose)
{
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
}
NodeContainer p2pNodes;
p2pNodes.Create (2);
NodeContainer csmaNodes;
csmaNodes.Add (p2pNodes.Get (1));
Om Dwivedi 19
csmaNodes.Create (nCsma);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer p2pDevices;
p2pDevices = pointToPoint.Install (p2pNodes);
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
NetDeviceContainer csmaDevices;
csmaDevices = csma.Install (csmaNodes);
InternetStackHelper stack;
stack.Install (p2pNodes.Get (0));
stack.Install (csmaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
pointToPoint.EnablePcapAll ("second");
csma.EnablePcap ("second", csmaDevices.Get (1), true);
AnimationInterface anim("second2.xml");
anim.SetConstantPosition(p2pNodes.Get(0),0.0,0.0);
anim.SetConstantPosition(p2pNodes.Get(1),10.0,20.0);
anim.SetConstantPosition(csmaNodes.Get(1),20.0,30.0);
anim.SetConstantPosition(csmaNodes.Get(2),30.0,40.0);
anim.SetConstantPosition(csmaNodes.Get(3),40.0,50.0);
Om Dwivedi 20
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
Om Dwivedi 21
Fig 6.2 NetAnim Graphical Simulation Output
Om Dwivedi 22