Uploaded by ruchir bisht

COMPUTER NETWORKS LAB ETCS-354

advertisement
05914802717
RUCHIR BISHT
6-C4
COMPUTER NETWORKS LAB
ETCS-354
Faculty Name: Dr. Pooja Gupta
Student Name: RUCHIR BISHT
Roll No.
: 05914802717
Semester
: 6th
Maharaja Agrasen Institute of Technology, PSP Area,
Sector – 22, Rohini, New Delhi – 110086
1|Page
05914802717
RUCHIR BISHT
6-C4
LIST OF EXPERIMENTS
(As prescribed by G.G.S.I.P.U)
1. Introduction to Computer Network laboratory, introduction to Discrete
Event Simulation and Discrete Event Simulation Tools
2. Introduction to NS3 and its comparison with NS2.
3. Install NS3 on Linux.
4. Using Free Open Source Software tools for network simulation – I
Preliminary usage of the tool ns3. Simulate a source node and a sink
node.
5. Using Free Open Source Software tools ns3, design and implement two
nodes topology.
6. Using Free Open Source Software tools ns3, design and implement three
nodes topology considering one node as a central node.
7. Using Free Open Source Software tools ns3, design and Implement star
topology using StarHelperClass.
8. Using Free Open Source Software tools ns3, design and implement a bus
topology using CSMA.
9. Using Free Open Source Software tools ns3, design and implement
hybrid topology connecting multiple routers and nodes.
10.Install and configure NetAnim.
2|Page
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT-1
3|Page
05914802717
RUCHIR BISHT
6-C4
4|Page
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT-2
5|Page
05914802717
RUCHIR BISHT
6-C4
6|Page
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT-3
AIM: Install NS3 on Linux
Description:
Following are the basic steps which must be followed for installing NS3
1.
2.
3.
4.
Install prerequisite packages
Download ns3 codes
Build ns3
Validate ns3
Prerequisite packages for Linux are as follows:
1.
2.
3.
4.
5.
6.
7.
Minimal requirements for Python: gcc g++ python
Debugging and GNU Scientific Library (GSL) support: gdbpythondev,valgrind gsl-bin,libgsl0-dev,libgsl0ldbl, Network Simulation
Cradle (nsc): flex,bison
Reading pcap packet traces: tcpdump
Database support for statistics framework: sqlite,sqlite3
XML-based version of the config store: libxml2
A GTK-based configuration system: libgtk2.0-0
Experimental with virtual machines and ns-3: vtun,lxc
Detail steps are as follows:
1. 1.$sudo apt-get update / dnf update
2. 2.$sudo apt-get upgrade / dnf upgrade
3. 3.Once ubuntu/fedora is installed run following command opening the
terminal(ctrl+alt+T) window.
4. 4.To install prerequisites dependency packages- Type the following
command in terminal window.
5. 5.$sudo apt-get/ dnf install gcc g++ python python-dev mercurial bzr gdb
valgrind gsl-bin libgsl0-dev libgsl0ldbl flex bison tcpdump sqlite sqlite3
7|Page
05914802717
RUCHIR BISHT
6-C4
libsqlite3-dev libxml2 libxml2- dev libgtk2.0-0 libgtk2.0-dev uncrustify
doxygen graphviz imagemagick texlive texlive-
6. latex-extra texlive-generic-extra texlive-generic-recommended texinfo dia
texlive
texlivelatex-extra
texlive-extra-utils
texlive-genericrecommended texi2html python-pygraphviz python-kiwi pythonpygoocanvas libgoocanvas-dev python-pygccxml
7. 6.After downloading NS3 on the drive, extract all the files in the NS3
folder, which you have created.
8. 7.Then you can find build.py along with other files in NS3 folder. Then to
build the examples in ns-3 run :
9. $./build.py --enable-examples –enable-tests
10.If the build is successful then it will give output "Build finished
successfully".
11.8.Now run the following command on the terminal window to configure
with waf (build tool)
12.$./waf -d debug --enable-examples --enable-tests configure To build with
waf (optional)
13.$./waf
14.9.To test everything all right run the following command on the terminal
window,
15.$./test.py
16.If the tests are ok the installation is done
17.10.Now after installing ns3 and testing it run some programs first to be ns3
user: make sure you are in directory where waf script is available then run
8|Page
05914802717
RUCHIR BISHT
6-C4
VIVA Questions
Q1 What protocols does ns support?
A lot! Almost all variants of TCP, several forms of multicast, wired networking,
several ad hoc routing protocols and propagation models (but not cellular
phones), data diffusion, satellite, and other stuff.
Q2. How should one can start doing something (like implementing a new
protocol or trying an experiment)?
Give a concise overview of the project. Describe the purpose of the study,
including problem to be investigated and hypothesis(es) to be tested, the
population, and the methods that will be used. Avoid the use of acronyms. Include
the expected benefit of the study.
Q3. What is waf and its importance in the simulation process?
A Web application firewall (WAF) or application-layer firewall is an appliance
or software designed to protect web applications against attacks and data leakage.
WAFs prevent threats when it is inconvenient to modify code. They also provide
an important feedback loop to developers as part of the overall SDLC process.
Q4. How we can test that NS3 has been installed properly?
You can run the unit tests of the ns-3 distribution by running the “./test.py -c
core” script,
./test.py -c core
These tests are run in parallel by waf. You should eventually see a report saying
that,
47 of 47 tests passed (47 passed, 0 failed, 0 crashed, 0 valgrind errors)
Q5. Why prerequisite packages are needed before the installation of NS3?
The core of ns-3 requires a gcc/g++ installation of 4.9 or greater (Linux), or a
recent version of clang compiler (OS X, Linux, or BSD), and Python 2.7 or
greater.
9|Page
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT-4
AIM: Using Free Open Source Software tools for network simulation – I
Preliminary usage of the tool ns3. Simulate a source node and a sink node.
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"
using namespace ns3;
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 (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
10 | P a g e
05914802717
RUCHIR BISHT
6-C4
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 (2048));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
11 | P a g e
05914802717
RUCHIR BISHT
6-C4
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
1. Data Rate = 5MBPS
2. Package Size: 2048 bytes
3. Port Number = 9
12 | P a g e
05914802717
RUCHIR BISHT
6-C4
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"
using namespace ns3;
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 (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes)
13 | P a g e
05914802717
RUCHIR BISHT
6-C4
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign (devices);
//Server
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
// Client
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (2048));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
14 | P a g e
05914802717
RUCHIR BISHT
6-C4
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
1.
2.
3.
4.
Data Rate = 5MBPS
Package Size: 2048 bytes
Port Number = 9
Using LOG_LEVEL_INFO which Log informational messages about
program progress
15 | P a g e
05914802717
RUCHIR BISHT
6-C4
VIVA Questions
Q1. What is Discrete Event Simulation?
Discrete event simulation (DES) is the process of codifying the behavior of a
complex system as an ordered sequence of well-defined events.
Q2. What is the importance and limitations of simulation?
Advantages




