Nitte Meenakshi Institute of Technology: Bachelor of Engineering in Computer Science and Engineering
Nitte Meenakshi Institute of Technology: Bachelor of Engineering in Computer Science and Engineering
Nitte Meenakshi Institute of Technology: Bachelor of Engineering in Computer Science and Engineering
(AN AUTONOMOUS INSTITUTION, AFFILIATED TO VISVESVARAYA TECHNOLOGICAL UNIVERSITY, BELGAUM, APPROVED BY AICTE
& GOVT.OF KARNATAKA)
COURSE-IMPLEMENTATION REPORT
on
“NS-3 SIMULATION”
Submitted in partial fulfilment of the requirement for the award of Degree of
Bachelor of Engineering in
Computer Science and Engineering
Submitted by:
MEGHANA M 1NT15CS093
NEHARIKA K 1NT15CS100
TABLE OF CONTENTS
Page 1
ns-3 SIMULATION
INTRODUCTION TO ns-3
ns-3 has been developed to provide an open, extensible network simulation platform,
for networking research and education. In brief, ns-3 provides models of how packet data
networks work and perform, and provides a simulation engine for users to conduct simulation
experiments. Some of the reasons to use ns-3 include to perform studies that are more difficult or
not possible to perform with real systems, to study system behaviour in a highly controlled,
reproducible environment, and to learn about how networks work. Users will note that the
available model set in ns-3 focuses on modelling how Internet protocols and networks work, but
ns-3 is not limited to Internet systems; several users are using ns-3 to model non-Internet-based
systems.
Many simulation tools exist for network simulation studies. Below are a few distinguishing
features of ns-3 in contrast to other tools.
• ns-3 is designed as a set of libraries that can be combined together and also with other
external software libraries. While some simulation platforms provide users with a single,
integrated graphical user interface environment in which all tasks are carried out, ns-3 is
more modular in this regard. Several external animators and data analysis and
visualization tools can be used with ns-3. However, users should expect to work at the
command line and with C++ and/or Python software development tools.
• ns-3 is primarily used on Linux systems, although support exists for FreeBSD, Cygwin
(for Windows), and native Windows Visual Studio support is in the process of being
developed.
Page 2
ns-3 SIMULATION
Page 3
ns-3 SIMULATION
ns-2 ns-3
Page 4
ns-3 SIMULATION
1. The total computation time required 1. NS-3 performs better than ns-2 in
to run a simulation scales better in ns-3 terms of memory management.
Performance than ns-2. 2. The aggregation system prevents
2. This is due to the removal of the unneeded parameters from being
overhead associated with stored, and packets don't contain
interfacing oTcl with C++,and the unused reserved header space.
overhead associated with the oTcl
interpreter.
Simulation Output NAM(Network Animator),it's a Tcl PyViz, which is a python based real-
based animation system that time visualization package
produces a visual representation of
the network described.
Page 5
ns-3 SIMULATION
EXPLANATION OF TERMS
Node
Because in any network simulation, we will need nodes. So ns-3 comes with NodeContainer that
you can use to manage all the nodes (Add, Create, Iterate, etc.).
In the real world, they correspond to network cables (or wireless media) and peripheral cards
(NIC). Typically these two things are intimately tied together. In the first example, we are
Using PointToPointHelper that wraps the Channel and NetDevice.
Then we need to install the devices. The internal of Install is actually more complicated, but for
now, let’s just skip the magic behind the scene.
Page 6
ns-3 SIMULATION
Protocols
Internet and IPv4. Since Internet is the current largest network to study, ns-3 has a particular focus
on it. The InternetStackHelper will install an Internet Stack (TCP, UDP, IP, etc.) on each of the
nodes in the node container.
To assign IP addresses, use a helper and set the base. The low level ns-3 system actually
remembers all of the IP addresses allocated and will generate a fatal error if you accidentally cause
the same address to be generated twice.
// Since IP Address assignment is so common, the helper does the dirty work!
// You only need to set the base.
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Applications
Every application needs to have Start and Stop function so that the simulator knows how to
schedule it. Other functions are application-specific. We will use UdpEchoServer and
UdpEchoClientfor now.
Page 7
ns-3 SIMULATION
// 2, Client:
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));
Simulation
// Start Simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
Page 8
ns-3 SIMULATION
SOURCE 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"
NS_LOG_COMPONENT_DEFINE ("SecondScriptExample");
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));
csmaNodes.Create (nCsma);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
Page 9
ns-3 SIMULATION
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);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Page 10
ns-3 SIMULATION
INFERENCE:
Page 11
ns-3 SIMULATION
Page 12