21CS52 CN Lab Manual
21CS52 CN Lab Manual
K R CIRCLE.BENGALURU 560001
FACULTY INCHARGE:
Dr. SOMESHA M
ASSISTANT PROFESSOR
DEPT OF CSE
PROGRAM LIST
Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and
2 determine the performance with respect to transmission of packets.
Implement an Ethernet LAN using n nodes and set multipletraffic nodes and plot
4 congestion window for different source / destination.
5 Write a program for error detecting code using CRC-CCITT (16- bits).
6 Write a program to find the shortest path between vertices using bellman-ford algorithm.
lab1.tcl
set ns [new Simulator]
lab1.awk
BEGIN {
c=0;
}
{
if($1=="d")
{ c++;
}
}
END{
printf("the number of packets dropped=%d\n",c);
}
Commands:
gedit lab1.tcl (to open the tcl program file, type the program andsave.)
gedit lab1.awk (to open the awk program file, type the program andsave)
Trace file:
Program 2: Implement simple ESS and with transmitting nodes in wire-less LAN by
simulation and determine the performance with respect to transmission ofpackets.
lab2.tcl
god 3
lab2.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\n",
((count2*pack2*8)/(time2*1000000)));
}
Commands:
gedit lab2.tcl (to open the tcl program file, type the program andsave.)
gedit lab2.awk (to open the awk program file, type the program andsave)
Topology:
Trace file:
Here “M” indicates mobile nodes, “AGT” indicates Agent Trace, “RTR”
indicates Router Trace.
Output:
Program 3: 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.
lab3.tcl
set ns [ new Simulator ]
lab3.awk
BEGIN {
c=0;
}
{
if($1=="d")
{ c++;
}
}
END{
printf("the number of packets dropped=%d\n",c)
}
Commands:
gedit lab3.tcl (to open the tcl program file, type the program andsave.)
gedit lab3.awk (to open the awk program file, type the program and save)ns lab3.tcl (to execute and
Output Topology
Output:
Program 4: Implement an Ethernet LAN using n nodes and set multiple trafficnodes and
plot congestion window for different source/destination.
lab4.tcl
$ns make-lan "$n0 $n1 $n2 $n3 $n4" 100Mb 100ms LL Queue/DropTailMac/802_3
lab4.awk
BEGIN {
}
{
if($6=="cwnd_") printf("%f\t%f\t\n",$1,$7);
} END {
}
Commands:
gedit lab4.tcl (to open the tcl program file, type the program andsave.)
gedit lab4.awk (to open the awk program file, type the program andsave)
Output Topology:
Output:
Program 5: Write a program for error detecting code using CRC-CCITT (16-bits).
CRC.java
import java.io.*;
class CRC
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[ ] data;
int[ ] div; int[ ] divisor; int[ ] rem;
int[ ] crc;
int data_bits, divisor_bits, tot_length; System.out.println("Enter number of
data bits : ");data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
System.out.println("Enter data bits : ");
for(int i=0; i<data_bits; i++) data[i]=Integer.parseInt(br.readLine());
System.out.println("Enter number of bits in divisor : ");
divisor_bits=Integer.parseInt(br.readLine());
divisor=new int[divisor_bits]; System.out.println("Enter Divisor
bits : ");for(int i=0; i<divisor_bits; i++)
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];
/* CRC GENERATION */
for(int i=0;i<data.length;i++)div[i]=data[i];
System.out.print("Dividend (after appending 0's) are : ");
for(int i=0; i< div.length; i++)
System.out.print(div[i]);
System.out.println();
for(int j=0; j<div.length; j++)
{
rem[j] = div[j];
}
rem=divide(div,divisor,rem);
for(int i=0;i<div.length;i++) //append dividend and remainder
{
crc[i]=(div[i]^rem[i]);
}
System.out.println(); System.out.println("CRC code
: ");for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
/* ERROR DETECTION */
System.out.println();
System.out.println("Enter CRC code of "+tot_length+" bits :
1) Without Error
2) With Error
Program 6: Program to find the shortest path between vertices usingbellman-ford algorithm.
BellmanFord.java
import java.util.Scanner;
public class BellmanFord
{
private int D[];
private int num_ver;
public static final int MAX_VALUE = 999;
Output:
Program 7: Write a Java Program Congestion control using Leaky BucketAlgorithm.
Leaky.java
import java.util.*;
public class Leaky
{
static int min(int x,int y)
{
if(x<y)
return x;
else
return y;
}
public static void main(String[] args)
{
int drop=0,mini,nsec,cap,count=0,i,process;
int inp[]=new int[25];
Scanner sc=new Scanner(System.in); System.out.print("Enter The
Bucket Size : ");cap= sc.nextInt();
System.out.print("Enter The Operation Rate : ");
process= sc.nextInt();
System.out.print("Enter the no. of seconds you want tosimulate : ");
nsec=sc.nextInt();
for(i=0;i<nsec;i++)
{
System.out.print("Enter the size of the packet enteringat "+ i+1 + " sec ");
inp[i] = sc.nextInt();
}
System.out.println("\nSecond | Packet Received | Packet Sent |Packet Left | Packet
Dropped|\n");
for(i=0;i<nsec;i++)
{
count+=inp[i];
if(count>cap)
{
drop=count-cap;
count=cap;
}
System.out.print(i+1);
System.out.print("\t\t"+inp[i]);
mini=min(count,process);
System.out.print("\t\t"+mini); count=count-
mini; System.out.print("\t\t"+count);
System.out.print("\t\t"+drop);drop=0;
System.out.println();
}
for(;count!=0;i++)
{
if(count>cap)
{
drop=count-cap;
count=cap;
}
System.out.print(i+1);
System.out.print("\t\t0");
mini=min(count,process);
System.out.print("\t\t"+mini);
count=count-mini;
System.out.print("\t\t"+count);
System.out.print("\t\t"+drop);
System.out.println();
}
}
}
Output: