Computer Networks Lab
Computer Networks Lab
Course Outcomes: By the end of the course, the student should be able to
CO1: Apply the routing, congestion control algorithms for a set of inputs.
CO2: Demonstrate Inter Process Communication, error detection and encryption technique.
CO 3: Analyse the performance of wired and wireless network for different topologies using simulator.
CO4: Evaluate the performance of GSM and CDMA network using simulator
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
PART – A
Simulation Exercises
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
NS2 Basics
NS or The Network Simulator is a discrete event network simulator. NS is popularly used in the
simulation of routing and multicast protocols, and is heavily used in ad hoc networking research.
NS is an object oriented simulator, written in C++, with an OTcl interpreter as a frontend. The
simulator supports class hierarchy in C++ (the compiled hierarchy), and a similar class hierarchy
within the OTcl interpreter (the interpreted hierarchy).
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Simulation Program 1:
Simulate a three point – to – point network with duplex links between them. Set the queue
size and vary the bandwidth and find the number of packets dropped.
Step1: Open text editor, type the below program and save with extension .tcl (prog1.tcl)
proc finish {} {
global f nf ns
$ns flush-trace
close $f
close $nf
exec nam 1.nam &
exec echo "The number of packet drops is " &
exec grep -c "^d" 1.tr &
exit 0
}
$ns duplex-link $n0 $n1 0.3Mb 10ms DropTail #vary bandwidth 0.3, 0.4, 0.5 and 0.7
$ns duplex-link $n1 $n2 0.3Mb 20ms DropTail #vary bandwidth 0.3, 0.4, 0.5 and 0.7
$ns queue-limit $n1 $n2 10
Step2: Open text editor, type the below program and save with extention .awk (prog1.awk )
BEGIN {
dcount = 0;
rcount = 0;
}
{
event = $1;
if(event == "d")
{
dcount++;
}
if(event == "r")
{
rcount++;
}
}
END {
printf("The no.of packets dropped : %d\n ",dcount);
printf ("The no.of packets recieved: %d\n ",rcount);
}
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Step 4: Now press the play button in the simulation window and the simulation will begins.
Step 5: After simulation is completed run awk file to see the output ,
[root@localhost~]# awk –f prog1.awk prog1.tr
Number of packets dropped = 16
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Simulation Program 2:
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.
Step1: Open text editor, type the below program and save with extension .tcl (prog2.tcl )
proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf
exec nam 2.nam &
puts "The number of ping packets dropped are "
exec grep "^d" 2.tr | cut -d " " -f 5 | grep -c "ping" &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
proc sendPingPacket {} {
global ns ping0 ping4
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Step2: Open text editor, type the below program and save with extention .awk (prog2.awk )
BEGIN {
count=0;
}
{
event=$1;
if(event=="d")
{
count++;
}
}
END {
printf("No of packets dropped: %d\n",count);
}
Step3: Run the simulation program
[root@localhost~]# ns prog2.tcl
(Here “ns” indicates network simulator. We get the topology shown in the snapshot.)
Step 4: Now press the play button in the simulation window and the simulation will begins
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Simulation Program 3:
Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion
window for different source / destination.
Step1: Open text editor, type the below program and save with extension .tcl (prog3.tcl )
proc finish {} {
global ns f nf outFile1 outFile2
$ns flush-trace
close $f
close $nf
exec nam 3.nam &
exec xgraph Congestion1.xg -geometry 400x400 &
exec xgraph Congestion2.xg -geometry 400x400 &
exit 0
}
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Step2: Open text editor, type the below program and save with extension .awk (prog3.awk )
BEGIN {
}
{
if($6=="cwnd_") {
printf("%f\t%f\n",$1,$7);
}
}
END {
}
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Step 4: Now press the play button in the simulation window and the simulation will begins.
Step 5: After simulation is completed run awk file and generate the graph ,
[root@localhost~]# awk –f prog3.awk cwnd.tr > a1
[root@localhost~]# awk –f prog3.awk cwnd2.tr > a2
[root@localhost~]#xgraph a1 a2
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Simulation Program 4:
Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and
determine the performance with respect to transmission of packets.
Step1: Open text editor, type the below program and save with extension .tcl (prog4.tcl )
if {$argc != 1} {
error "Command: ns <ScriptName.tcl><Number_of_Nodes>"
exit 0
}
proc stop {} {
global ns trfd namfd
close $trfd
close $namfd
exec nam 4.nam &
#Calculate throughput = (number of packets received/time taken for simulation)
set datasize1 1060
set num1 [exec grep "^r" 6.tr | grep "_3_" | grep -c "AGT"]
set time1 100
puts "The throughput from n1 to n3 is "
puts "[expr ($datasize1*$num1)/$time1] bytes per second"
exit 0
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Step2: Open text editor, type the below program and save with extension .awk (prog4.awk )
BEGIN {
count1=0
count2=0
pack1=0
pack2=0
time1=0
time2=0
}
{if($1=="r"&& $3=="_1_" && $4=="AGT")
{count1++
pack1=pack1+$8
time1=$2 }
if($1=="r" && $3=="_2_" && $4=="AGT")
{count2++
pack2=pack2+$8
time2=$2}
}
END{
printf("The Throughput from n0 to n1: %f Mbps \n", ((count1*pack1*8)/(time1*1000000)));
printf("The Throughput from n1 to n2: %f Mbps", ((count2*pack2*8)/(time2*1000000)));
}
Step 5: After simulation is completed run awk file to see the output ,
[root@localhost~]# awk –f prog4.awk prog4.tr
Simulation Program 5:
Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or equivalent
environment.
# General Parameters
set stop 100 ;# Stop time.
# Topology
set type gsm ;#type of link:
# AQM parameters
set minth 30
set maxth 0
set adaptive 1 ;# 1 for Adaptive RED, 0 for plain RED
# Traffic generation.
set flows 0 ;# number of long-lived TCP flows
set window 30 ;# window for long-lived traffic
# Plotting statistics.
set opt(wrap) 100 ;# wrap plots?
set opt(srcTrace) is ;# where to plot traffic
set opt(dstTrace) bs2 ;# where to plot traffic
proc cell_topo {} {
global ns nodes
$ns duplex-link $nodes(lp) $nodes(bs1) 3Mbps 10ms DropTail
$ns duplex-link $nodes(bs1) $nodes(ms) 1 1 RED
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
source web.tcl
#Create topology
switch $type {
gsm -
cdma {cell_topo}
}
set_link_params $type
$ns insert-delayer $nodes(ms) $nodes(bs1) [new Delayer]
$ns insert-delayer $nodes(ms) $nodes(bs2) [new Delayer]
proc stop {} {
global nodes opt tf
set wrap $opt(wrap)
set sid [$nodes($opt(srcTrace)) id]
set did [$nodes($opt(dstTrace)) id]
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
set a "out.tr"
exit 0
}
$ns at $stop "stop"
$ns run
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Simulation Program 6:
Implement and study the performance of CDMA on NS2/NS3 (Using stack called Call net) or
equivalent environment.
# General Parameters
set stop 100 ;# Stop time.
# Topology
set type cdma ;#type of link
# AQM parameters
set minth 30
set maxth 0
set adaptive 1 ;# 1 for Adaptive RED, 0 for plain RED
# Traffic generation.
set flows 0 ;# number of long-lived TCP flows
set window 30 ;# window for long-lived traffic
# Plotting statics.
set opt(wrap) 100 ;# wrap plots?
set opt(srcTrace) is ;# where to plot traffic
set opt(dstTrace) bs2 ;# where to plot traffic
proc cell_topo {} {
global ns nodes
$ns duplex-link $nodes(lp) $nodes(bs1) 3Mbps 10ms DropTail
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
source web.tcl
#Create topology
switch $type {
cdma {cell_topo}
}
set_link_para $type
$ns insert-delayer $nodes(ms) $nodes(bs1) [new Delayer]
$ns insert-delayer $nodes(ms) $nodes(bs2) [new Delayer]
proc stop {} {
global nodes opt tf
set wrap $opt(wrap)
set sid [$nodes($opt(srcTrace)) id]
set did [$nodes($opt(dstTrace)) id]
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
set a "out.tr"
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
PART – B
Network Programs
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Experiment No 1: - CRC
Problem Statement
Write a program for error detecting code using CRC-CCITT (16 bits).
Theory
CRC(Cyclic Redundancy Check) is an error detecting technique used in digital networks and
storage devices to detect the accidental changes to raw data. It cannot be used for correcting
errors.
The CRC does error checking via polynomial division. The generated polynomial g(x) =
16 12
5 0
x +x +x +x
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 17 bits.
Algorithm:
S s
1) Given a bit string (message to be sent), append 16 0 to the end of it (the number of 0 is
S
the same as the degree of the generator polynomial) let this string + 0 be called as
modified string B
2) Divide B by agreed on polynomial g(x) and determine the remainder R(x). The 16-bit
remainder received is called as checksum.
3) The message string is appended with checksum and sent to the receiver.
4) At the receiver side, the received message is divided by generator polynomial g(x).
5) If the remainder is 0, the receiver concludes that there is no error occurred otherwise, the
receiver concludes an error occurred and requires a retransmission.
Program:
import java.util.Scanner;
class crc
{
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
//Generated Codeword
data = data + checksum;
System.out.println("Sender Checksum="+checksum);
System.out.println( "Code word transmitted overnetwork="+data);
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
}
}
Output:
1. Enter the data to be encrypted
10111
Div=0110001011010110
Sender Checksum=0110001011010110
Code word transmitted overnetwork=101110110001011010110
Enter the received codeword
101110110001011010110
Div=0000000000000000
No error in data transmission
100100011001001110010
Div=0000000000000001
Error in transmission
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Experiment No 2
Bellman-Ford algorithm
Problem Statement
Write a program to find the shortest path between vertices using bellman-ford
algorithm.
Theory
Routing algorithm is a part of network layer software which is responsible for deciding which output
line an incoming packet should be transmitted on. If the subnet uses datagram internally, this decision
must be made anew for every arriving data packet since the best route may have changed since last time.
If the subnet uses virtual circuits (connection Oriented), routing decisions are made only when a new
established route is being set up.
Routing algorithms can be grouped into two major classes: adaptive and nonadaptive. Nonadaptive
algorithms do not base their routing decisions on measurement or estimates of current traffic and
topology. Instead, the choice of route to use to get from I to J (for all I and J) is compute in advance,
offline, and downloaded to the routers when the network ids booted. This procedure is sometime called
static routing.
Adaptive algorithms, in contrast, change their routing decisions to reflect changes in the topology, and
usually the traffic as well. Adaptive algorithms differ in where they get information (e.g., locally, from
adjacent routers, or from all routers), when they change the routes (e.g., every ∆T sec, when the load
changes, or when the topology changes), and what metric is used for optimization (e.g., distance, number
of hops, or estimated transit time).
Two algorithms in particular, distance vector routing and link state routing are the most popular.
Distance vector routing algorithms operate by having each router maintain a table (i.e., vector) giving the
best known distance to each destination and which line to get there. These tables are updated by
exchanging information with the neighbors.
The distance vector routing algorithm uses Bellman-Ford routing algorithm and Ford-Fulkerson
algorithm. In distance vector routing, each router maintains a routing table that contains two parts: the
preferred out going line to use for that destination, and an estimate of the time or distance to that
destination. The metric used might be number of hops, time delay in milliseconds, total number of
packets queued along the path, or something similar.
The Routing tables are shared among the neighbors, and the tables at the router are updated, such that
the router will know the shortest path to the destination.
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Program:
importjava.io.*;
importjava.util.Scanner;
classdist_vec
{
publicstaticvoid main(String args[])
{
intdmat[][];
intdist[][];
int via[][];
int n=0,i=0,j=0,k=0,count=0;
Scanner in = new Scanner(System.in);
System.out.println("enter the number of nodes\n");
n = in.nextInt();
dmat = newint[n][n];
dist = newint[n][n];
via = newint[n][n];
System.out.println("enter the cost matrix\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
dmat[i][j] = in.nextInt();
dmat[i][i]=0;
dist[i][j]=dmat[i][j];
via[i][j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(dist[i][j]>dmat[i][k]+dist[k][j])
{
dist[i][j]=dist[i][k]+dist[k][j];
via[i][j]=k;
count++;
}
}
while(count!=0);
for(i=0;i<n;i++)
{
System.out.println("state value for router"+i+" is");
for(j=0;j<n;j++)
{
System.out.println("To "+j+" -Via "+via[i][j]+" distance is
"+dist[i][j]);
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
}
}
}
}
Output:
enter the number of nodes
4
enter the cost matrix
0 3 23 999
999 0 2 999
999 999 999 5
999 999 999 999
state value for router0 is
To 0 -Via 0 distance is 0
To 1 -Via 1 distance is 3
To 2 -Via 1 distance is 5
To 3 -Via 2 distance is 10
state value for router1 is
To 0 -Via 0 distance is 999
To 1 -Via 1 distance is 0
To 2 -Via 2 distance is 2
To 3 -Via 2 distance is 7
state value for router2 is
To 0 -Via 0 distance is 999
To 1 -Via 1 distance is 999
To 2 -Via 2 distance is 0
To 3 -Via 3 distance is 5
state value for router3 is
To 0 -Via 0 distance is 999
To 1 -Via 1 distance is 999
To 2 -Via 2 distance is 999
To 3 -Via 3 distance is 0
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Experiment 3
Using TCP/IP sockets, write a client – server program to make the client send the file
name and to make the server send back the contents of the requested file if present.
Theory:
Procedure:
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
import java.net.*;
import java.io.*;
public class TCPServer
{
public static void main(String args[]) throws Exception
{
ServerSocketsersock=new ServerSocket(4000);
System.out.println("Server ready for Connection");
Socket sock=sersock.accept();
System.out.println("Connection is Successful and waiting for chatting");
InputStreamistream=sock.getInputStream();
BufferedReaderfileRead=new BufferedReader(new InputStreamReader(istream));
String fname=fileRead.readLine();
BufferedReadercontentRead=new BufferedReader(new FileReader(fname));
OutputStreamostream=sock.getOutputStream();
PrintWriterpwrite=new PrintWriter(ostream,true);
String str;
while((str=contentRead.readLine())!=null)
{
pwrite.println(str);
}
sock.close();
sersock.close();
pwrite.close();
fileRead.close();
contentRead.close();
}
}
import java.net.*;
import java.io.*;
public class TCPClient
{
public static void main(String args[]) throws Exception {
Socket sock=new Socket("127.0.0.1",4000);
System.out.println("Enter the filename");
BufferedReaderkeyRead=new BufferedReader(new InputStreamReader(System.in));
String fname=keyRead.readLine();
OutputStreamostream=sock.getOutputStream();
PrintWriterpwrite=new PrintWriter(ostream,true);
pwrite.println(fname);
InputStreamistream=sock.getInputStream();
BufferedReadersocketRead=new BufferedReader(new InputStreamReader(istream));
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
String str;
while((str=socketRead.readLine())!=null)
{
System.out.println(str);
}
pwrite.close();
socketRead.close();
keyRead.close();
}
}
Output:
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Experiment No 4
Client-Server Program using UDP Socket
Problem Statement
Write a program on datagram socket for client/server to display the messages on client side,
typed at the server side.
Theory
Procedure:
import java.io.*;
import java.net.*;
class UDPServer
{
public static void main(String args[ ]) throws Exception
{
BufferedReaderinFromUser=new BufferedReader(new InputStreamReader(System.in));
DatagramSocketserverSocket=new DatagramSocket(11117);
byte[ ] receiveData=new byte[1024];
byte[ ] sendData=new byte[1024];
while(true)
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
{
DatagramPacketreceivePacket=new
DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence=new String(receivePacket.getData( ));
System.out.println("Client Message:"+sentence);
InetAddressIPAddress=receivePacket.getAddress( );
int port=receivePacket.getPort( );
String message=inFromUser.readLine( );
sendData=message.getBytes( );
DatagramPacketsendPacket=new DatagramPacket(sendData, sendData.length,
IPAddress, port);
serverSocket.send(sendPacket);
}
}
}
// UDP Client Program
import java.net.*;
class UDPClient
{
public static void main(String args[ ]) throws Exception
{
DatagramSocketclientSocket=new DatagramSocket( );
InetAddressIPAddress=InetAddress.getByName("127.0.0.1");
byte[] sendData=new byte[1024];
byte[] receiveData=new byte[1024];
String sentence= "Hi, I am Client. Send me a message";
sendData=sentence.getBytes( );
DatagramPacketsendPacket=new DatagramPacket(sendData,sendData.length, IPAddress,
11117);
clientSocket.send(sendPacket);
DatagramPacketreceivePacket=new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
String reply=new String(receivePacket.getData( ));
System.out.println("From Server:" + reply);
clientSocket.close( );
}
}
Output:
run udpserver.java program
run client.java program
Experiment No 5
RSA Algorithm
Problem Statement
Write a program for simple RSA algorithm to encrypt and decrypt the data.
Theory
Cryptography is the study of creating ciphers(cipher text) and breaking them (cryptanalysis). The
message to be encrypted, known as the plaintext, are transformed by a function that is parameterized by a
key. The output of the encryption process, known as the ciphertext, is then transmitted. often by
messenger or radio. The hacker, or intruder, hears and accurately copies down the complete ciphertext.
However, unlike the intended recipient, he does not know the decryption key and so cannot decrypt the
ciphertext easily.
There are several ways of classifying cryptographic algorithms. They are generally categorized based
on the number of keys that are employed for encryption and decryption, and further defined by their
application and use. The three types of algorithms are as follows:
1. Secret Key Cryptography (SKC): Uses a single key for both encryption and decryption. It is also
known as symmetric cryptography.
2. Public Key Cryptography (PKC): Uses one key for encryption and another for decryption. It is also
known as asymmetric cryptography.
3. Hash Functions: Uses a mathematical transformation to irreversibly "encrypt" information
Public-key cryptography has been said to be the most significant new development in cryptography.
Modern PKC was first described publicly by Stanford University professor Martin Hellman and graduate
student Whitfield Diffie in 1976. In public key cryptography, one key is used to encrypt the plaintext and
the other key is used to decrypt the ciphertext.
In PKC, one of the keys is designated the public key and may be advertised as widely as the owner
wants. The other key is designated the private key and is never revealed to another party. It is straight
forward to send messages under this scheme. Public key of the receiver is used for encryption, so that
only the receiver can decrypt the message (using his private key).
The RSA algorithm is named after Ron Rivest, Adi Shamir and Len Adleman, who invented it in
1977. The RSA algorithm can be used for both public key encryption and digital signatures.
Algorithm
1. Generate two large random primes, P and Q, of approximately equal size.
2. Compute N = P x Q
3. Compute Z = (P-1) x (Q-1).
4. Choose an integer E, 1 <E<Z, such that GCD (E, Z) = 1
5. Compute the secret exponent D, 1 <D<Z, such that E x D ≡ 1 (mod Z)
6. The public key is (N, E) and the private key is (N, D).
The message is encrypted using public key and decrypted using private key.
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
^D
To check decryption we compute Message’ = C mod N
^7
= 13 mod 33
= 7.
Note that we don't have to calculate the full value of 13 to the power 7 here. We can make use of the
fact that a = bc mod n = (b mod n).(c mod n) mod n so we can break down a potentially large number into
its components and combine the results of easier, smaller calculations to calculate the final value.
Program:
importjava.util.*;
importjava.math.BigInteger;
importjava.lang.*;
class RSA
{
publicstaticvoid main(String[ ] args)
{
Random rand1=new Random(System.currentTimeMillis( ));
Random rand2=new Random(System.currentTimeMillis( )*10);
intpubkey=2;
BigInteger p=BigInteger.probablePrime(32, rand1);
BigInteger q=BigInteger.probablePrime(32, rand2);
BigInteger n=p.multiply(q);
BigInteger p_1=p.subtract(newBigInteger("1"));
BigInteger q_1=q.subtract(newBigInteger("1"));
BigInteger z=p_1.multiply(q_1);
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
while(true)
{
BigInteger GCD=z.gcd(newBigInteger(""+pubkey));
if(GCD.equals(BigInteger.ONE))
{
break;
}
pubkey++;
}
BigIntegerbig_pubkey=newBigInteger(""+pubkey);
BigIntegerprvkey=big_pubkey.modInverse(z);
System.out.println("public key : "+big_pubkey+","+n);
System.out.println("private key : "+prvkey+","+n);
//RSA Encryption and Decryption
Scanner sc = new Scanner(System.in);
System.out.println("Enter the message to be encrypted");
String msg = sc.nextLine( );
Output:
public key : 5,13806019430595312251
private key : 5522407769265360173,13806019430595312251
Enter the message to be encrypted
acharya
Cipher text: 8587340257
Plain text:a
Cipher text: 9509900499
Plain text:c
Cipher text: 12166529024
Plain text:h
Cipher text: 8587340257
Plain text:a
Cipher text: 19254145824
Plain text:r
Cipher text: 25937424601
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Plain text:y
Cipher text: 8587340257
Plain text:a
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Experiment No 6
Leaky Bucket
Problem Statement
Write a program for congestion control using leaky bucket algorithm.
Theory
The congesting control algorithms are basically divided into two groups: open loop and closed loop.
Open loop solutions attempt to solve the problem by good design, in essence, to make sure it does not
occur in the first place. Once the system is up and running, midcourse corrections are not made. Open
loop algorithms are further divided into ones that act at source versus ones that act at the destination.
In contrast, closed loop solutions are based on the concept of a feedback loop if there is any
congestion. Closed loop algorithms are also divided into two sub categories: explicit feedback and
implicit feedback. In explicit feedback algorithms, packets are sent back from the point of congestion to
warn the source. In implicit algorithm, the source deduces the existence of congestion by making local
observation, such as the time needed for acknowledgment to come back.
The presence of congestion means that the load is (temporarily) greater than the resources (in part of
the system) can handle. For subnets that use virtual circuits internally, these methods can be used at the
network layer.
Another open loop method to help manage congestion is forcing the packet to be transmitted at a more
predictable rate. This approach to congestion management is widely used in ATM networks and is called
traffic shaping.
The other method is the leaky bucket algorithm. Each host is connected to the network by an interface
containing a leaky bucket, that is, a finite internal queue. If a packet arrives at the queue when it is full,
the packet is discarded. In other words, if one or more process are already queued, the new packet is
unceremoniously discarded. This arrangement can be built into the hardware interface or simulate d by
the host operating system. In fact it is nothing other than a single server queuing system with constant
service time.
The host is allowed to put one packet per clock tick onto the network. This mechanism turns an
uneven flow of packet from the user process inside the host into an even flow of packet onto the network,
smoothing out bursts and greatly reducing the chances of congestion.
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Program
importjava.util.*;
classcongestioncontrol
{
publicstaticvoid main(String[ ] args)
{
int time, output_rate, max_buffer_size, num_of_pkts, count=0, cur_buffer_size=0;
Scanner in = new Scanner(System.in);
time=0;
count=0;
while(count <num_of_pkts)
{
if(time==arr_time_of_pkts[count])
{
Random rn = new Random();
pkt_size[count] = (rn.nextInt(10)+1) * 10;
System.out.println("Packet "+(count+1)+" has arrived & its size is:" +pkt_size[count]);
System.out.println("Current Size of buffer:"+cur_buffer_size);
if (cur_buffer_size + pkt_size [count] <max_buffer_size)
{
cur_buffer_size += pkt_size[count];
@ Copyrights
Computer Network Laboratory Dept. Of ISE, AcIT, Bangalore
Output:
Enter the maximum size of buffer
40
Enter the output rate of packets from the buffer
30
Enter the number of arriving packets
5
Enter the time of arrival of packets
1
2
2
3
4
Packet 1 has arrived & its size is:30
Current Size of buffer:0
Packet1 arriving at 1 is CONFORMING PACKET
Viva Questions
1) What is a Link?
A link refers to the connectivity between two devices. It includes the type of cables and
protocols used in order for one device to be able to communicate with the other.
4) What is a LAN?
LAN is short for Local Area Network. It refers to the connection between computers and other
network devices that are located within a small physical location.
5) What is a node?
A node refers to a point or joint where a connection takes place. It can be computer or device
that is part of a network. Two or more nodes are needed in order to form a network connection.
@ Copyrights
9) What is subnet mask?
A subnet mask is combined with an IP address in order to identify two parts: the extended
network address and the host address. Like an IP address, a subnet mask is made up of 32 bits.
15) What is the job of the Network Layer under the OSI reference model?
The Network layer is responsible for data routing, packet switching and control of network
congestion. Routers operate under this layer.
16) How does a network topology affect your decision in setting up a network?
Network topology dictates what media you must use to interconnect devices. It also serves as
basis on what materials, connector and terminations that is applicable for the setup.
@ Copyrights
WAN stands for Wide Area Network. It is an interconnection of computers and devices that are
geographically dispersed. It connects networks that are located in different regions and countries.
23) What are proxy servers and how do they protect computer networks?
Proxy servers primarily prevent external users who identifying the IP addresses of an internal
network. Without knowledge of the correct IP address, even the physical location of the network
cannot be identified. Proxy servers can make a network virtually invisible to external users.
25) What is the importance of implementing a Fault Tolerance System? Are there
limitations?
A fault tolerance system ensures continuous data availability. This is done by eliminating a single
point of failure. However, this type of system would not be able to protect data in some cases,
such as in accidental deletions.
30) What is OSI and what role does it play in computer networks?
OSI (Open Systems Interconnect) serves as a reference model for data communication. It is made
up of 7 layers, with each layer defining a particular aspect on how network devices connect and
@ Copyrights
communicate with one another. One layer may deal with the physical media used, while another
layer dictates how data is actually transmitted across the network.
31) What is the purpose of cables being shielded and having twisted pairs?
The main purpose of this is to prevent crosstalk. Crosstalks are electromagnetic interferences or
noise that can affect data being transmitted across cables.
34) What is the equivalent layer or layers of the TCP/IP Application layer in terms of OSI
reference model?
The TCP/IP Application layer actually has three counterparts on the OSI model: the Session
layer, Presentation Layer and Application Layer.
@ Copyrights
42) Give some examples of private network addresses.
10.0.0.0 with a subnet mask of 255.0.0.0
172.16.0.0 with subnet mask of 255.240.0.0
192.168.0.0 with subnet mask of 255.255.0.0
51) What protocol can be applied when you want to transfer files between different
platforms, such between UNIX systems and Windows servers?
Use FTP (File Transfer Protocol) for file transfers between such different servers. This is
possible because FTP is platform independent.
@ Copyrights
Default gateways provide means for the local networks to connect to the external network. The
default gateway for connecting to the external network is usually the address of the external
router port.
53) One way of securing a network is through the use of passwords. What can be
considered as good passwords?
Good passwords are made up of not just letters, but by combining letters and numbers. A
password that combines uppercase and lowercase letters is favorable than one that uses all upper
case or all lower case letters. Passwords must be not words that can easily be guessed by hackers,
such as dates, names, favorites, etc. Longer passwords are also better than short ones.
57) What happens when you use cables longer than the prescribed length?
Cables that are too long would result in signal loss. This means that data transmission and reception
would be affected, because the signal degrades over length.
@ Copyrights
63) What advantages does fiber optics have over other media?
One major advantage of fiber optics is that is it less susceptible to electrical interference. It also
supports higher bandwidth, meaning more data can be transmitted and received. Signal degrading
is also very minimal over long distances.
65) What are the different network protocols that are supported by Windows RRAS
services?
There are three main network protocols supported: NetBEUI, TCP/IP, and IPX.
66) What are the maximum networks and hosts in a class A, B and C network?
For Class A, there are 126 possible networks and 16,777,214 hosts
For Class B, there are 16,384 possible networks and 65,534 hosts
For Class C, there are 2,097,152 possible networks and 254 hosts
68) What protocols fall under the Application layer of the TCP/IP stack?
The following are the protocols under TCP/IP Application layer: FTP, TFTP, Telnet and SMTP.
69) You need to connect two computers for file sharing. Is it possible to do this without
using a hub or router?
Yes, you can connect two computers together using only one cable. A crossover type cable can
be use in this scenario. In this setup, the data transmit pin of one cable is connected to the data
receive pin of the other cable, and vice versa.
@ Copyrights
74) When you move the NIC cards from one PC to another PC, does the MAC address gets
transferred as well?
Yes, that's because MAC addresses are hard-wired into the NIC circuitry, not the PC. This also
means that a PC can have a different MAC address when the NIC card was replace by another
one.
76) In a network that contains two servers and twenty workstations, where is the best place
to install an Anti-virus program?
An anti-virus program must be installed on all servers and workstations to ensure protection. That's
because individual users can access any workstation and introduce a computer virus when plugging
in their removable hard drives or flash drives.
@ Copyrights
Authentication is the process of verifying a user's credentials before he can log into the network.
It is normally performed using a username and password. This provides a secure means of
limiting the access from unwanted intruders on the network.
86) What are the different technologies involved in establishing WAN links?
Analog connections - using conventional telephone lines; Digital connections - using digitalgrade
telephone lines; switched connections - using multiple sets of links between sender and receiver
to move data.
90) How does dynamic host configuration protocol aid in network administration?
Instead of having to visit each client computer to configure a static IP address, the network
administrator can apply dynamic host configuration protocol to create a pool of IP addresses
known as scopes that can be dynamically assigned to clients.
@ Copyrights
Rights refer to the authorized permission to perform specific actions on the network. Each user on
the network can be assigned individual rights, depending on what must be allowed for that user.
@ Copyrights