Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Maharaja Surajmal Institute of Technology

Data Communication Network


Practical File

Submitted by – Sarthak Arora


Serial Number- 27
Submitted to – Dr. Anupama Kaushik
Branch – IT-1 Morning
INDEX
S. No. Experiment Name Page No. Date Remarks

SARTHAK ARORA,27 2
Experiment 1
AIM: Introduction to Discrete Event Simulation tools Ns2/s3, Omnet++ and installation of
Ns3.

(I) Ns(from network simulator) is a name for a series of discrete event network simulators,
specifically Ns-1, Ns-2, and Ns-3. All are discrete-event computer network simulators,
primarily used in research and teaching. The normal process of creating a simulation can be
divided into several steps:
1. Definition of Topology: To facilitate the construction of basic facilities and to explain
their relationship, ns-3 has a system of containers and assistants who run this process.
2. Model development: Models added to simulations (for example, UDP, IPv4, point-to-
point devices and links, applications); most of the time this is done using assistants. Node and
link configuration: models set their default values (for example, the size of the packets sent
by the application or the MTU point-to-point link); most of the time this is done using an
attribute system.
3. Execution: Simulation centers produce events, user-requested data is included.
4. Performance analysis: After the simulation is complete and the data is available as a
timed event tracker. This data can be mathematically analyzed with R-like tools to reach a
conclusion.
5. Image Visual: Raw or processed data collected in the simulation can be retrieved using
tools such as Gnuplot, matplotlib or XGRAPH.
(II) NS2 (Network Simulator 2):
NS2 is an open-source simulation tool running on Linux. It is a discrete event network-based
template and provides great support for route simulation, multiple streams and IP protocols
and protocols, such as UDP, TCP, RTP and SRM over wireless and wireless networks (local
and satellite). It has many advantages that make it a useful tool, such as repetition protocols
and the ability to describe in detail network traffic. Additionally, NS2 supports several
algorithms for routing and linearization of LAN routes and streaming is part of the
algorithms. Online algorithms include right line, robin deficit and FIFO. NS2 started as a
variant of the REAL network simulator in 1989 (see Resources). REAL is a network template
initially intended to study the dynamic flow behavior and congestion control schemes of the
flexible package data networks. NS2 is a tool that helps you better understand certain
methods in protocol definitions, such as overcrowding, hard to see in live testing. Provides
excellent documentation and support for various add-ons. We they recommend NS2 as a tool
to help understand how protocols work and interact with different network topology.
(III) NS3 (Network Simulator 3):
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 work and create,

SARTHAK ARORA,27 3
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.
(IV) Difference between NS3 and NS2: -
Table 1.1

SARTHAK ARORA,27 4
(V) Introduction to OMNet ++:
OMNeT ++ (Objective Modular Network Testbed in C ++) is a module-based library
module, based on the C ++ component and the framework, especially for building network
simulations. OMNeT ++ can be used free of charge for non-commercial use imitation as in
educational and teaching institutions. OMNEST is an extended version of OMNeT ++ for
commercial use. OMNeT ++ itself is a simulation framework without models for network
protocols such as IP or HTTP. Main computer network simulation models are available in a
few external frames. The most commonly used INET offers a variety of models for all types
of network protocols and technologies such as IPv6, BGP. INET and provides a set of motion
models to mimic the movement of the node in the simulation. INET models are licensed
under the LGPL or GPL. NED (Network Description) is a topology definition language for
OMNeT ++. Managing and reducing the time to make large simulations, additional tools
have been developed, so that for example, based on Python.
(VI) Ns3 and NetAnim Installation:
Operating System is Community Edition OS (CentOS)
Download ns-allinone-3.20.4.tar.bz2
● Execute the following commands in the terminal
1. tar -xvf 3.20.4.tar.bz2 : This instruction helps in extracting the folders from the zip file.
2. cd ns-allinone-3.20 : Move into the extracted folder
3. ./build.py
4. /waf configure-enable-tests
5. /waf-enable-examples
Copy the file first.cc from examples>tutorials into the scratch folder ensuring you delete all
previous files.
● To run the program execute the command- /waf-run scratch/first
(VII) 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

