18CSL57 CN Lab Manual
18CSL57 CN Lab Manual
Koorgalli, Mysore.
Department
Of
Information Science & Engineering.
Prepared by
K B Manasa
Assistant Professor
Dept of ISE
COMPUTER NETWORK LABORATORY
[As per Choice Based Credit System (CBCS) scheme]
(Effective from the academic year 2016 -2017)
SEMESTER – V
For the experiments below modify the topology and parameters set for the experiment and take
multiple rounds of reading and analyse the results available in log files. Plot necessary Graphs and
conclude. Use NS2/NS3.
Lab Experiments:
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.
3. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion
window for different source / destination.
4. Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and determine
the performance with respect to transmission of packets.
5. Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or equivalent
environment.
6. Implement and study the performance of CDMA on NS2/NS3 (Using stack called Call net) or
equivalent environment.
PART B
7. Write a program for error detecting code using CRC-CCITT (16- bits).
8. Write a program to find the shortest path between vertices using bellman-ford algorithm.
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.
10. Write a program on datagram socket for client/server to display the messages on client side, typed
at the server side.
11. Write a program for simple RSA algorithm to encrypt and decrypt the data.
12. Write a program for congestion control using leaky bucket algorithm.
Computer Network Laboratory 18CSL57
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.
$ns run
AWK file (Open a new editor using “vi command” and write awk file and save with “.awk”
extension)
/*immediately after BEGIN should open braces ‘{‘
BEGIN { c=0;
}
{
If ($1= ="d")
{
c++;
printf("%s\t%s\n",$5,$11);
}
}
/*immediately after END should open braces ‘{‘
END{
printf("The number of packets dropped =%d\n",c);
}
//AWK File:
//gedit lab2.awk
BEGIN{
drop=0;
}
{
if($1= ="d" )
{
drop++;
}
}
END{
printf("Total number of %s packets dropped due to congestion =%d\n",$5,drop);
}
3. Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot
//gedit lab3.tcl
//gedit lab3.awk
BEGIN {
}{
if($6= ="cwnd_") /* don’t leave space after writing cwnd_ */
printf("%f\t%f\t\n",$1,$7); /* you must put \n in printf */
}
END {
}
4. Implement simple ESS and with transmitting nodes in wire-less LAN by simulation
//gedit lab4.awk
BEGIN{
count1=0
count2=0
pack1=0
pack2=0
time1=0
time2=0
}{
if($1= ="r"&& $3= ="_1_" && $4= ="AGT")
{
count1++
pack1=pack1+$6
time1=$2
}
if($1= ="r" && $3= ="_2_" && $4= ="AGT")
{
count2++
pack2=pack2+$6
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)));
}
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
set web 2 ;# number of web sessions
# 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 10nodes(ms) DropTail
$ns duplex-link $nodes(bs1) $nodes(ms) 1 1 RED
$ns duplex-link $nodes(ms) $nodes(bs2) 1 1 RED
$ns duplex-link $nodes(bs2) $nodes(is) 3Mbps 50nodes(ms) DropTail
puts " GSM Cell Topology"
}
proc set_link_para {t} {
global ns nodes bwUL bwDL propUL propDL buf
$ns bandwidth $nodes(bs1) $nodes(ms) $bwDL($t) duplex
$ns bandwidth $nodes(bs2) $nodes(ms) $bwDL($t) duplex
$ns delay $nodes(bs1) $nodes(ms) $propDL($t) duplex
$ns delay $nodes(bs2) $nodes(ms) $propDL($t) duplex
$ns queue-limit $nodes(bs1) $nodes(ms) 10
$ns queue-limit $nodes(bs2) $nodes(ms) 10
}
# RED and TCP parameters
Queue/RED set adaptive_ $adaptive
Queue/RED set thresh_ $minth
Queue/RED set maxthresh_ $maxth
Agent/TCP set window_ $window
source web.tcl
#Create topology
switch $type {
gsm -
gprs -
umts {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 nf
set wrap $opt(wrap)
set sid [$nodes($opt(srcTrace)) id]
set did [$nodes($opt(dstTrace)) id]
set a "out.tr"
set GETRC "../../../bin/getrc"
set RAW2XG "../../../bin/raw2xg"
exec $GETRC -s $sid -d $did -f 0 out.tr | \
$RAW2XG -s 0.01 -m $wrap -r > plot.xgr
exec $GETRC -s $did -d $sid -f 0 out.tr | \
$RAW2XG -a -s 0.01 -m $wrap >> plot.xgr
exec xgraph -x time -y packets plot.xgr &
exit 0
}
$ns at $stop "stop"
$ns run
6. Implement and study the performance of CDMA on NS2/NS3 (Using stack called
Call net) or equivalent environment.
Source Code:
# 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
DEPT OF ISE Page 14
Computer Network Laboratory 18CSL57
proc cell_topo {} {
global ns nodes
$ns duplex-link $nodes(lp) $nodes(bs1) 3Mbps 10nodes(ms) DropTail
$ns duplex-link $nodes(bs1) $nodes(ms) 1 1 RED
$ns duplex-link $nodes(ms) $nodes(bs2) 1 1 RED
$ns duplex-link $nodes(bs2) $nodes(is) 3Mbps 50nodes(ms) DropTail
puts " cdma Cell Topology"
}
source web.tcl
DEPT OF ISE Page 15
Computer Network Laboratory 18CSL57
#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 nf
set wrap $opt(wrap)
set sid [$nodes($opt(srcTrace)) id]
set did [$nodes($opt(dstTrace)) id]
set a "out.tr"
set GETRC "../../../bin/getrc"
set RAW2XG "../../../bin/raw2xg"
exec $GETRC -s $sid -d $did -f 0 out.tr | \
$RAW2XG -s 0.01 -m $wrap -r > plot.xgr
exec $GETRC -s $did -d $sid -f 0 out.tr | \
$RAW2XG -a -s 0.01 -m $wrap >> plot.xgr
exec xgraph -x time -y packets plot.xgr &
exit 0
}
$ns at $stop "stop"
$ns run
7. Write a program for error detecting code using CRC-CCITT (16- bits).
import java.io.*;
public class crc {
data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
System.out.println("Enter data bits : ");
divisor[i]=Integer.parseInt(br.readLine());
tot_length=data_bits+divisor_bits-1;
div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
System.out.println();
}
System.out.println();
System.out.println("CRC code : ");
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
crc[i]=Integer.parseInt(br.readLine());
rem[j] = crc[j];
}
rem=divide(crc, divisor, rem);
for(int i=0; i< rem.length; i++)
if(rem[i]!=0)
{
System.out.println("Error");
break;
}
if(i==rem.length-1)
System.out.println("No Error");
}
}
{
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
break;
}
return rem;
}
}
8. Write a program to find the shortest path between vertices using bellman-ford algorithm.
package bellman;
import java.util.Scanner;
public class BellmanFord
{
}
}
}
if(flag==1)
{
System.out.println("The Graph contains negative egde cycle");
}
else
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.
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
fis.close();
dos.close();
}
private Socket s;
int read = 0;
while((read = dis.read(buffer, 0,
(buffer.length))) > 0) {
System.out.println(new String(buffer,0,read));
fos.write(buffer, 0, read);
}
fos.close();
dis.close();
}
public static void main(String args[]) {
fileclient fc = new fileclient("localhost", 9886);
}
}
10. Write a program on datagram socket for client/server to display the messages on client
side, typed at the server side.
//UDP Client
import java.net.*;
public class client
{
public static void main(String[] args) throws Exception
{
byte[] buf = new byte[1024];
System.out.println("Receiver");
DatagramSocket ds = new DatagramSocket(3000);
while(true)
{
DatagramPacket dp = new DatagramPacket(buf, 1024);
ds.receive(dp);
String msg = new String(dp.getData(), 0, dp.getLength());
System.out.println(msg);
}
}
}
// UDP Server
import java.net.*;
import java.util.Scanner;
public class server
{
public static void main(String[] args) throws Exception
{
System.out.println("Sender");
DatagramSocket ds = new DatagramSocket();
DEPT OF ISE Page 24
Computer Network Laboratory 18CSL57
while(true)
{
String msg = scanner.nextLine();
InetAddress ip = InetAddress.getByName("127.0.0.1");
11. Write a program for simple RSA algorithm to encrypt and decrypt the data.
import java.util.*;
import java.math.BigInteger;
import java.lang.*;
class RSA
{
public static void main(String[] args)
{
Random rand1=new Random();
Random rand2=new Random();
Scanner si=new Scanner(System.in);
int pubkey=si.nextInt();//nteger.parseInt(args[0]);
BigInteger bigB_p=BigInteger.probablePrime(32, rand1);
BigInteger bigB_q=BigInteger.probablePrime(32, rand2);
BigInteger bigB_n=bigB_p.multiply(bigB_q);
BigInteger bigB_p_1=bigB_p.subtract(new BigInteger("1"));
BigInteger bigB_q_1=bigB_q.subtract(new BigInteger("1"));
BigInteger bigB_p_1_q_1=bigB_p_1.multiply(bigB_q_1);
while(true)
{
BigInteger BigB_GCD=bigB_p_1_q_1.gcd(new BigInteger(""+pubkey));
if(BigB_GCD.equals(BigInteger.ONE))
{
break;
}
pubkey++;
}
BigInteger bigB_cipherVal=bigB_val.modPow(bigB_pubkey,bigB_n);
System.out.println("Cipher text: " + bigB_cipherVal);
BigInteger bigB_plainVal=bigB_cipherVal.modPow(bigB_prvkey,bigB_n);
int plainVal=bigB_plainVal.intValue();
System.out.println("Plain text:" + plainVal);
}
}
12. Write a program for congestion control using leaky bucket algorithm.
else
{
for(int i=f;i<r;i++)
{
try
{
t.sleep(1000);
}
q. insert(size); q.delete();
catch(Exception e){}
System.out.print("\nLeaked Packet: "+q[i]);
f++;
}
}
System.out.println();
}
}
class Leaky extends Thread
{
public static void main(String ar[]) throws Exception
{
Queue q=new Queue();
Scanner src=new Scanner(System.in);
System.out.println("\nEnter the packets to be sent:");
int size=src.nextInt();
}
}