0% found this document useful (0 votes)
37 views

Computer Networks Lab Manual-1

This experiment involves setting up a three node network in different topologies like linear and varying parameters like queue size and bandwidth to observe their impact on packet drops. The key steps are: 1) Create three nodes and connect them with duplex links in different topologies 2) Configure the queue size and bandwidth 3) Initiate data transfer between nodes 4) Monitor packet transmission and record packet drops 5) Repeat the process by varying the queue size and bandwidth to understand their effect on congestion.

Uploaded by

Jaikishore M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Computer Networks Lab Manual-1

This experiment involves setting up a three node network in different topologies like linear and varying parameters like queue size and bandwidth to observe their impact on packet drops. The key steps are: 1) Create three nodes and connect them with duplex links in different topologies 2) Configure the queue size and bandwidth 3) Initiate data transfer between nodes 4) Monitor packet transmission and record packet drops 5) Repeat the process by varying the queue size and bandwidth to understand their effect on congestion.

Uploaded by

Jaikishore M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Computer Networks Laboratory

DEPARTMENT OF ARTIFICIAL INTELLIGENCE & MACHINE LEARNING

THE OXFORD COLLEGE ENGINEERING

Hosur Road, Bommanahalli, Bengaluru-560 068

Website:www.theoxford.edu/http://theoxfordengg.org/Email :[email protected]
APPROVED BY AICTE, ACCREDITED BY NAAC, AFFILIATED TO VTU

LAB MANUAL FOR

COMPUTER NETWORKS
21CS52

1
Computer Networks Laboratory

Vision of the Institute:


“To be a Respected and Most Sought after Engineering Educational Institution Engaged in
Equipping Individuals capable of Building Learning Organizations in the New
Millennium”.

Mission of the Institute:


Our Mission is to develop Competent Students with good value Systems and Face
Challenges of the Continuously Changing World.

Vision of the Department:


“To Create Technocrats with Cognitive Skills and Technical Proficiency to Succeed in the
Challenging World of New Era”.

Mission of the Department:


To Produce outstanding Artificial Engineering Professionals with cognitive
MD1 skills.

To Enrich the students’ skill set by continuous learning and research


MD2
capabilities with vibrant ambience.
● To empower students with Technical Proficiency, Competency and
MD3
Ethicalness for the new Era.
Program Educational Objectives (PEOs)

To Empower graduates with cognitive skills to lead their professional career in


Reputed Industries and Solve Problems by Applying the Principles of Mathematics,
PEO 1 Artificial Intelligence and Machine Learning, Scientific Investigations using the
Latest Technologies through the opportunities of Artificial Intelligence & Machine
Learning.
To Enrich the graduates by engaging them in research area of Artificial
PEO 2 Intelligence & Machine Learning and empower them to work in scientific
environment.
To create graduates with Professional Advancement, Communication Skills, Life
PEO 3 Long Learning Process, Ethical Attitude, Social Responsibility, Team Work,
Project Management and Leadership Skills Through Continuing Education.

Program Specific Outcomes (PSOs)


Use appropriate Techniques and Tools in application design with a knowledge of
Computer Science, Networking, Software Engineering, Programs, Projects, Design
PSO 1
of new Algorithms, Artificial Intelligence and Machine Learning Systems for
Solving Complex Engineering Problems.
Inculcate the ability to work with Professional Ethics, Communication Skills,
PSO 2 Team Work, Exchange of Innovative Ideas to Carryout Lifelong Learning with the
state of art technologies and development.

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

S. No. PROGRAME NAME PAGE No.

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.
2 Implement simple ESS and with transmitting nodes in wire-less LAN
by simulation and determine the throughput with respect to
transmission of packets.
3 Write a program for error detecting code using CRC-CCITT (16- bits).

4 Implement transmission of ping messages/trace route over a network


topology consisting of 6 nodes and find the number of packets dropped
due to congestion in the network.
5 Write a program to find the shortest path between vertices using
bellman-ford algorithm.

6 Implement an Ethernet LAN using n nodes and set multiple traffic