Conditions can be varied and outcomes investigated.
Critical situations can be investigated without risk.
It is cost effective.
Simulations can be sped up so behaviour can be studied easily over a long
period of time.
 Simulations can be slowed down to study behaviour more closely.
Disadvantages
 It can be expensive to measure how one thing affects another, to take the
initial measurements and to create the model itself (such as aerodynamic
wind tunnels).
 To simulate something, a thorough understanding is needed and an
awareness of all the factors involved. Without this, a simulation cannot be
created.
Q3. What is the relationship between state, system and an event?
SYSTEM: A collection of entities that interact together over time to accomplish
goals.
MODEL: An abstract representation of a system, usually containing structural
logical or mathematical relationship.
STATE: A collection of variables that contains all the information necessary to
describe the system at any time.
16 | P a g e
05914802717
RUCHIR BISHT
6-C4
Q4. What is the difference between deterministic and stochastic model?
Q5. What is proof of correctness? Why mathematical models are more
reliable than simulations?
A proof of correctness is a mathematical proof that a computer program or a part
thereof will, when executed, yield correct results, i.e. results fulfilling specific
requirements.
Mathematical Models exactly represent the real problem situations. Models help
managers to take decisions faster and more accurately. They typically offer
convenience and cost advantages over other means of obtaining the required
information on reality.
17 | P a g e
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT-5
AIM: Using Free Open Source Software tools ns3, design and implement two
nodes topology.
DESCRIPTION:
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"
18 | P a g e
05914802717
RUCHIR BISHT
6-C4
using namespace ns3;
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
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);
//Server
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
19 | P a g e
05914802717
RUCHIR BISHT
6-C4
serverApps.Stop (Seconds (10.0));
// 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));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
20 | P a g e
05914802717
RUCHIR BISHT
6-C4
VIVA questions:
Q1 which probable protocols can come into play when 2 nodes are
connected?
Aloha, csma, csma /cd
Q2. What is the difference between UDP and TCP?
Q3. What is a Point to Point Connection? What are its characteristics
A Point to Point Connection is a private data connection securely connecting two
or more locations for private data services.
Characteristics of Point to Point Protocol
 As mentioned in the beginning, PPP resides at the layer two of the OSI
