FInal Lab
FInal Lab
FInal Lab
PART-A
1. 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.
#The below code is used to set the queue size b/w the nodes
#The below code sets the udp0 packets to red and udp1
proc finish { } {
global ns nf tf
$ns flush-trace
close $tf
close $nf
exit 0
$ns run
BEGIN{
count=0;
if($1=="d")
count++
END{
OUTPUT:
Topology Output
Trace File
puts " The node [$node_ id] received an reply from $from
proc finish {} {
global ns nf tf
$ns flush-trace
close $tf
close $nf
exit 0
#to n6 and when the time becomes 1.5 the link between n2 to
#n6 is enabled.
$ns run
BEGIN{
count=0;
if($1=="d")
count++
END{
OUTPUT:
Topology Output
Trace File
3. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot
congestion window for different source / destination.
$ns make-lan "$n0 $n1 $n2 $n3" 10mb 10ms LL Queue/DropTail Mac/802_3
proc finish { } {
global nf tf ns
$ns flush-trace
close $nf
close $tf
exit 0
$ns run
BEGIN{
if($6=="cwnd_")
END{
puts "DONE"
OUTPUT:
[root@localhost~]# ns lb3.tcl
4. Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and
determine the performance with respect to transmission of packets.
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail \
-ifqLen 50 \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-propType Propagation/TwoRayGround \
-antType Antenna/OmniAntenna \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON
create-god 3
$n0 set X_ 50
$n0 set Y_ 50
$n0 set Z_ 0
$n1 set Z_ 0
$n2 set Z_ 0
proc finish {} {
global ns nf tf
$ns flush-trace
close $tf
exit 0
$ns run
BEGIN{
count1=0
count2=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{
((count1*pack1*8)/(time1*1000000)))
OUTPUT:
[root@localhost~]# ns lb4.tcl
Trace File
Part B
1. Write a program for error detecting code using CRC-CCITT (16- bits).
import java.io.*;
class Crc
int[ ] data;
int[ ]div;
int[ ]divisor;
int[ ]rem;
int[ ] crc;
data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
data[i]=Integer.parseInt(br.readLine());
divisor_bits=Integer.parseInt(br.readLine());
divisor=new int[divisor_bits];
divisor[i]=Integer.parseInt(br.readLine());
tot_length=data_bits+divisor_bits;
div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
for(int i=0;i<data.length;i++)
div[i]=data[i];
System.out.print(div[i]);
System.out.println();
rem[j] = div[j];
for(int i=0;i<div.length;i++)
crc[i]=(div[i]^rem[i]);
System.out.println();
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
/*-------------------ERROR DETECTION---------------------*/
System.out.println();
crc[i]=Integer.parseInt(br.readLine());
rem[j] = crc[j];
if(rem[i]!=0)
System.out.println("Error");
break;
if(i==rem.length-1)
System.out.println("No Error");
int cur=0;
while(true)
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
cur++;
if((rem.length-cur)<divisor.length)
break;
return rem;
OUTPUT:
2. Write a program to find the shortest path between vertices using bellman-ford algorithm.
import java.util.Scanner;
this.num_ver = num_ver;
D[node] = MAX_VALUE;
D[source] = 0;
if (A[sn][dn] != MAX_VALUE)
if (A[sn][dn] != MAX_VALUE)
int num_ver = 0;
int source;
num_ver = scanner.nextInt();
A[sn][dn] = scanner.nextInt();
if (sn == dn)
A[sn][dn] = 0;
continue;
if (A[sn][dn] == 0)
A[sn][dn] = MAX_VALUE;
source = scanner.nextInt();
b.BellmanFordEvaluation(source, A);
scanner.close();
OUTPUT 1:
OUTPUT 2:
3.a) 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.*;
String fname=keyRead.readLine();
OutputStream Ostream=sock.getOutputStream();
pwrite.println(fname);
InputStream istream=sock.getInputStream();
String str;
while((str=socketRead.readLine())!=null)
System.out.println(str);
pwrite.close();
socketRead.close();
keyRead.close();
3.b) 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.*;
Socket sock=sersock.accept();
InputStream istream=sock.getInputStream();
String fname=fileRead.readLine();
String str;
while((str=contentRead.readLine())!=null)
pwrite.println(str);
sock.close();
sersock.close();
pwrite.close();
fileRead.close();
contentRead.close();
OUTPUT:
4.A) Write a program on datagram socket for client/server to display the messages on client
side, typed at the server side.
import java.io.*;
import java.net.*;
class UDPClient
{
public static void main(String args[]) throws Exception
{
BufferedReader inFromUser = new BufferedReader(newInputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress= InetAddress.getByName("localhost");
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData,receiveData.length);
clientSocket.receive(receivePacket);
import java.io.*;
import java.net.*;
while(true)
serverSocket.receive(receivePacket);
InetAddress IPAddress=receivePacket.getAddress();
sendData=sentence1.getBytes();
serverSocket.send(sendPacket);
OUTPUT:
5. Write a program for simple RSA algorithm to encrypt and decrypt the data.
import java.util.*;
import java.io.*;
while(n!=0)
int r=m%n;
m=n;
n=r;
return m;
int p=0,q=0,n=0,e=0,d=0,phi=0;
int i=0,j=0,nofelem=0;
String message ;
message= sc.nextLine();
p=sc.nextInt();
q=sc.nextInt();
n=p*q;
phi=(p-1)*(q-1);
for(i=2;i<phi;i++)
if(gcd(i,phi)==1) break;
e=i;
for(i=2;i<phi;i++)
if((e*i-1)%phi==0)
break;
d=i;
for(i=0;i<message.length();i++)
char c = message.charAt(i);
int a =(int)c;
nummes[i]=c-96;
nofelem=message.length();
for(i=0;i<nofelem;i++)
encrypted[i]=1;
for(j=0;j<e;j++)
encrypted[i] =(encrypted[i]*nummes[i])%n;
for(i=0;i<nofelem;i++)
System.out.print(encrypted[i]);
System.out.print((char)(encrypted[i]+96));
for(i=0;i<nofelem;i++)
decrypted[i]=1;
for(j=0;j<d;j++)
decrypted[i]=(decrypted[i]*encrypted[i])%n;
for(i=0;i<nofelem;i++)
System.out.print((char)(decrypted[i]+96));
System.out.println();
return;
OUTPUT:
import java.util.*;
int bucket_size;
int out_rate,no_packets,tot_size=0;
bucket_size=s.nextInt();
no_packets=s.nextInt();
for(int i=0;i<no_packets;i++)
in_size[i]=s.nextInt();
if((tot_size+in_size[i]<=bucket_size))
tot_size=tot_size+in_size[i];
else
continue;
out_rate=s.nextInt();
int sent_pkts=1;
while((out_rate<=temp))
sent_pkts=sent_pkts+1;
temp=temp-out_rate;
OUTPUT: