CN Manual 2022
CN Manual 2022
CN Manual 2022
A
COLLEGEOF ENGINEERING & TECHNOLOGY
RECORD BOOK
Register No:
Selvan / Selvi of
Laboratory.
Examination on 2022
PAGE MARKS
PAGE MARKS
1
FLOW CHART:
2
IMPLEMENTATION OF ERROR DETECTION AND CORRECTION TECHNIQUES
EXPT NO: 1a
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
3
PROGRAM:
#include<string.h>
char text[20],key[20],rem[20];
void crc()
{
int i,j,keylen,textlen;
char temp[100];
strcpy(temp,text);
keylen=strlen(key);
for(i=0;i<keylen-1;i++)strcat(temp,"0");
textlen=strlen(temp);
strncpy(rem,temp,keylen);
while(i!=textlen)
{
if(rem[0]=='0')
{
strcpy(rem,&rem[1]);
rem[keylen-1]=temp[++i];
rem[keylen]='\0';
continue;
}
for(j=0;j<keylen;j++)
rem[j]=((rem[j]-'0')^(key[j]-'0'))+'0';
}
}
main()
{
int i,choice;
while(1)
{
printf("\n1.Find CRC\n2.Check CRC\n3.Quit\nEnter the choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter the i/p\n");
scanf("%s",text);
printf("Enter the key\n");
scanf("%s",key);
crc();
printf("Msg %s \n",strcat(text,rem));
break;
case 2: printf("Enter the input");
scanf("%s",text);
4
OUTPUT:
5
printf("\nEnter key");
scanf("%s",key);
crc();
for(i=0;i<strlen(key)-1;i++)
if(rem[i]=='1')
break;
if(i==strlen(key)-1)
printf("NO ERROR\n");
else printf("ERROR");
break;
case 3:
exit(0);
}
}
}
RESULT
Thus, the program for 8-bit CRC was successfully executed.
6
FLOW CHART:
7
b.) ERROR CORRECTION – HAMMING CODE
EXPT NO: 1b
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
8
PROGRAM:
import java.util.Scanner;
public class hamming{
static Scanner S=new Scanner(System.in);
static int p1,p2,m1,p3,m2,m3,m4;
public static void main(String args[])
{
Generation();
check();
}
public static void Generation()
{
System.out.print("Enter the msg bits:");
m1=S.nextInt();
m2=S.nextInt();
m3=S.nextInt();
m4=S.nextInt();
System.out.print("The message bits are:");
System.out.printf("%d%d%d%d",m1,m2,m3,m4);
p1=m1^m2^m4;
p2=m1^m3^m4;
p3=m3^m2^m4;
System.out.print("\n The parity bits are:");
System.out.printf("%d%d%d",p1,p2,p3);
System.out.print("\n The encoded bits are:");
System.out.printf("%d%d%d%d%d%d%d",p1,p2,m1,p3,m2,m3,m4);
}
public static void check()
{
System.out.print("\n Enter the received data bits one by one: ");
int r1 = S.nextInt();
int r2 = S.nextInt();
int r3 = S.nextInt();
int r4 = S.nextInt();
int r5 = S.nextInt();
int r6 = S.nextInt();
int r7 = S.nextInt();
int c1= r1 ^ r3 ^ r5 ^ r7;
int c2= r2 ^ r3 ^ r6 ^ r7;
9
OUTPUT:
10
int c3= r4 ^ r5 ^ r6 ^ r7;
int c=c3*4+c2*2+c1 ;
if(c==0)
{
System.out.print("\n There is NO error: ");
} else {
System.out.println("Error on the position: "+c);
System.out.println("The correct message is:");
System.out.printf("%d%d%d%d%d%d%d",p1,p2,m1,p3,m2,m3,m4);
}
}
}
RESULT:
Thus, the program for 4-bit Hamming code error correction was successfully executed.
11
FLOW CHART:
12
2) IMPLEMENTATION OF STOP AND WAIT PROTOCOL
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
13
PROGRAM:
SENDER:
import java.io.*;
import java.net.*;
class Stopsend{
static final int port=8080;
public static void main(String args[]){
try
{
ServerSocket ss=new ServerSocket(port);
Socket s=ss.accept();
int no=0;
System.out.println("Enter the number of frames u want to transmit:");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int limit=Integer.parseInt(in.readLine());
while(no<limit)
{ if(no!=limit-1)
{
PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter ( s.getOutputStream()
)),true);
System.out.println("\nFrame"+no+" has been sent");
out.println(no);
out.println(limit);
BufferedReader brr=new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println("\nAcknowledgement "+brr.readLine()+" has been received");
no=no+1; }
else {
PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter ( s.getOutputStream()
)),true);
System.out.println("\n Frame EOT has been sent");
String str="EOT";
out.println(str);
BufferedReader brr=new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println("\nAcknowledgement "+brr.readLine()+" has been received");
no=no+1;
} }
System.out.println("\nClosing");
s.close();
}
catch(Exception e){ }
}}
14
OUTPUT:
15
RECEIVER :
import java.io.*;
import java.net.*;
class stopreceive
{
static final int port=8080;
public static void main(String args[])
{ try{
InetAddress addr=InetAddress.getByName("Localhost");
Socket s=new Socket(addr,port);
int r=10,limit=0;
while(r!=limit)
{ if(r==limit-1)
{
BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter (s.getOutputStream()
)),true);
String str=in.readLine();
System.out.println("\nFrame "+str+" has been received");
out.println(str);
System.out.println("\nAcknowledgement "+str+" has been sent");
break;
}
else
{
BufferedReader in=new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter (s.getOutputStream()
)),true);
r=Integer.parseInt(in.readLine());
limit=Integer.parseInt(in.readLine());
System.out.println("\nFrame"+r+" has been received");
out.println(r);
System.out.println("\nAcknowledgement"+r+" has been sent");
}}}
catch(Exception e){ }
}}
RESULT:
Thus, the program for stop & wait protocol was successfully executed.
16
FLOW CHART:
17
IMPLEMENTATION OF GO BACK N AND SELECTIVE REPEAT PROTOCOL
EXPT NO:3
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
18
PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int n,r;
struct frame
{
char ack;
int data;
}frm[10];
int sender(void);
void recvfrm(void);
void resend(void);
void resend1(void);
void goback(void);
void selective(void);
int main()
{
int c;
clrscr();
do {
printf("\n\n1.Selective repeat ARQ\n2.Goback ARQ\n3.exit");
printf("\nEnterur choice:");
scanf("%d",&c);
switch(c)
{
case 1:
selective();
break;
case 2:
goback();
break;
case 3:
exit(0);
break;
}
}while(c!=4);
}
void goback()
{
sender();
recvfrm();
resend1();
printf("\n all packets sent successfully\n");
}
19
OUTPUT:
20
void selective(){
sender(); recvfrm(); resend();
printf("\nAll packets sent successfully");
}
int sender() {
int i;
printf("\nEnter the no. of packets to be sent:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter data for packets[%d]",i);
scanf("%d",&frm[i].data);
frm[i].ack='y';
} return 0; }
voidrecvfrm() {
int i;
rand();
r=rand()%n;
frm[r].ack='n';
for(i=0;i<n;i++)
{
if(frm[i].ack=='n')
printf("\nThe packet number %d is not received\n",r);
}}
void resend() {
printf("\nresending packet %d",r);
sleep(2);
frm[r].ack='y';
printf("\nThe received packet is %d",frm[r].data);
}
void resend1() {
int i;
printf("\n resending from packet
%d",r); for(i=r;i<n;i++) {
sleep(2);
frm[i].ack='y';
printf("\nReceived data of parent %d is %d",i,frm[i].data);
}}
RESULT:
Thus, the program for implementation of go back n and selective repeat protocol was successfully
executed.
21
4) IMPLEMENTATION OF HIGH-LEVEL DATA LINK CONTROL (HDLC) USING C
EXPT NO: 4
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
22
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main() {
int i,j,k,data[100],n;
clrscr();
printf("Enter no. of bits :\n");
scanf("%d",&n);
printf("Enter data to be sent :\n");
for(i=0;i<n;i++)
scanf("%d",&data[i]);
printf("The initial array is\n");
for(i=0;i<n;i++)
printf("%d\t",data[i]);
for(i=0;i<n;i++)
{
if(data[i]==0)
if(data[i+1]==1)
if(data[i+2]==1)
if(data[i+3]==1)
if(data[i+4]==1)
if(data[i+5]==1)
if(data[i+6]==1)
if(data[i+7]==0)
{
i=i+8;
for(j=i+8;j>=i;j--)
{
data[j+8]=data[j];
n++;
}
for(k=0;k<8;k++)
{
if(k==0||k==7)
data[i]=0;
else
data[i]=1;
i++;
}
23
OUTPUT:
24
}
}
RESULT:
Thus, the program for implementation High Level Data Link Control (HDLC) was
successfully executed.
25
FLOW CHART:
26
NETWORK TOPOLOGY - STAR, BUS AND RING
EXPT NO:5
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
27
PROGRAM: //Star topology
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Executenam on the trace file
exec nam out.nam &
exit0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#Change the shape of center node in a star topology
$n0 shape square
#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n0 $n3 1Mb 10ms DropTail
$ns duplex-link $n0 $n4 1Mb 10ms DropTail
$ns duplex-link $n0 $n5 1Mb 10ms DropTail
#Create a TCP agent and attach it to node n0
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
28
OUTPUT:
Star topology
Bus topology
Ring topology
29
ns connect $tcp0 $sink0
# Create a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
//Bus topology
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Executenam on the trace file
exec nam out.nam &
exit 0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#CreateLanbetween the nodes
set lan0 [$ns newLan "$n0 $n1 $n2 $n3 $n4" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
#Create a TCP agent and attach it to node n0
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Create a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
30
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
//Ring topology
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Executenam on the trace file
exec nam out.nam &
exit0 }
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
$ns duplex-link $n4 $n5 1Mb 10ms DropTail
$ns duplex-link $n5 $n0 1Mb 10ms DropTail
#Create a TCP agent and attach it to node n0
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Create a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
31
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 “$cbr0 start”
$ns at 4.5 “$cbr0 stop”
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 “finish”
#Run the simulation
$ns run
RESULT:
Thus, the program for network topology such as star bus and ring were executed successfully.
32
FLOW CHART:
33
DISTANCE VECTOR ROUTING
EXPT NO:6
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
34
PROGRAM:
#include<stdio.h>
#include<conio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int dmat[20][20];
int n,i,j,k,count=0;
clrscr();
printf("\nEnter the number of nodes : ");
scanf("%d",&n);
printf("\nEnter the cost matrix :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
}while(count!=0);
for(i=0;i<n;i++)
{
printf("\n\nState value for router %d is \n",i+1);
for(j=0;j<n;j++)
35
OUTPUT:
36
{
printf("\t\nnode %d via %d Distance%d",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}
printf("\n\n");
getch();
}
RESULT:
Thus, the program for finding shortest path using distance vector routing algorithm was successful executed.
37
FLOWCHART:
38
IMPLEMENTATION OF LINK STATE ROUTING
EXPT NO: 7
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
39
PROGRAM:
#include<stdio.h>
#include<conio.h>
int a[5][5],n,i,j;
void main()
{
void getdata();
void shortest();
void display();
clrscr();
getdata();
shortest();
display();
getch();
}
void getdata()
{
printf("\nEnter the no. of host in the graph\t");
scanf("%d",&n);
printf("\nIf there is no direction path\nHighest distance value 1000\n");
for(i=0;i<n;i++)
{
a[i][j]=0;
for(j=0;j<n;j++)
{
if(i!=j)
{
printf("\nEnter the distance b/w (%d %d): ",i+1,j+1);
scanf("%d",&a[i][j]);
if(a[i][j]==0)
a[i][j]=1000;
}
}
}
}
void shortest()
{
inti,j,k;
for(k=0;k<n;k++)
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(a[i][k]+a[k][j]<a[i][j])
a[i][j]=a[i][k]+a[k][j];
}
}
40
OUTPUT:
41
void display()
{
inti,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(i!=j)
{
printf("\nShortest path is:(%d %d): %d\n",i+1,j+1,a[i][j]);
}
}
RESULT:
Thus, the program for open shortest path 1st(OSPF) – state routing was successfully
written & executed.
42
FLOWCHART:
43
9) ENCRYPTION & DECRYPTION USING RSA ALGORITHM
EXPT NO: 9
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
44
PROGRAM:
import java.io.*;
import java.util.Scanner;
public class Rsa1
{
static Scanner sc=new Scanner(System.in);
static int z,m,n,e,d,c,flag;
public static void main(String args[])
{
int p,q,s;
System.out.println("Enter Two Relatively Prime Numbers\t: ");
p = sc.nextInt();
q = sc.nextInt();
n = p*q;
z=(p-1)*(q-1);
System.out.printf("\n z value= %d",z);
System.out.println("\n Enter the value of e: ");
e = sc.nextInt();
check();
while(flag==1);
d = 1;
do
{
s = (d*e)%z;
d++;
}
while(s!=1);
d = d-1;
System.out.printf("\n\tPublic Key\t: {%d,%d}",e,n);
System.out.printf("\n\tPrivate Key\t: {%d,%d}",d,n);
System.out.println("\n\n Enter The numerical value to encrypt \t: ");
m = sc.nextInt();
encrypt();
System.out.println("\n\nEnter the Cipher text\t: ");
c = sc.nextInt();
decrypt();
}
45
OUTPUT:
46
int i;
for(i=3;e%i==0 &&z%i==0;i++)
{
flag = 1;
}
flag = 0;
}
public static void encrypt()
{
int i;
c = 1;
for(i=0;i<e;i++)
c=c*m%n;
c=c%n;
System.out.printf("\n\tEncrypted keyword : %d",c);
}
RESULT:
Thus the program for encryption & decryption using RSA algorithm was successfully executed
47
10) IMPLEMENTATION OF IP COMMANDS PING, TRACEROUTE , NSLOOKUP
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
48
PROGRAM:
//PING
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
class Ping{
try {
Process p = Runtime.getRuntime().exec(command);
String s = "";
{ System.out.println(s); }
} catch (Exception e) {
e.printStackTrace();
} }
{ String ip;
ip = sc.nextLine();
49
OUTPUT:
50
RESULT:
Thus the program for implementing the ip command ping was done successfully.
51
FLOWCHART:
52
b)IMPLEMENTATION OF IP COMMAND TRACEROUTE
EXPT NO:10b
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
53
PROGRAM:
//TRACEROUTE
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class traceRT {
static Scanner sc = new Scanner(System.in);
public static void runSystemCommand(String command) {
try {
Process p = Runtime.getRuntime().exec(command);
BufferedReaderinputStream = new BufferedReader(new InputStreamReader (p.getInputStream()));
String s = "";
// reading output stream of the command
while ((s = inputStream.readLine()) != null)
{
System.out.println(s);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args)
{
String ip;
System.out.print("Enter the IP or Website Address:");
ip = sc.nextLine();
runSystemCommand("tracert " + ip);
}
}
54
OUTPUT:
55
RESULT:
Thus the program for implementing the ip command traceroute was done successfully.
56
FLOWCHART:
57
c)IMPLEMENTATION OF IP COMMAND NSLOOKUP
EXPT NO:10c
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
58
OUTPUT:
59
PROGRAM:
import java.io*;
import java.util.Scanner;
class nslookup{
try {
Process p = Runtime.getRuntime().exec(command);
String s = "";
{ System.out.println(s);
} catch (Exception e) {
e.printStackTrace(); }}
{ String ip;
ip = sc.nextLine();
}}
RESULT:
Thus the program for implementing the ip command nslookup was done successfully.
60
STUDY THE PERFORMANCE OF NETWORK WITH CSMA / CA
EXPT NO: 11
DATE:
AIM:
To create scenario and study the performance of the network with CSMA/CA protocol and compare
with CSMA/CD protocol through simulation using NETSIM software.
(a) Study the difference between unicast and broadcast transmission (for a fixed
transmitting nodes)
61
(a) LAN (unicast vs.
Hub1
2 6
AP1
3 5
62
Formulae:
(i) Throughput (%)
Mean time a frame waits at a station before being successfully transmitted (queuing time
and medium access time) and the transmission time per frame.
Also called as Service Time; Sum of medium access time & transmission time per frame.
broadcast): Specifications:
Sl No Parameters Value
1. Network Wireless LAN
2. Topology Star-Hub
3. Traffic Broadcast / Point to Point
63
Model graph:
66
64
Throughput
62
Broadcast
60
Unicast
58
56
52
0 2 4 6 8
TransmittingNodes
64
PROGRAM:
CSMA/CA:
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace files
set file1 [open out.tr w]
set winfile [open WinFile w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 0
}
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$n1 color red
$n1 shape box
#Create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Ca Channel]
#Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552
#Setup a FTP over TCP connection
65
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 124.0 "$ftp stop"
$ns at 124.5 "$cbr stop"
# next procedure gets two arguments: the name of the
# tcp source node, will be called here "tcp",
# and the name of output file.
proc plotWindow {tcpSource file} {
global ns
set time 0.1
set now [$ns now]
set cwnd [$tcpSource set cwnd_]
set wnd [$tcpSource set window_]
puts $file "$now $cwnd"
$ns at [expr $now+$time] "plotWindow $tcpSource $file" }
$ns at 0.1 "plotWindow $tcp $winfile"
$ns at 5 "$ns trace-annotate \"packet drop\""
# PPP
$ns at 125.0 "finish"
$ns run
CSMA/CD:
set ns [new Simulator]
66
set winfile [open WinFile w]
$ns trace-all $file1
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
# PPP
68
OUTPUT:
CSMA/CD
CSMA/CA
69
Procedure:
10. SettheBroadcasttrafficononeadditionalnode(totalof2nodes)ClickConfigureand
Simulate.
11. Follow the same procedure increasing the number of Broadcast nodes by 1 every time,
till all 6 nodes broadcast.
12. For unicast, set the traffic (in the traffic Generator) to Point to Point and follow the
procedure as given for broadcast. (Refer Analysis for generatingplot)
Inference:
For unicast (point to point traffic), the nodes use RTS/CTS mechanism to avoid data
collision. But in broadcast the frames are simply sent without RTS/CTS .The reduction in
protocol overheads results in better throughput, for broadcast transmission.
Specifications:
Sl No Parameters CSMA/CD CSMA/CA
1. Network LAN LAN
2. Protocol Ethernet - Star Wireless LAN
3. Topology/ Device Hub Star-Hub
4. Traffic Broadcast Point to Point
Procedure:
Network Diagram:
Node 1 Node 3 Node 5
Hub1
Hub1
2 6
71
Model graph:
120
100
Throughput
80
60
40
20
0
1 2 3 4 5
0 6 7
Transmitting Nodes
72
1. Drag and drop the BSS and the Hub on the environment. Connect the BSS and the hub.
2. Drag and drop the node near to the BSS only. Two is the minimum number of nodes
required for transmission to take place.
3. Right click on the 1stnode and select Point to Point from the transmission option.
Click Accept and Close.
4. Click Configure and Simulate - you will see the performance metrics screen.
5. Close and save the experiment
6. After saving the experiment, click File and Open from the sub menu on the file
panel.
7. SelectLANoption.SelectWirelessLAN-Protocol,Star-HubTopologyandthe
Experiment you have saved. Click on the accept button.
9. Follow the same procedure increasing the number of nodes by 1 every time, till all 6
nodes transmit Point to Point.
10. Follow the appropriate procedure given for Ethernet Star – Hub with 6 nodes
broadcast.
11. Analyze and compare the results between the experiment done in CSMA/CA and one
done with CSMA/CD.
Analysis:
1. Select Simulation and Analysis from the sub menu in the file panel.
2. Select the required details such as User, Network, Protocol and the Sample
3. Add all the samples to the table.
4. After all the samples are added, select the required input and output axis from the
browse button. Select either the Bar Chart or the Line Chart to view the graphs.
5. User can also Export to Excel and plot the graph. Click close to exit.
Inference:
The collision avoidance concept in wireless LAN protocol, avoids the possibility of
collision of data frames. The working of wireless LAN is such that when a node transmits to the
destination the data reaches the access point (coordination point) and from there it is transmitted
to the destination node. Due to its nature of double transmission and protocol overheads, the
throughput is reduced by 50% when compared to Ethernet.
73
Result:
Thus, the scenario was created and the performance of the network with
CSMA/CA protocol and compared with CSMA/CD protocol through simulation using NETSIM
software.
a) The difference between unicast and broadcast transmission (for a fixed number
of transmitting nodes) was studied.
b) CSMA / CD and CSMA / CA protocols (for a fixed number of transmitting
nodes) were compared.
74
FLOWCHART:
DATE:
AIM:
APPARATUS REQUIRED:
ALGORITHM:
76
FLOWCHART:
77
PROGRAM:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
int p[8],i,j,clk,bs,or,ir,psr=0,ps,pt;
clrscr();
for(i=0;i<5;i++)
{p[i]=rand()%10;
if(p[i]==0)--i;
}
printf("\nEnter o/p rate\n");
scanf("%d",&or);
printf("\nEnter bucket size\n");
scanf("%d",&bs);
for(i=0;i<5;i++)
{if((p[i]+psr)>bs)
{
if(p[i]>bs)
printf("\nIncomingpacketsize %d greater then bucket capacity\n",p[i]);
else printf("\nBuffer size exceeded\n");
}
else
{
ps=p[i];
psr=ps;
printf("\n_____________________________________________\n");
printf("\nIncoming packets: %d",ps);
printf("\nTransmission left:%d\n",psr);
pt=rand()%10;
printf("\nNext packet will come at %d",pt);
for(clk=0;clk<pt&&psr>0;++clk)
{
printf("\nTime left %d--No. of packets to transmit%d \n",pt,clk);
sleep(1);
if(psr)
{
printf("\nTransmitted\n");
if(psr<or)
78
OUTPUT:
79
psr=0;
else
psr=or;
printf("\nBytes remaining: %d \n",psr);
}
else
printf("\nNo packets to transmit\n");
}
}
}
getch();
}
RESULT:
Thus, the program for congestion control using leaky bucket algorithm was successfully
executed.
80