model.
 This protocol supports other essentials such as authentication, error
detection, link quality monitoring, load balancing, compression, etc.
Q4. What will happen if the client starts first then the server?
If there is no server running, there is nothing for it to connect to hence client
would be in idle state.
21 | P a g e
05914802717
RUCHIR BISHT
6-C4
Q5. What is the difference between IPv4 and IPv6?
22 | P a g e
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT-6
AIM: Using Free Open Source Software tools ns3, design and implement three
nodes topology considering one node as a central node.
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"
using namespace ns3;
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (3);
23 | P a g e
05914802717
RUCHIR BISHT
6-C4
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);
//Server
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
// 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));
24 | P a g e
05914802717
RUCHIR BISHT
6-C4
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
OUTPUT:
25 | P a g e
05914802717
RUCHIR BISHT
6-C4
VIVA questions:
Q1. What if all the 3 nodes are the part of the same network and each
interface is assigned the IP address of the same range?
They will form a LAN.
Q2. What is the port number? What is its significance?
A port number is a way to identify a specific process to which an Internet or other
network message is to be forwarded when it arrives at a server.
 The simplest explanation is that ports identify what process on the host the
received traffic should be sent to.
 A computer can have multiple simultaneous connections, all receiving data
for different processes (mail, web, database, etc) on that computer.
 When the computer receives data, the port information allows it to give the
