CN Lab All Programs (Bcs502)
CN Lab All Programs (Bcs502)
Program 1
AIM : Implement three nodes point – to – point network with
duplex links between them. Set the queue size, vary the bandwidth,
and find the number of packets dropped.
OUTPUT:
Awk file :
REGIN,
drop=0;
-
,
if($1=="d")
,
drop++; -
- END,
printf("total no of %s type packets dropped=%d\n",$5,drop);
-
Experiment – 2
AIM:- 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.
proc finish , - ,
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam lab2.nam &
exit 0
-
REGIN,
drop=0;
-
,
if($1=="d")
,
drop++; -
- END,
printf("total no of %s type packets dropped=%d\n",$5,drop);
-
OUTPUT:
Experiment – 3
AIM:- Implement an Ethernet LAN using n nodes and set multiple
traffic nodes and plot congestion window for different source /
destination.
set ns *new Simulator+
set tf *open lab3.tr w+
$ns trace-all $tf
set nf *open lab3.nam w+
$ns namtrace-all $nf
set n0 *$ns node+
$n0 color "magenta"
$n0 label "src1"
set n1 *$ns node+
set n2 *$ns node+
$n2 color "magenta"
$n2 label "src2"
set n3 *$ns node+
$n3 color "blue"
$n3 label "dest2"
set n4 *$ns node+
set n5 *$ns node+
$n5 color "blue"
$n5 label "dest1"
$ns make-lan "$n0 $n1 $n2 $n3 $n4" 100Mb 100ms LL
Queue/DropTail Mac/802_3
$ns duplex-link $n4 $n5 1Mb 1ms DropTail
set tcp0 *new Agent/TBP+
$ns attach-agent $n0 $tcp0
set ftp0 *new Application/FTP+
$ftp0 attach-agent $tcp0
$ftp0 set packetSize_ 500
$ftp0 set interval_ 0.0001
set sink5 *new Agent/TBPSink+
$ns attach-agent $n5 $sink5
$ns connect $tcp0 $sink5
set tcp2 *new Agent/TBP+
$ns attach-agent $n2 $tcp2
set ftp2 *new Application/FTP+
$ftp2 attach-agent $tcp2
$ftp2 set packetSize_ 600
$ftp2 set interval_ 0.001
set sink3 *new Agent/TBPSink+
$ns attach-agent $n3 $sink3
$ns connect $tcp2 $sink3
set file1 *open file1.tr w+
$tcp0 attach $file1
set file2 *open file2.tr w+
$tcp2 attach $file2
$tcp0 trace cwnd_
$tcp2 trace cwnd_
proc finish ,- ,
global ns nf tf
$ns flush-trace
close $tf
close $nf
exec nam lab3.nam &
exit 0
-
$ns at 0.1 "$ftp0 start"
$ns at 5 "$ftp0 stop"
$ns at 7 "$ftp0 start"
$ns at 14 "$ftp0 stop"
$ns at 0.2 "$ftp2 start"
$ns at 8 "$ftp2 stop"
$ns at 10 "$ftp2 start"
$ns at 15 "$ftp2 stop"
$ns at 16 "finish"
$ns run
AWK FILE:
REGIN,
-
,
if($6=="cwnd_")
printf("%f\t%f\t\n",$1,$7);
- END,
-
OUTPUT:
xgraph
Experiment - 4
AIM - Write a program for error detecting code using CRC-
CCITT (16- bits)
import java.util.*;
public class p3 ,
void div(int a*+, int k) ,
int gp*+ = ,1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1-;
int count = 0;
for (int i = 0; i < k; i++) ,
if (a*i+ == gp*0+) ,
for (int j = i; j < 17 + i; j++) ,
a*j+ = a*j+ ^ gp*count+++;
-
count = 0;
-
-
-
k = len - 16;
ob.div(a, k);
System.out.println("Data to be transmitted:");
for (int i = 0; i < len; i++) ,
System.out.print(a*i+ + " ");
-
System.out.println();
System.out.println("Enter the ]eceived Data:");
for (int i = 0; i < len; i++) ,
a*i+ = sc.nextInt();
-
ob.div(a, k);
Output1 –
Enter the length of Data Frame: 4
Enter the Message: 1 0 1 1
Data to be transmitted: 1 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 1 1
Enter the ]eveived Data: 1 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 1 1
no error
Output2 –
Enter the length of Data Frame: 4
Enter the Message: 1 0 1 1
Data to be transmitted: 1 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 1 1
Enter the ]eveived Data: 1 0 1 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 0 1
error in data
Experiment - 5
AIM:-Develop a program to implement a sliding window protocol in
the data link layer.
import java.util.]andom;
import java.util.Scanner;
class SlidingWindowProtocol ,
private int windowSize;
private int totalFrames;
OUTPUT:
Experiment – 6
AIM:-Write a program to find the shortest path between
vertices using bellman-ford algorithm.
import java.util.*;
public Relmanford(int n) ,
this.n = n;
D = new int*n + 1+;
-
OUTPUT:
Experiment – 7
AIM:- 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.
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 Connection");
Socket sock=sersock.accept();
System.out.println("Connection is Successful and waiting for chatting");
InputStream istream=sock.getInputStream();
BufferedReaderfileRead=newBufferedReader(newInputStreamReader(istrea
m));
String fname=fileRead.readLine();
BufferedReader contentRead=new BufferedReader(new FileReader(fname));
OutputStream ostream=sock.getOutputStream();
PrintWriter pwrite=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.*;
OUTPUT:
Experiment – 8
AIM:- Develop a program on a datagram socket for
client/server to display the messages on client side, typed at
the server side.
import java.io.*;
import java.net.*;
public class UDPServer,
public static void main(String*+ args),
DatagramSocket skt=null;
try,
System.out.println("server is started");
skt=new DatagramSocket(6942);
byte*+ buffer = new byte*1000+;
while(true),
DatagramPacket request = new DatagramPacket
(buffer,buffer.length);
skt.receive(request);
String*+ message = (new String(request.getData())).split(" ");
byte*+ sendMsg= (message*1+.toUpperCase()+ " from server
to client.").getBytes();
DatagramPacket reply = new
DatagramPacket(sendMsg,sendMsg.length,request.getAddr
ess(),request.getPort());
skt.send(reply);
-
-
catch(Exception ex),
System.out.println(ex.getMessage());
-
-
-
import java.io.*;
import java.net.*;
public class UDPClient,
public static void main(String*+ args),
DatagramSocket skt;
try,
skt=new DatagramSocket();
String msg= "Redundant college";
byte*+ b = msg.getBytes();
InetAddress host=InetAddress.getByName("127.0.0.1");
int serverSocket=6942;
DatagramPacket request =new DatagramPacket
(b,b.length,host,serverSocket);
skt.send(request);
byte*+ buffer =new byte*2000+;
DatagramPacket reply= new
DatagramPacket(buffer,buffer.length);
skt.receive(reply);
System.out.println("client received:" +new
String(reply.getData()));
skt.close();
-
catch(Exception ex),
System.out.println(ex.getMessage());
-
-
-
OUTPUT:
Experiment – 9
AIM:- Develop a program for a simple RSA algorithm to encrypt and
decrypt the data.
import java.util.*;
import java.io.*;
n = p * q;
phi = (p - 1) * (q - 1);
System.out.println("\nEncrypted message\n");
System.out.println("\nDecrypted message\n");
Output:
Experiment – 10
AIM:- Develop a program for congestion control using a leaky
bucket algorithm.
import java.util.Scanner;