nodes and plot congestion window for different source / destination.

7 Write a program for congestion control using leaky bucket algorithm.

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)

● Computers with sufficient processing capabilities

● Basic understanding of networking concepts

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 1: Network Setup


1. Select a Simulation Tool: Start by launching the network simulation software on your computer.
2. Create Nodes: Create three nodes (Node A, Node B, and Node C) within the simulation environment.
3. Establish Duplex Links: Connect these nodes with point-to-point duplex links. You will experiment with the
following topologies:
- Linear (A-B-C)

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.

Part 3: Data Transmission & Observation


1. Initiate Data Transfer: Start a data transfer between the nodes. This could be a constant bit rate (CBR) or
variable bit rate (VBR) traffic.
2. Monitor Packet Transmission: Use the simulation tools to monitor the data packets as they travel through the
network.
3. Record Packet Drops: Observe and record the number of packet drops during transmission. Packet drops are
often indicative of congestion in the network.

Part 4: Varying Parameters


1. Vary Queue Size: Repeat the data transmission with different queue sizes and record the packet drops.
2. Vary Bandwidth: Adjust the bandwidth for the links and observe the impact on packet transmission and
drops.

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.

● Detailed methodology for each part of the experiment.

● Observations and data collected.

● Analysis of the data and conclusions drawn from the experiment.

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

#Finish Procedure proc Finish {} {


global ns ntrace namfile

#Dump all the trace data and close the files


$ns flush-trace close $ntrace close $namfile

#Execute the nam animation file exec nam prog1.nam &

#Show the number of packets dropped


exec echo "The number of packet drops is " & exec grep -c "^d" prog1.tr &
exit 0
}

#Create 3 nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node]

#Label the nodes


$n0 label "TCP Source"
$n2 label "Sink"

#Set the color

$ns color 1 blue

#Create Links between nodes


#You need to modify the bandwidth to observe the variation in packet drop
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail

#Make the Link Orientation


$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right

#Set Queue Size


#You can modify the queue length as well to observe the variation in packet drop
$ns queue-limit $n0 $n1 10
$ns queue-limit $n1 $n2 10

#Set up a Transport layer connection. set tcp0 [new Agent/TCP]


6
Computer Networks Laboratory
$ns attach-agent $n0 $tcp0
set sink0 [new Agent/TCPSink]
$ns attach-agent $n2 $sink0
$ns connect $tcp0 $sink0

#Set up an Application layer Traffic


set cbr0 [new Application/Traffic/CBR]
$cbr0 set type_ CBR
$cbr0 set packetSize_ 100
$cbr0 set rate_ 1Mb
$cbr0 set random_ false
$cbr0 attach-agent $tcp0

$tcp0 set class_ 1

#Schedule Events
$ns at 0.0 "$cbr0 start"
$ns at 5.0 "Finish"

#Run the Simulation


$ns run

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

- Basic knowledge of wireless networking concepts

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

Part 1: Simulation Setup

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

Part 2: Adding Nodes and Configuring Transmission

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.

Part 3: Measuring Throughput

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

Compile a comprehensive lab report that includes the following components:

● An introduction to wireless LANs, focusing on the concept of ESS.

● A detailed description of the setup and methodology.

● Observations and data collected during the experiment.

● Analysis of how packet transmission rates affect network throughput.

● Conclusions based on the experiment's findings.


9
Computer Networks Laboratory

Program

COMPUTER NETWORK [.tcl] CODE


Save the below code with filename .tcl extension
#Create a ns simulator
set ns [new Simulator]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid 1500 1500

#Open the NS trace file


set tracefile [open p4.tr w]
$ns trace-all $tracefile

#Open the NAM trace file