data to the correct process.
For example, data with port 80 should go to the http process. Data with port 25
should go to the mail process, and so on.
Q3. What is socket address? What is the role of IP address in it?
Socket address is the combinations of IP address and port number
Process to process delivery (transport layer communication) needs two
identifiers, one is IP address and the other is port number at each end to make a
connection.
Q4. How a NS3 program is simulated? Explain various stages.
26 | P a g e
05914802717
RUCHIR BISHT
6-C4
Q5. What is the difference between IP address and physical address?
27 | P a g e
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT 7
AIM: Using Free Open Source Software tools ns3, design and Implement star
topology using StarHelperClass.
Steps:
Step 1: Define the No of spokes (No of nodes connecting in Star Topology)
uint32_t nSpokes = 8;
Step 2: Set the attributes of one Point to Point link
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
PointToPointStarHelper star (nSpokes, pointToPoint);
Step 3 : Install the Internet stack on nodes
NS_LOG_INFO ("Install internet stack on all nodes.");
InternetStackHelper internet; star.InstallStack (internet);
Step 4: Assign the IP addresses using a helper and set the base.
28 | P a g e
05914802717
RUCHIR BISHT
6-C4
NS_LOG_INFO ("Assign IP Addresses.");
star.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"))
Step5: Create a packet sink on the star "hub" to receive packets using Packet
Sink Helper Class uint16_t port = 50000;
Address hubLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory",
hubLocalAddress); ApplicationContainer hubApp = packetSinkHelper.Install
(star.GetHub ()); hubApp.Start (Seconds (1.0));
hubApp.Stop (Seconds (10.0));
Step 6: Create On Off applications to send TCP to the hub, one on each spoke
node using OnOff Helper class
OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
onOffHelper.SetAttribute ("OnTime", StringValue
("ns3::ConstantRandomVariable[Constant=1]")); onOffHelper.SetAttribute
("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
Step7: Turn on global static routing so that nodes data can actually be routed
across the star.
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
NS_LOG_INFO ("Enable pcap tracing.");
Step 8: Enable pcap tracing on all point-to-point devices on all nodes by
EnablePcapAll feature. pointToPoint.EnablePcapAll ("star");
Step 9: Finally run the simulation and destroy in order to release the resources.
NS_LOG_INFO ("Run Simulation."); Simulator::Run (); Simulator::Destroy ();
NS_LOG_INFO ("Done.");
29 | P a g e
05914802717
RUCHIR BISHT
6-C4
OUTPUT:
VIVA questions:
Q1 What is network topology?
Network topology is the way a network is arranged, including the physical or
logical description of how links and nodes are set up to relate to each other.
Q2. What is the difference between Star and Bus topology?
Q3. What is role of socket address in networking?
A socket is one endpoint of a two-way communication link between two
programs running on the network. A socket is bound to a port number so that the
TCP layer can identify the application that data is destined to be sent to. An
endpoint is a combination of an IP address and a port number.
30 | P a g e
05914802717
RUCHIR BISHT
6-C4
Q4. Why server is started before the client in a NS3 program?
Server has to be started first since thereafter only the connections with the
clients/other servers can be possible.
Q5. What is the role of command line arguments in a NS3 program?
They are parameters/arguments supplied to the program when it is invoked. They
are used to control program from outside instead of hard coding those values
inside the code.
31 | P a g e
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT 8
AIM: Using Free Open Source Software tools ns3, design and implement a bus
topology using CSMA.
: Bus Topology (using CSMA)
STEPS:
Step 1: Define the No of connecting in CSMA
uint32_t nCsma = 3;
Step 2: Set the attributes of one Point to Point link
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
Step 3: Declare one NetDevice Container.
NetDeviceContainer p2pDevices;
Step 4: Install the Point to Point link on Devices (Nodes).
p2pDevices = pointToPoint.Install (p2pNodes);
32 | P a g e
05914802717
RUCHIR BISHT
6-C4
Step 5: Set CSMA channel attributes and install on nodes
CsmaHelper csma;
csma.SetChannelAttribute ("DataRate", StringValue ("100Mbps"));
csma.SetChannelAttribute ("Delay", TimeValue (NanoSeconds (6560)));
csmaDevices = csma.Install (csmaNodes);
Step 6 : Install the Internet stack on nodes stack.Install (p2pNodes.Get (0));
stack.Install (csmaNodes);
Step 7: Assign the IP addresses using a helper and set the base. p2pInterfaces =
address.Assign (p2pDevices); address.SetBase ("10.1.2.0", "255.255.255.0");
Ipv4InterfaceContainer csmaInterfaces;
csmaInterfaces = address.Assign (csmaDevices);
Step8: Set the applications using UDP Echo Server and UDP Echo Client
applications. Install the
server application on one node and set the Port No. for accessing the services.
Install the client applications on two nodes; set the communication attributes in
terms of Packet Size and Interval while client is communicating with server
with the defined port no.
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));
Step9: Turn on global static routing so that nodes data can actually be routed
across the star.
33 | P a g e
05914802717
RUCHIR BISHT
6-C4
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Step 10: Enable pcap tracing on all point-to-point devices on all nodes by
EnablePcapAll feature. pointToPoint.EnablePcapAll ("second");
csma.EnablePcap ("second", csmaDevices.Get (1), true);
Step 11: Finally run the simulation and destroy in order to release the resources.
Simulator::Run (); Simulator::Destroy ();
OUTPUT:
VIVA questions:
Q1 What is the difference between CSMA/CA and CSMA/CD protocol?
34 | P a g e
05914802717
RUCHIR BISHT
6-C4
Q2 Explain the flowchart of CSMA protocol?
Throughput and Efficiency – The throughput of CSMA/CD is much greater than
pure or slotted ALOHA.
For 1-persistent method throughput is 50% when G=1.
For non-persistent method throughput can go upto 90%.
Q3. Explain the persistence strategy and the types of persistence strategies?
 "Nonpersistent: If the medium is idle, transmit; if the medium is busy, wait
