Network Lab -2022 (1)
Network Lab -2022 (1)
1. Simulate a three nodes point-to-point network with dulpex links between them.Set
the queue size and vary the bandwidth and find the number of packets dropped.
PROCEDURE
#===================================
# Simulation parameters setup
#===================================
set val(stop) 20.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 3 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
1
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 1.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 5
$ns duplex-link $n0 $n2 1.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 5
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n2 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 20.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam p1.nam &
exec echo "number of packets dropped is "&
exec grep -c "^d"pgm1.tr &
exit 0
}
2
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
3
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
Procedure
#===================================
# Simulation parameters setup
#===================================
set val(stop) 20.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Nodes Definition
#===================================
#Create 6 nodes
set n0 [$ns node]
4
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n1 1.0Mb 10ms DropTail
$ns queue-limit $n0 $n1 5
$ns duplex-link $n2 $n1 1.0Mb 10ms DropTail
$ns queue-limit $n2 $n1 5
$ns duplex-link $n2 $n3 1.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 5
$ns duplex-link $n3 $n4 1.0Mb 10ms DropTail
$ns queue-limit $n3 $n4 5
$ns duplex-link $n4 $n5 1.0Mb 10ms DropTail
$ns queue-limit $n4 $n5 5
#===================================
# Agents Definition
#===================================
#Setup a TCP connection
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0
set sink2 [new Agent/TCPSink]
$ns attach-agent $n3 $sink2
$ns connect $tcp0 $sink2
$tcp0 set packetSize_ 1500
5
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP connection
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp0
$ns at 1.0 "$ftp1 start"
$ns at 20.0 "$ftp1 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
6
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam p2.nam &
puts " no of packets dropped"
exec grep "^d" p2.tr | grep -c "ping" &
exit 0
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
7
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
3. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot
congestion window for different source / destination.
PROCEDURE
#===================================
# Simulation parameters setup
#===================================
set val(stop) 20.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
8
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Links Definition
#===================================
#Createlinks between nodes
$ns duplex-link $n0 $n2 1.0Mb 10ms DropTail
$ns queue-limit $n0 $n2 5
$ns duplex-link $n1 $n2 1.0Mb 10ms DropTail
$ns queue-limit $n1 $n2 5
$ns duplex-link $n2 $n3 1.0Mb 10ms DropTail
$ns queue-limit $n2 $n3 5
set lan [$ns newLan "$n3 $n4 $n5 $n6 $n7 $n8 $n9 $n10" 0.5mb 100ms ll
Queue/DropTail MAC/802_3 channel]
#Give node position (for NAM)
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right-up
#===================================
# Agents Definition
#===================================
#Setup a TCP/Reno connection
set tcp0 [new Agent/TCP/Reno]
$ns attach-agent $n0 $tcp0
set sink1 [new Agent/TCPSink]
$ns attach-agent $n10 $sink1
$ns connect $tcp0 $sink1
$tcp0 set packetSize_ 1500
9
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Applications Definition
#===================================
#Setup a FTP Application over TCP/Reno connection
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 "$ftp0 start"
$ns at 1.0 "plot $tcp0 $r"
$ns at 20.0 "$ftp0 stop"
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam p3.nam &
exec xgraph reno vegas tahoe &
exit 0
}
proc plot { tcps file} {
global ns
set now [$ns now]
set cwnd [$tcps set cwnd_]
puts $file "$now $cwnd"
$ns at [expr $now+0.1] "plot $tcps $file"
10
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run
11
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
4. Implement simple ESS and with transmitting nodes in wire-less LAN by simulation
and determine the performance with respect to transmission of packets.
PROCEDURE
Open the terminal.
Execute java –jar nsg2.jar.
In scenario, select new wireless scenario.
Select nodes, create nodes.
In links,select duplex-link and connect.
Apply udp and null between two nodes and establish a peer-peer connection between
them.
In application ,selectcbr for udp agent.
Set bandwidth and queue - size
In parameters set the simulation time.
Gototcl and code will be generated.
#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 7 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 1091 ;# X dimension of topography
set val(y) 781 ;# Y dimension of topography
set val(stop) 200.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
12
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 7 nodes
set n0 [$ns node]
$n0 set X_ 604
$n0 set Y_ 681
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 399
$n1 set Y_ 599
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 798
$n2 set Y_ 602
$n2 set Z_ 0.0
13
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n3 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n6 $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
$ns at 1.0 "$cbr0 start"
$ns at 200.0 "$cbr0 stop"
#===================================
# Termination
#===================================
14
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
15
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
16
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
5. Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or
equivalent environment.
PROCEDURE
17
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
18
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
19
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
puts "........................................"
for {set i 0} {$i < $val(nn) } {incr i} {
set k 0
for { set j 0} {$j < $val(nn) } {incr j} {
set a [expr $X1($j)-$X1($i)]
set b [expr $a*$a]
set c [expr $Y1($j)-$Y1($i)]
set d [expr $c*$c]
set e [expr $b+$d]
set f 0.5
set g [expr pow($e,$f)]
if {$g <= 200 && $i != $j} {
puts "| node($i) | node($j) |"
set nei($m) $j
set k [expr $k+1]
set m [expr $m+1]
}
}
puts "........................................"
}
puts "Loading connection pattern...."
puts "Loading scenario file...."
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp2 [new Agent/UDP]
$ns attach-agent $n0 $udp2
set sink [new Agent/LossMonitor]
$ns attach-agent $n9 $sink
$ns connect $udp2 $sink
$udp2 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr3 [new Application/Traffic/CBR]
$cbr3 attach-agent $udp2
$cbr3 set packetSize_ 1000
$cbr3 set rate_ 1.0Mb
$cbr3 set random_ null
$ns at 1.0 "$cbr3 start"
$ns at 50.0 "$cbr3 stop"
set holdtime 0
set holdseq 0
set holdrate1 0
proc record {} {
global sink f0 f1 f2 holdtime holdseq holdrate1
set nsi [Simulator instance]
set time 0.9 ;#set sampling time 0.9 sec
20
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
21
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
22
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
23
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
24
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
6. Implement and study the performance of CDMA on NS2/NS3 (Using stack called
Call net) or equivalent environment.
PROCEDURE
#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 20 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 1500 ;# X dimension of topography
set val(y) 800 ;# Y dimension of topography
set val(stop) 200.0 ;# time of simulation end
25
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 20 nodes
set n0 [$ns node]
$n0 set X_ 246
$n0 set Y_ 609
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
26
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
27
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
28
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# 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
$ns at 1.0 "$cbr0 start"
$ns at 200.0 "$cbr0 stop"
set holdtime 0
set holdseq 0
set holdrate1 0
proc record {} {
global sink f0 f1 f2 holdtime holdseq holdrate1
29
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile f0 f1 f2
$ns flush-trace
close $tracefile
close $namfile
exec nam p6.nam &
exec xgraph throughput.tr &
30
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
31
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
PART-B
package crc;
import java.util.*;
}
System.out.println("\n the CRC code generated is :");
for(int i=0;i<data.length;i++)
{
System.out.println(data[i]);
}
for(int i=0;i<remainder.length-1;i++)
{
System.out.println(remainder[i]);
}
System.out.println();
int sent_data[]=new int[data.length+remainder.length-1];
System.out.println("enter the DATA recevied at the receiver");
for(int i=0;i<sent_data.length;i++){
sent_data[i]=scan.nextInt();
32
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
}
recieve(sent_data,divisor);
}
static int[] divide(int old_data[],int divisor[]){
int remainder[],i;
int data[]=new int[old_data.length+divisor.length];
System.arraycopy(old_data,0,data,0,old_data.length);
remainder=new int[divisor.length];
System.arraycopy(data,0,remainder,0,divisor.length);
for(i=0;i<old_data.length;i++){
if(remainder[0]==1){
for(int j=1; j<divisor.length;j++)
{
remainder[j-1]=exor(remainder[j],divisor[j]);
}
}
else
{
for(int j=1;j<divisor.length;j++)
{
remainder[j-1]=exor(remainder[j],0);
}
}
remainder [divisor.length-1]= data[i+divisor.length];
}
return remainder;
}
static int exor(int a,int b)
{
if(a==b)
{
return 0;
}
return 1;
}
static void recieve(int data[],int divisor[]){
int remainder[]=divide(data,divisor);
for(int i=0;i<remainder.length;i++)
{
if(remainder[i]!=0)
{
System.out.println("there is an error in recieved data......");
return;
}
}
System.out.println("data recieved without any error");
}
}
33
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
34
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
8.Write a program to find the shortest path between vertices using bellman-ford algorithm.
import java.util.Scanner;
public class BellmanFord
{
private int dist[];
private int n;
public static final int MAX_VALUE=999;
public BellmanFord(int n)
{
this.n=n;
dist=new int[n+1];
}
public void BellmanFordEvaluation(int src, int adj[][])
{
for(int nd=1; nd<=n; nd++)
{
dist[nd]=MAX_VALUE;
}
dist[src]=0;
for(int nd=1; nd<=n-1; nd++)
{
for(int sn=1; sn<=n; sn++)
{
for(int dn=1; dn<=n; dn++)
{
if(adj[sn][dn]!=MAX_VALUE)
{
if(dist[dn]>dist[sn]+adj[sn][dn])
dist[dn]=dist[sn]+adj[sn][dn];
}
}
}
}
for(int sn=1; sn<=n; sn++)
{
for(int dn=1; dn<=n; dn++)
{
if(adj[sn][dn]!=MAX_VALUE)
{
if(dist[dn]>dist[sn]+adj[sn][dn])
System.out.println("The graph contains negative edge cycle.");
}
}
}
for(int vertex=1; vertex<=n; vertex++)
{
System.out.println("Distance of src"+src+"to"+vertex+"is"+dist[vertex]);
}
}
35
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
36
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
9.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.
/*client*/
import java.net.*;
import java.io.*;
import java.util.*;
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");
BufferedReader BufRead1 =new BufferedReader(new InputStreamReader(System.in));
String fname =BufRead1.readLine();
OutputStream ostream =sock.getOutputStream();
PrintWriter pw=new PrintWriter(ostream,true);
pw.println(fname);
InputStream istream =sock.getInputStream();
BufferedReader BufRead2 =new BufferedReader(new InputStreamReader(istream));
String str;
while((str=BufRead2.readLine())!=null)
{
System.out.println(str);
}
}
}
/*server*/
import java.net.*;
import java.io.*;
public class TCPServer
{
public static void main(String args []) throws Exception
{
ServerSocket sersock=new ServerSocket(4000);
System.out.println("server ready for transmission");
Socket sock=sersock.accept();
System.out.println("connection is successful and waiting for chatting");
InputStream istream=sock.getInputStream();
BufferedReader bufRead1=new BufferedReader(new InputStreamReader(istream));
String fname=bufRead1.readLine();
System.out.println("the requested file from client is:"+fname);
BufferedReader bufRead2=new BufferedReader(new FileReader(fname));
OutputStream ostream =sock.getOutputStream();
37
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
Client Side
38
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
10. Write a program on datagram socket for client/server to display the messages on
client side, typed at the server side.
/*client side*/
import java.io.*;
import java.net.*;
public class UDPClient{
public static void main(String args[]) throws Exception{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the message");
String message=in.readLine();
DatagramSocket clientSocket=new DatagramSocket();
InetAddress IPAddress=InetAddress.getByName("localhost");
byte[] sendData=new byte[1024];
byte[] receiveData=new byte[1024];
sendData=message.getBytes();
DatagramPacket sendPacket=new
DatagramPacket(sendData,sendData.length,IPAddress,9876);
clientSocket.send(sendPacket);
DatagramPacket receivePacket=new DatagramPacket(receiveData,receiveData.length);
clientSocket.receive(receivePacket);
String ServerMessage=new String(receivePacket.getData());
System.out.println("from server:"+ServerMessage);
clientSocket.close();
}
}
/*server side*/
import java.io.*;
import java.util.*;
import java.net.*;
public class UDPServer{
public static void main(String args[]) throws Exception{
while(true){
DatagramPacket receivePacket=new DatagramPacket(receiveData,receiveData.length);
ss.receive(receivePacket);
String clientmessage=new String(receivePacket.getData());
System.out.println("from client:"+clientmessage);
InetAddress IPAdd=receivePacket.getAddress();
39
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
int port=receivePacket.getPort();
String message= in.readLine();
sendData=message.getBytes();
DatagramPacket sendPacket=new DatagramPacket(sendData,sendData.length,IPAdd,port);
ss.send(sendPacket);
}
}
}
Client Side
Server Side
40
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
11. Write a program for simple RSA algorithm to encrypt and decrypt the data.
package rsa;
import java.io.*;
import java.math.BigInteger;
import java.util.Random;
public class Rsa {
private BigInteger p,q,n,z,e,d;
private int bitlength=1024;
private Random r;
public Rsa()
{
r=new Random();
p=BigInteger.probablePrime(bitlength, r);
q=BigInteger.probablePrime(bitlength, r);
n=p.multiply(q);
z=p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
e=BigInteger.probablePrime(bitlength/2, r);
while (z.gcd(e).compareTo(BigInteger.ONE)>1 && e.compareTo(z)>0)
{
e.add(BigInteger.ONE);
}
d=e.modInverse(z);
}
41
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
}
OUTPUT
42
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
12. Write a program for congestion control using leaky bucket algorithm.
package leakybucket;
import java.util.Random;
import java.util.Scanner;
System.out.println("Enter bucket size, outgoing rate,no of inputs and incoming size: ");
buck_size = Sc.nextInt();
outgoing = Sc.nextInt();
n = Sc.nextInt();
while (n != 0) {
System.out.println("Enter the incoming packet size : " );
incoming = Sc.nextInt();
if (incoming <= (buck_size - store)){
store += incoming;
System.out.println("Bucket buffer size is " + store + "out of " + buck_size);
}
else {
System.out.println("Packet Loss " + (incoming - (buck_size - store)));
store = buck_size;
System.out.println("Bucket buffer size is " + store + "out of " + buck_size);
}
store = store - outgoing;
System.out.println("After outgoing : " + store + "packets left out of " + buck_size + "in
buffer");
n--;
Thread.sleep(3000);
}
}
}
OUTPUT
43
Dept.of.CS&E, KVGCE, Sullia
COMPUTER NETWORK LABORATORY 18CSL57
44
Dept.of.CS&E, KVGCE, Sullia