set namfile [open p4.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile 1500 1500

#===================================
#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

#Setup a TCP connection


set tcp0 [new Agent/TCP]
$ns attach-agent $n3 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n5 $sink1
$ns connect $tcp0 $sink1

#===================================
#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

#Setup a FTP Application over TCP connection


set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0

#===================================
#Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile

exec nam p4.nam &


exec echo "Number of packets dropped is:" &
exec grep -c "^D" p4.tr &
exit 0

$ns at 1.0 "$cbr0 start"


$ns at 2.0 "$ftp0 start"
$ns at 180.0 "$ftp0 stop"
$ns at 200.0 "$cbr0 stop"
$ns at 200.0 "finish"
$ns at 70 "$n4 set dest 100 60 20"
$ns at 100 "$n4 set dest 700 300 20"
$ns at 150 "$n4 set dest 900 200 20"
$ns run

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

How to Use the Program


Input Data: Provide the data for which you want to calculate the CRC checksum. The data should be in
hexadecimal format (e.g., "1234ABCD").
Call crc_ccitt Function: The function crc_ccitt computes the CRC checksum using the specified polynomial
and initial value.
Output: The program outputs the CRC checksum in hexadecimal format.

Understanding the Code


Initial Value: The CRC-CCITT typically starts with an initial value of 0xFFFF.
Polynomial: The standard polynomial for CRC-CCITT 16-bit is 0x1021.
Calculation: The algorithm processes each bit of the input data, applying the polynomial division. The final
CRC value is the remainder of this division.

Program Code
import java.util.Scanner;
import java.io.*;
public class CRC1 {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

//Input Data Stream


System.out.print("Enter message bits: ");
String message = sc.nextLine();
System.out.print("Enter generator: ");
String generator = sc.nextLine();
int data[] = new int[message.length() + generator.length() - 1];
int divisor[] = new int[generator.length()];
for(int i=0;i<message.length();i++)
data[i] = Integer.parseInt(message.charAt(i)+"");
for(int i=0;i<generator.length();i++)
divisor[i] = Integer.parseInt(generator.charAt(i)+"");

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

//Check for input CRC code


System.out.print("Enter checksum code: ");
message = sc.nextLine();
System.out.print("Enter generator: ");
generator = sc.nextLine();
data = new int[message.length() + generator.length() - 1];
divisor = new int[generator.length()];
for(int i=0;i<message.length();i++)
data[i] = Integer.parseInt(message.charAt(i)+"");
for(int i=0;i<generator.length();i++)
divisor[i] = Integer.parseInt(generator.charAt(i)+"");

//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];
}

//Display validity of data


boolean valid = true;
for(int i=0;i<data.length;i++)
if(data[i]==1){
valid = false;
break;
}

if(valid==true)
System.out.println("Data stream is valid");
else
System.out.println("Data stream is invalid. CRC error occurred.");
}

Output

EXPERIMENT: 4

Implement transmission of ping messages/trace route over a network topology consisting


of 6 nodes and find the number of packets dropped due to congestion in the network.

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.

Step 1: Install a Network Simulator


First, you need to have a network simulation tool installed on your computer. NS2 and NS3 are popular
choices in the academic community for such simulations.

14
Computer Networks Laboratory

Step 2: Design the Network Topology


1. Create Nodes: Define six nodes in the simulator.
2. Configure Network Topology: Arrange these nodes in a desired topology (e.g., star, ring, mesh, etc.).
3. Establish Connections: Connect these nodes using appropriate links. Assign bandwidth and delay properties
to these links.

Step 3: Configure the Simulation


1. Assign IP Addresses: Allocate IP addresses to each node.
2. Set Routing Protocol: Define the routing protocol to be used (e.g., OSPF, RIP, etc.) for path determination.
3. Configure Ping/Trace Route: Set up ping (ICMP Echo) or trace route mechanisms to send messages between
nodes. Determine the source and destination nodes for these messages.

Step 4: Simulate Traffic and Congestion


1. Generate Network Traffic: Apart from ping/trace route messages, generate additional network traffic to
simulate a realistic network load. This could involve TCP/UDP traffic between different nodes.
2. Introduce Congestion: You might manually configure high traffic loads on certain links or nodes to create
congestion scenarios.

Step 5: Run the Simulation