an amount of time drawn from a probability distribution and then check the
medium.
 1-persistent: If the medium is idle, transmit; if the medium is busy continue
to listen until the channel is sensed idle; then transmit immediately.
35 | P a g e
05914802717
RUCHIR BISHT
6-C4
 p-persistent: If the medium is idle, transmit with probability p, and delay
one-time unit with probability (1 – p); if the medium is busy, continue to
listen until the channel is idle and repeat. "
Q4. Which persistence strategy is the best and why?
0.01 - persistent strategy, due to maximum throughput.
Q5. What is the difference between Star and Bus topology?
36 | P a g e
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT-9
AIM: Using Free Open Source Software tools ns3, design and implement
hybrid topology connecting multiple routers and nodes.
STEPS
Step 1: Create nodes that include Host, Four Routers and Host1.
NodeContainer host, router, host1; host.Create (2);
router.Create (4);
Step2: Set subnets and assign host to each subnet.
NodeContainer subnet1; subnet1.Add (host.Get (0));
subnet1.Add (router.Get (0));
Step 3: Set the attributes of one Point to Point link.
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
Step 4: Declare one NetDevice Container.
NetDeviceContainer subnet1Devices; subnet1Devices = pointToPoint.Install
(subnet1);
37 | P a g e
05914802717
RUCHIR BISHT
6-C4
Step 5: Install the Point to Point link on Devices (Nodes).
subnet1Devices = pointToPoint.Install (subnet1);
Step 6: Install the Internet stack on nodes.
InternetStackHelper stack; stack.Install (router); stack.Install (host);
Step7: Assign the IP addresses using a helper and set the base.
Ipv4AddressHelper address1, address2, address3, address4, address5, address6,;
Address1.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer subnet1Interfaces;
subnet1Interfaces = address1.Assign (subnet1Devices);
Step8: Set the applications using UDP Echo Server and UDP Echo Client
applications.
UdpEchoServerHelper echoServer (9);
UdpEchoClientHelper echoClient (subnet5Interfaces.GetAddress (1), 9);
Step 9: Install the server application on node and set the Port No. for accessing
the services.
ApplicationContainer serverApps = echoServer.Install (subnet5.Get (1));
Step 10: Install the client applications on two nodes; set the communication
attributes in terms of
Packet Size and Interval while client is communicating with server with the
defined port no.
echoClient.SetAttribute ("MaxPackets", UintegerValue (3));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (subnet1.Get (0));
38 | P a g e
05914802717
RUCHIR BISHT
6-C4
Step 11: As for simulations each application is required to Start and Stop after a
time interval; Start and Stop the Ser4ver and the Clients.
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
clientApps.Start (Seconds (1.0));
clientApps.Stop (Seconds (10.0));
Step12: Turn on global static routing to populate the routing tables.
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Step 13: Finally run the simulation and destroy in order to release the resources.
Simulator::Run (); Simulator::Destroy ();
OUTPUT
39 | P a g e
05914802717
RUCHIR BISHT
6-C4
VIVA Questions
Q1 What is the difference between amplifier and repeater?
Q2 What is hub and how it is different from router?
Typically, passive hubs are connected to other devices in a star configuration.
Hub is a passive device without software while router is a networking device, and
data transmission form in hub is in electrical signal or bits while in router it is in
form of packet.
Q3. What is the role of animation in NS3 simulator?
Animation in NS3 simulator (NetAnim) uses a trace file generated during an ns-3
simulation to display the topology and animate the packet flow between nodes.
Q4. Explain difference between TCP/IP protocol suite and OSI model?
OSI(Open System
Interconnection)
TCP/IP(Transmission Control Protocol
/ Internet Protocol)
1. OSI is a generic, protocol
independent standard, acting
as a communication gateway
between the network and end
user.
1. TCP/IP model is based on standard
protocols around which the Internet has
developed. It is a communication
protocol, which allows connection of
hosts over a network.
40 | P a g e
05914802717
RUCHIR BISHT
6-C4
2. In OSI model the transport
layer guarantees the delivery
of packets.
2. In TCP/IP model the transport layer
does not guarantees delivery of packets.
Still the TCP/IP model is more reliable.
3. Follows vertical approach.
3. Follows horizontal approach.
4. OSI model has a separate
Presentation layer and Session
layer.
4. TCP/IP does not have a separate
Presentation layer or Session layer.
5. Transport Layer is
Connection Oriented.
5. Transport Layer is both Connection
Oriented and Connection less.
6. Network Layer is both
Connection Oriented and
Connection less.
6. Network Layer is Connection less.
7. OSI is a reference model
around which the networks are
built. Generally it is used as a
guidance tool.
7. TCP/IP model is, in a way
implementation of the OSI model.
8. Network layer of OSI model 8. The Network layer in TCP/IP model
provides connectionless service.
provides both connection
oriented and connectionless
service.
9. It has 7 layers
9. It has 4 layers
Q5. How communication can be set between nodes of a ring network?
Each node connects to exactly two other nodes, forming a single continuous
pathway for signals through each node - a ring. Data travels from node to node,
with each node along the way handling every packet.
41 | P a g e
05914802717
RUCHIR BISHT
6-C4
EXPERIMENT 10
AIM: To Install and configure NetAnim.
 Description:
1.
Install Mercurial:
$apt−get/dnf
install mercurial
2.
Install QT4 development package:
$apt−get/dnf
install qt4−dev−tools
3.
Use Synaptic alternatively to install above mentioned packages.
4.
Download NetAnim:
hg clone http://code.nsnam.org/netanim
5.
Build NetAnim:
$cd netanim-3.xxx
$make clean
$qmake / qmake-qt?
$NetAnim. Pro
$make
 Compiling code with NetAnim :
Make the following changes to the code, in order to view the animation
on NetAnim. #include " ... "
#include "ns3/netanim−module .h"
char ∗argv [ ] )
//1 Include. . . int main ( int argc ,
42 | P a g e
05914802717
RUCHIR BISHT
6-C4
{
std : : string animFile = "somename. xml";
//2 Name of f i l e for animation
AnimationInterface anim ( animFile );
//3 Animation
interface Simulator : : Run ();
Simulator : : Destroy ();
return 0;
}
 To run the code:
1.
Move the waf , waf.bat , wscript and wutils.py les in to the scratch
folder (~/ns-allinone- 3.24/ns-3.24/scratch/).
2.
Move the example code to the scratch folder and make the
changes required for NetAnim, as shown above.
3.
Now cd to the scratch folder (cd ~/ns-allinone-3.24/ns3.24/scratch/).
4.
Run the code using the command:
$./ waf --run <filename>
Note: < lename> should not contain the extension .cc
 To visualize on NetAnim:
1.
cd to the netanim folder ($cd ~/netanim/).
2.
Run Netanim: $. /NetAnim
3.
Include the .xml file generated in
43 | P a g e
05914802717
RUCHIR BISHT
6-C4
NetAnim GUI
VIVA Questions
Q1 What is the role of NetAnim in NS3 simulator?
NetAnim is an offline network animator tool which now ships along with the
NS3.xx package. It can animate the ns-3 network simulation using an XML trace
file that is generated as an output during simulation.
Q2 What is the role of scratch folder in NS3 program simulation?
drop your script into the scratch directory and it will automatically be built if you
run Waf.
Q3. What is the role of animation in NS3 simulator?
Animation in NS3 simulator (NetAnim) uses a trace file generated during an ns-3
simulation to display the topology and animate the packet flow between nodes.
44 | P a g e
05914802717
RUCHIR BISHT
6-C4
Q4. Explain TCP/IP protocol suite?
 The TCP/IP protocol suite consists of many protocols that operate at one of 4
layers.
 The protocol suite is named after two of the most common protocols – TCP
(transmission Control Protocol) and IP (internet Protocol).
 TCP/IP was designed to be independent of networking Hardware and
should run across any connection media.
 The earliest use, and the most common use is over Ethernet networks.
 Ethernet is a 2 layer protocol/standard covering the physical and data link
layer, shown in the diagram above.
Q5. What is the hybrid network?
A hybrid network is any computer network that uses more than one type of
connecting technology or topology. For example, a home network that uses both
Wi-Fi and Ethernet cables to connect computers is a hybrid.
45 | P a g e
Download