Computer Networks Lab Manual-1
Computer Networks Lab Manual-1
Website:www.theoxford.edu/http://theoxfordengg.org/Email :[email protected]
APPROVED BY AICTE, ACCREDITED BY NAAC, AFFILIATED TO VTU
COMPUTER NETWORKS
21CS52
1
Computer Networks Laboratory
2
Computer Networks Laboratory
PROGRAM OUTCOMES
1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
3
Computer Networks Laboratory
INDEX
4
Computer Networks Laboratory
EXPERIMENT: 1
Implement Three nodes point – to – point network with duplex links between them for
different topologies. 1Set the queue size, vary the bandwidth, and find the number of
packets dropped for various iterations.
Aim
To understand the basic concepts of network topologies, duplex communication, and the impact of varying
network parameters such as queue size and bandwidth on packet transmission.
Requirements
● Networking Simulation Software (e.g., NS2, NS3, or similar)
Experiment Overview
This experiment involves setting up a three-node network with point-to-point duplex links. Configure the
network in different topologies, adjust the queue sizes and bandwidths, and observe the number of packets
dropped during data transmission.
Procedures
Part 2: Configuration
1. Set Queue Size: Configure the queue size for the routers. Start with a default value, and vary it in subsequent
iterations.
2. Configure Bandwidth: Set the initial bandwidth for the links. This value should be varied in later
experiments to observe the impact on packet transmission.
Analysis
● Compare the packet drop rate across different topologies.
5
Computer Networks Laboratory
● Analyze the effect of varying queue size and bandwidth on the packet drop rate.
● Discuss why packet drops occur and how network topology, queue size, and bandwidth influence this.
Report
Prepare a lab report documenting the procedures, observations, and your analysis. Include the following:
● Introduction to the concepts covered in the lab.
Program
#Create Simulator
set ns [new Simulator]
#Open Trace file and NAM file set ntrace [open prog1.tr w]
$ns trace-all $ntrace
set namfile [open prog1.nam w]
$ns namtrace-all $namfile
#Create 3 nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node]
#Schedule Events
$ns at 0.0 "$cbr0 start"
$ns at 5.0 "Finish"
Output
EXPERIMENT: 2
Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and
determine the throughput with respect to transmission of packets.
Aim
The aim of this lab exercise is to understand the working of an Extended Service Set (ESS) in a wireless LAN
(WLAN) setup and to analyze the throughput in relation to packet transmission. Set up a simulated wireless
LAN with multiple transmitting nodes and measure the throughput of the network.
Requirements
- Networking Simulation Software capable of WLAN simulation (e.g., NS2, NS3, OPNET, or similar)
- Computers with adequate processing power
7
Computer Networks Laboratory
Experiment Overview
Create a simple ESS configuration in a WLAN environment using a simulation tool. The setup will involve
multiple transmitting nodes within the ESS. The task is to transmit packets through these nodes and measure
the network's throughput, observing how it varies with different transmission rates and environmental factors.
8
Computer Networks Laboratory
Procedures
1. Launch Simulation Software: Open the network simulation tool on your computer.
2. Create a WLAN Environment: Set up a wireless LAN environment, defining the parameters such as signal
range, frequency band, etc.
3. Establish ESS: Implement an Extended Service Set, which typically includes one or more Basic Service Sets
(BSS) connected through a Distribution System (DS).
1. Add Wireless Nodes: Introduce multiple wireless nodes within the ESS. These nodes will act as transmitting
and receiving points.
2. Configure Packet Transmission: Set up the nodes to transmit data packets. This could involve configuring
packet size, transmission rate, and other relevant parameters.
1. Initiate Packet Transmission: Start the transmission of packets from the nodes.
2. Monitor Throughput: Use the simulation tool to monitor and record the throughput of the network.
Throughput is typically measured in bits per second (bps).
3. Vary Transmission Rates: Adjust the transmission rates and possibly other environmental factors, and
observe how these changes impact the network throughput.
Part 4: Analysis
1. Analyze Data: Analyze the data collected to understand the relationship between packet transmission rates
and throughput.
2. Identify Trends: Look for trends in how changes in the network (like increased transmission rates or more
nodes) affect throughput.
Report
Program
#===================================
#Mobile node parameter setup
#===================================
$ns node-config -adhocRouting DSDV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail \
-ifqLen 20 \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-propType Propagation/TwoRayGround \
-antType Antenna/OmniAntenna \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON
#===================================
#Nodes Definition
#===================================
create-god 6
#Create 6 nodes
set n0 [$ns node]
$n0 set X_ 630
$n0 set Y_ 501
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 454
$n1 set Y_ 340
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 785
$n2 set Y_ 326
$n2 set Z_ 0.0
$ns initial_node_pos $n2 20
set n3 [$ns node]
$n3 set X_ 270
$n3 set Y_ 190
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 539
$n4 set Y_ 131
10
Computer Networks Laboratory
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 964
$n5 set Y_ 177
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
#===================================
#Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n4 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500
#===================================
#Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
#===================================
#Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
11
Computer Networks Laboratory
#===================================
COMPUTER NETWORK [.awk] CODE
Save the below code file name with .awk extension
#CODE TO BE SAVED AS .awk FILE
#===================================
BEGIN{
count1=0
count2=0
pack1=0
pack2=0
time1=0
time2=0
}
{
if($1=="r"&&$3=="_1_"&&$4=="RTR")
{
count1++
pack1=pack1+$8
time1=$2
}
if($1=="r"&&$3=="_2_"&&$4=="RTR")
{
count2++
pack2=pack2+$8
time2=$2
}
}
END{
printf("The Throughput from n0 to n1: %fMbps\n",((count1*pack1*8)/(time1*1000000)));
printf("The Throughput from n1 to n2: %fMbps\n",((count2*pack2*8)/(time2*1000000)));
}
Output
EXPERIMENT: 3
Write a program for error detecting code using CRC-CCITT (16- bits).
12
Computer Networks Laboratory
Program Code
import java.util.Scanner;
import java.io.*;
public class CRC1 {
//Calculation of CRC
for(int i=0;i<message.length();i++)
{
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
}
//Display CRC
System.out.print("The checksum code is: ");
for(int i=0;i<message.length();i++)
data[i] = Integer.parseInt(message.charAt(i)+"");
for(int i=0;i<data.length;i++)
System.out.print(data[i]);
System.out.println();
//Calculation of remainder
for(int i=0;i<message.length();i++) {
13
Computer Networks Laboratory
if(data[i]==1)
for(int j=0;j<divisor.length;j++)
data[i+j] ^= divisor[j];
}
if(valid==true)
System.out.println("Data stream is valid");
else
System.out.println("Data stream is invalid. CRC error occurred.");
}
Output
EXPERIMENT: 4
AIM
To implement the transmission of ping messages or trace route in a network topology consisting of 6 nodes and
to monitor the number of packets dropped due to congestion, you would typically use network simulation
software. This task involves creating a network topology, simulating traffic, and then analyzing the results.
Below is a high-level outline of how you might approach this using a network simulator like NS2, NS3, or
similar tools.
14
Computer Networks Laboratory
Step 7: Reporting
Document your findings in a detailed report that includes:
- Network topology diagram.
- Description of the simulation setup.
- Observations regarding packet transmission, delays, and drops.
- Analysis of how congestion affected packet transmission and network performance.
Note
- Ensure that the simulation parameters (like bandwidth, delay, packet size, etc.) realistically represent the
scenarios you want to study.
- The complexity of the simulation can vary based on the network simulator used and the specific requirements
of your analysis.
Program code:
#Create Simulator
set ns [new Simulator]
#Open trace and NAM trace file set ntrace [open prog3.tr w]
$ns trace-all $ntrace
set namfile [open prog3.nam w]
$ns namtrace-all $namfile
15
Computer Networks Laboratory
#Create two ping agents and attach them to n(0) and n(5)
set p0 [new Agent/Ping]
$p0 set class_ 1
$ns attach-agent $n(0) $p0
#Create Congestion
#Generate a Huge CBR traffic between n(2) and n(4)
set tcp0 [new Agent/TCP]
$tcp0 set class_ 2
$ns attach-agent $n(2) $tcp0 set sink0 [new Agent/TCPSink]
$ns attach-agent $n(4) $sink0
$ns connect $tcp0 $sink0
#Schedule events
$ns at 0.2 "$p0 send"
$ns at 0.4 "$p1 send"
$ns at 0.4 "$cbr0 start"
$ns at 0.8 "$p0 send"
$ns at 1.0 "$p1 send"
$ns at 1.2 "$cbr0 stop"
$ns at 1.4 "$p0 send"
$ns at 1.6 "$p1 send"
$ns at 1.8 "Finish"
16
Computer Networks Laboratory
#Run the Simulation
$ns run
Output:
EXPERIMENT: 5
Write a program to find the shortest path between vertices using bellman-ford algorithm.
Note
This program handles negative weights but reports if there is a negative weight cycle, as the algorithm cannot
find shortest paths in such cases.
You need to add the actual edges of your graph in the main method, where the edges are defined.
Ensure that the graph configuration (number of vertices and edges, and the edges themselves) reflects the
actual graph you wish to analyze.
Program Code
import java.util.Scanner;
public class ford
{
private int D[];
private int num_ver;
public static final int MAX_VALUE = 999;
public ford(int num_ver)
{
this.num_ver = num_ver;
D = new int[num_ver + 1];
}
17
Computer Networks Laboratory
for (int node = 1; node <= num_ver; node++)
{
D[node] = MAX_VALUE;
}
D[source] = 0;
18
Computer Networks Laboratory
System.out.println("Enter the source vertex");
source = scanner.nextInt();
ford b = new ford (num_ver);
b.BellmanFordEvaluation(source, A);
scanner.close();
}
}
Output
EXPERIMENT: 6
Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot
congestion window for different source / destination.
Aim
Implementing an Ethernet LAN with multiple nodes and plotting the congestion window for different
source/destination pairs involves a complex process that typically requires network simulation software. Tools
like NS2, NS3, or OPNET are commonly used for such tasks. Below is a high-level outline of the steps you
would follow to implement this, primarily focusing on the use of a network simulator.
Steps
Step 1: Select and Set Up a Network Simulator
Choose a network simulator that supports Ethernet LAN simulations and congestion analysis (NS2, NS3,
OPNET, etc.). Install and set up the software on your computer.
1. TCP Congestion Control: If you are using TCP traffic, the TCP congestion control mechanism will be
inherently part of the simulation. Ensure that the simulator is configured to capture and plot TCP congestion
window sizes.
2. Custom Congestion Control: If you want to implement a custom congestion control mechanism, you may
need to program this into the simulator, depending on its capabilities.
Note
- This is a high-level overview. The exact steps may vary based on the chosen network simulator and the
specific requirements of your network scenario.
- This simulation will provide insights into how different traffic patterns affect network congestion,
particularly in an Ethernet LAN environment. It's a valuable exercise for understanding network dynamics and
the impact of congestion control mechanisms.
Program Code
#Create Simulator
set ns [new Simulator]
#Open trace and NAM trace file set ntrace [open prog5.tr w]
$ns trace-all $ntrace
set namfile [open prog5.nam w]
$ns namtrace-all $namfile
#Use some flat file to create congestion graph windows set winFile0 [open WinFile0 w]
set winFile1 [open WinFile1 w]
#Plot the Congestion Window graph using xgraph exec xgraph WinFile0 WinFile1 &
exit 0
}
#Create 6 nodes
for {set i 0} {$i<6} {incr i} { set n($i) [$ns node]
}
#Setup queue between n(2) and n(3) and monitor the queue
$ns queue-limit $n(2) $n(3) 20
$ns duplex-link-op $n(2) $n(3) queuePos 0.5
#Set error model on link n(2) to n(3) set loss_module [new ErrorModel]
$loss_module ranvar [new RandomVariable/Uniform]
$loss_module drop-target [new Agent/Null]
$ns lossmodel $loss_module $n(2) $n(3)
#Set up the TCP connection between n(0) and n(4) set tcp0 [new Agent/TCP/Newreno]
$tcp0 set fid_ 1
$tcp0 set window_ 8000
$tcp0 set packetSize_ 552
$ns attach-agent $n(0) $tcp0
set sink0 [new Agent/TCPSink/DelAck]
$ns attach-agent $n(4) $sink0
$ns connect $tcp0 $sink0
#Set up another TCP connection between n(5) and n(1) set tcp1 [new Agent/TCP/Newreno]
$tcp1 set fid_ 2
$tcp1 set window_ 8000
$tcp1 set packetSize_ 552
$ns attach-agent $n(5) $tcp1
set sink1 [new Agent/TCPSink/DelAck]
$ns attach-agent $n(1) $sink1
$ns connect $tcp1 $sink1
#Schedule Events
$ns at 0.1 "$ftp0 start"
$ns at 0.1 "PlotWindow $tcp0 $winFile0"
$ns at 0.5 "$ftp1 start"
21
Computer Networks Laboratory
$ns at 0.5 "PlotWindow $tcp1 $winFile1"
$ns at 25.0 "$ftp0 stop"
$ns at 25.1 "$ftp1 stop"
$ns at 25.2 "Finish"
Output
EXPERIMENT: 7
Write a program for congestion control using leaky bucket algorithm.
Note
This is a basic simulation and might need to be adjusted for more complex network scenarios.
The program outputs the state of the bucket at each time interval, showing how the Leaky Bucket Algorithm
controls the data transmission and manages congestion.
Program Code:
22
Computer Networks Laboratory
import java.util.Scanner;
import java.lang.*;
public class lab7 {
public static void main(String[] args)
{
int i;
int a[]=new int[20];
int buck_rem=0,buck_cap=4,rate=3,sent,recv;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of packets");
int n = in.nextInt();
System.out.println("Enter the packets");
for(i=1;i<=n;i++)
a[i]= in.nextInt();
System.out.println("Clock \t packet size \t accept \t sent \t remaining");
for(i=1;i<=n;i++)
{
if(a[i]!=0)
{
if(buck_rem+a[i]>buck_cap)
recv=-1;
else
{
recv=a[i];
buck_rem+=a[i];
}
}
else
recv=0;
if(buck_rem!=0)
{
if(buck_rem<rate)
{sent=buck_rem;
buck_rem=0;
}
else
{
sent=rate;
buck_rem=buck_rem-rate;
}
}
else
sent=0;
if(recv==-1)
System.out.println(+i+ "\t\t" +a[i]+ "\t dropped \t" + sent +"\t" +buck_rem);
else
System.out.println(+i+ "\t\t" +a[i] +"\t\t" +recv +"\t" +sent + "\t" +buck_rem);
}
}
}
Output:
23
Computer Networks Laboratory
24