1. Execute the Simulation: Run the simulation for a specified duration.
2. Monitor Packet Flow: Use the simulator’s tools to monitor the packet flow and trace the route of ping
messages.

Step 6: Analyze the Results


1. Packet Drop Analysis: Examine the simulation results to identify where and why packet drops occurred.
Look for patterns indicating congestion (e.g., dropped packets at specific nodes or links).
2. Trace Route Analysis: Analyze the trace route results to understand the path taken by packets and where
delays or failures occurred.

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]

#Use colors to differentiate the traffic


$ns color 1 Blue
$ns color 2 Red

#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

#Finish Procedure proc Finish {} {


global ns ntrace namfile

15
Computer Networks Laboratory

#Dump all trace data and close the file


$ns flush-trace close $ntrace close $namfile

#Execute the nam animation file exec nam prog3.nam &

#Find the number of ping packets dropped


puts "The number of ping packets dropped are "
exec grep "^d" prog3.tr | cut -d " " -f 5 | grep -c "ping" & exit 0
}

#Create six nodes


for {set i 0} {$i < 6} {incr i} {
set n($i) [$ns node]
}
#Connect the nodes
for {set j 0} {$j < 5} {incr j} {
$ns duplex-link $n($j) $n([expr ($j+1)]) 0.1Mb 10ms DropTail
}

#Define the recv function for the class 'Agent/Ping'


Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] received ping answer from $from with round trip time $rtt
ms"
}

#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

set p1 [new Agent/Ping]


$p1 set class_ 1
$ns attach-agent $n(5) $p1
$ns connect $p0 $p1

#Set queue size and monitor the queue


#Queue size is set to 2 to observe the drop in ping packets
$ns queue-limit $n(2) $n(3) 2
$ns duplex-link-op $n(2) $n(3) queuePos 0.5

#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

#Apply CBR traffic over TCP


set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set rate_ 1Mb
$cbr0 attach-agent $tcp0

#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.

How to Use the Program


Define the Graph: Specify the number of vertices and edges in your graph. Then, define each edge with its
source, destination, and weight.
Run BellmanFord: Call the BellmanFord method with the graph and the source vertex.
Observe Output: The program outputs the shortest distance from the source vertex to every other vertex.

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];
}

public void BellmanFordEvaluation(int source, int A[][])


{

17
Computer Networks Laboratory
for (int node = 1; node <= num_ver; node++)
{
D[node] = MAX_VALUE;
}

D[source] = 0;

for (int node = 1; node <= num_ver - 1; node++)


{
for (int sn = 1; sn <= num_ver; sn++)
{
for (int dn = 1; dn <= num_ver; dn++)
{
if (A[sn][dn] != MAX_VALUE)
{
if (D[dn] > D[sn]+ A[sn][dn])
D[dn] = D[sn] + A[sn][dn];
}
}
}
}

for (int sn = 1; sn <= num_ver; sn++)


{
for (int dn = 1; dn <= num_ver; dn++)
{
if (A[sn][dn] != MAX_VALUE)
{
if (D[dn] > D[sn]+ A[sn][dn])
System.out.println("The Graph contains negative egde cycle"); }
}
}

for (int vertex = 1; vertex <= num_ver; vertex++)


{
System.out.println("distance of source"+source+"to"+vertex+"is" + D[vertex]);
}
}

public static void main(String[ ] args)