SARTHAK ARORA,27 5
Experiment 2
AIM: Write a Program to simulate point to point topology using Ns-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"

// Default Network Topology


// 10.1.1.0
// n0 -------------- n1
// point-to-point
using namespace ns3;

NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int main (intargc, char *argv[])
{
CommandLinecmd (__FILE__);
cmd.Parse (argc, argv);

Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);

NodeContainer nodes;
nodes.Create (2);

PointToPointHelperpointToPoint;
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);

SARTHAK ARORA,27 6
UdpEchoServerHelperechoServer (9);

ApplicationContainerserverApps = echoServer.Install (nodes.Get (1));


serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));

UdpEchoClientHelperechoClient (interfaces.GetAddress (1), 9);


echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

ApplicationContainerclientApps = echoClient.Install (nodes.Get (0));


clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
AnimationInterface anim("twoPoint.xml");
anim.SetConstantPosition(nodes.Get(0),1.5,2.4);
anim.SetConstantPosition(nodes.Get(1),3,3);

Simulator::Run ();
Simulator::Destroy ();
return 0;
}

Output:

Fig 2.1

SARTHAK ARORA,27 7
Fig 2.2

SARTHAK ARORA,27 8
Experiment 3
AIM: Write a Program to simulate three point topology using Ns-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"

using namespace ns3;

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;

SARTHAK ARORA,27 9
  address.SetBase ("10.1.1.0", "255.255.255.0");
 
  Ipv4AddressHelper address1;
  address1.SetBase ("10.5.1.0", "255.255.255.0");

  Ipv4InterfaceContainer interfaces = address.Assign(devices);


  Ipv4InterfaceContainer interfaces1 = address1.Assign(devices1);

  Ipv4GlobalRoutingHelper::PopulateRoutingTables();

  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));

    ApplicationContainer clientApps1 = echoClient.Install (nodes.Get(2));


  clientApps1.Start (Seconds(2.0));
  clientApps1.Stop (Seconds(10.0));

  AnimationInterface anim("threePoint.xml");
  anim.SetConstantPosition(nodes.Get(0),20,20);
  anim.SetConstantPosition(nodes.Get(1),40,60);
  anim.SetConstantPosition(nodes.Get(2),60,20);
  Simulator::Run ();
  Simulator::Destroy ();
  return 0;
}

SARTHAK ARORA,27 10
Output-

Fig 3.1

Fig 3.2

SARTHAK ARORA,27 11
Experiment 6
AIM – Simulate bus topology using NS3.
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/netanim-module.h"
#include "ns3/ipv4-global-routing-helper.h"

// Default Network Topology


//
// 10.1.1.0
// n0 -------------- n1 n2 n3 n4
// point-to-point | | | |
// ================
// LAN 10.1.2.0

using namespace ns3;

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);

SARTHAK ARORA,27 12
}

nCsma = nCsma == 0 ? 1 : nCsma;

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"));

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);

address.SetBase ("10.1.2.0", "255.255.255.0");


Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (csmaNodes.Get (nCsma));


serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));

SARTHAK ARORA,27 13
UdpEchoClientHelper echoClient (csmaInterfaces.GetAddress (nCsma), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));

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


clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
//static route is provided to network

pointToPoint.EnablePcapAll ("second"); //packet capture


csma.EnablePcap ("second", csmaDevices.Get (1), true);

AnimationInterface anim("secondscratch.xml");
anim.SetConstantPosition(p2pNodes.Get(0),10.0, 10.0);
anim.SetConstantPosition(csmaNodes.Get(0),20.0, 20.0);
anim.SetConstantPosition(csmaNodes.Get(1),30.0, 20.0);
anim.SetConstantPosition(csmaNodes.Get(2),40.0, 20.0);
anim.SetConstantPosition(csmaNodes.Get(3),50.0, 20.0);

Simulator::Run ();
Simulator::Destroy ();
return 0;
}

Output-

Fig 6.1

SARTHAK ARORA,27 14

You might also like