{
int num_ver = 0;
int source;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of vertices");
num_ver = scanner.nextInt();

int A[][] = new int[num_ver + 1][num_ver + 1];


System.out.println("Enter the adjacency matrix");
for (int sn = 1; sn <= num_ver; sn++)
{
for (int dn = 1; dn <= num_ver; dn++)
{
A[sn][dn] = scanner.nextInt();
if (sn == dn)
{
A[sn][dn] = 0;
continue;
}
if (A[sn][dn] == 0)
{
A[sn][dn] = MAX_VALUE;
}
}
}

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.

Step 2: Design the Ethernet LAN


1. Create Nodes: Define 'n' nodes within the simulation environment to represent the computers in the LAN.
2. Configure Ethernet LAN: Set up an Ethernet LAN connecting these nodes. This usually involves specifying
the network topology (star, bus, ring, etc.), assigning IP addresses, and setting up Ethernet links.

Step 3: Configure Traffic Nodes


1. Select Traffic Nodes: Choose nodes that will act as sources and destinations of network traffic.
2. Set Traffic Parameters: Define the type of traffic for each source node (e.g., TCP, UDP, HTTP). Specify
parameters like packet size, transmission rate, and start/end times.

Step 4: Implement Congestion Control


19
Computer Networks Laboratory

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.

Step 5: Run the Simulation


Execute the simulation for a defined duration. Ensure the simulation captures detailed data on network traffic,
especially focusing on congestion window sizes for TCP connections.

Step 6: Analyze and Plot Results


1. Collect Data: After the simulation, collect data on the congestion window sizes for different
source/destination pairs.
2. Plot Congestion Window: Use the collected data to plot the congestion window size over time. This can
typically be done within the network simulator or exported to a data analysis tool like MATLAB or Python for
more complex analysis.

Step 7: Reporting and Interpretation


Prepare a detailed report that includes:
- The network topology and configuration.
- The traffic patterns used in the simulation.
- Congestion window plots for different source/destination pairs.
- Analysis of how different traffic patterns affected the congestion window sizes and overall network
performance.

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]

#Use colors to differentiate the traffics


$ns color 1 Blue
$ns color 2 Red

#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]

#Finish Procedure proc Finish {} {


#Dump all trace data and Close the files global ns ntrace namfile
$ns flush-trace close $ntrace close $namfile

#Execute the NAM animation file exec nam prog5.nam &

#Plot the Congestion Window graph using xgraph exec xgraph WinFile0 WinFile1 &
exit 0
}

#Plot Window Procedure


20
Computer Networks Laboratory
proc PlotWindow {tcpSource file} { global ns
set time 0.1
set now [$ns now]

set cwnd [$tcpSource set cwnd_] puts $file "$now $cwnd"


$ns at [expr $now+$time] "PlotWindow $tcpSource $file"
}

#Create 6 nodes
for {set i 0} {$i<6} {incr i} { set n($i) [$ns node]
}

#Create duplex links between the nodes


$ns duplex-link $n(0) $n(2) 2Mb 10ms DropTail
$ns duplex-link $n(1) $n(2) 2Mb 10ms DropTail
$ns duplex-link $n(2) $n(3) 0.6Mb 100ms DropTail

#Nodes n(3) , n(4) and n(5) are considered in a LAN


set lan [$ns newLan "$n(3) $n(4) $n(5)" 0.5Mb 40ms LL Queue/DropTail MAC/802_3 Channel]

#Orientation to the nodes


$ns duplex-link-op $n(0) $n(2) orient right-down
$ns duplex-link-op $n(1) $n(2) orient right-up
$ns duplex-link-op $n(2) $n(3) orient right

#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

#Apply FTP Application over TCP set ftp0 [new Application/FTP]


$ftp0 attach-agent $tcp0

$ftp0 set type_ FTP

#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

#Apply FTP application over TCP set ftp1 [new Application/FTP]


$ftp1 attach-agent $tcp1
$ftp1 set type_ FTP

#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"

#Run the simulation


$ns run

Output

EXPERIMENT: 7
Write a program for congestion control using leaky bucket algorithm.

How the Program Works


inputFlow: An array representing the number of data packets arriving at different time intervals.
bucketSize: The maximum capacity of the bucket.
outputRate: The rate at which packets can leave the bucket.
The program calculates packet loss (if any) at each time interval and simulates the transmission of packets
from the bucket at a constant rate.
Running the Program
Set the Input Flow: Define the number of packets arriving at each time interval in the inputFlow array.
Configure Bucket Size and Output Rate: Set the bucketSize and outputRate according to your requirements.
Run the Program: Execute the program. It will display information about packet loss and transmission for each
time interval.

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

You might also like