The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
Networks lab manual ecp62
1. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
EC P62 - COMPUTER NETWORKS LABORATORY
Lab Manual
EC P62 - COMPUTER NETWORKS LABORATORY
1. Simulation of ON-OFF and voice traffic model
a) To simulate the ON-off traffic model and plot the following waveform
i. User numbers Vs ON period. ii. Time slot Vs number of users.
iii. Time slot Vs bandwidth allotted.
b) To simulate voice traffic model and obtain
i. Time slot Vs bandwidth plot. ii. Time slot Vs error plot.
iii. Average error rate.
iv. The optimum buffer size for which error rate will be less than stipulated value.
BHARATHIYAR COLLEGE OF ENGINEERING AND TECHNOLOGY
KARAIKAL
2. 2. Simulation of data traffic and video traffic model
a) To simulate the data traffic and multiple rate video traffic for multiple users and to obtain
i. Time slot Vs bandwidth plot. ii. Time slot Vs BER plot.
iii. The optimum buffer size for which error rate will be less than stipulated
value.
3. Simulation of ISDN traffic model
a) To simulate the ISDN traffic model for multiple users and to obtain
i. Time slot VS bandwidth plot. ii. Time slot Vs BER plot.
iii. Time slot Vs un-served video user. iv. Time slot Vs un-served data user.
4. PN sequence generation and testing
a) To generate maximal and non maximal length PN sequence and test its randomness
properties.
5. M/M/I queuing model
a) To simulate M/M/I queuing model and obtain
i. Time slot Vs packet loss plot. ii. Maximum and average packet loss without buffer.
iii. Buffer size for the given loss. iv. Maximum and average packet loss with buffer.
6. M/G/I and G/G/I queuing model.
a) To simulate a M/G/I and G/G/I queuing model and obtain
i. Time slot Vs packet loss plot. ii. Maximum average packet loss without buffer.
iii. Buffer size for the given loss. iv. Maximum and average packet loss with buffer.
7. Encryption and decryption
a) To simulate and test the following encryption and decryption algorithm.
i. Mono alphabetic cipher- caeser cipher.
ii. Poly alphabetic cipher- Trithemius key, Vigenere key, Vigenere plain and
cipher key.
iii. RSA with and without digital signature.
8. Flow control
a) To simulate and test
i. Stop and wait protocol ii. Go back N protocol iii. Selective repeat protocol
9. Error control protocol
a) To simulate and test
i. Cyclic redundancy check ii. Hamming code
10. Routing algorithms
a) To simulate and test
i. Shortest path routing algorithm ii. Hierarchical routing algorithm
11. Generation of PDF
a) To study, generate and trace the following PDF
i. Gaussian distribution ii. Uniform distribution iii. Exponential distribution
iv. Rayleigh distribution v. Binomial distribution vi. Negative binomial distribution
vii. Gamma distribution viii. Poisson distribution
12. Wireless LAN
a) To establish wireless LAN test bed (or) wireless LAN environment and perform
i. Uni-cast ii. Multicast iii. File transfer protocol
3. Experiment
No
Name of the Experiment Page NO
1 Simulation of ON-OFF and voice traffic model
2
Simulation of data traffic and video traffic
model
3 Simulation of ISDN traffic model
4 PN sequence generation and testing
5 M/M/I queuing model
6 M/G/I and G/G/I queuing model
7 Encryption and decryption
8 Flow control
9 Error control protocol
10 Routing algorithms
11 Generation of PDF
12 Wireless LAN
4. Exp.No:1 Simulation of ON-OFF and voice traffic model
Date:
Aim:
To simulate
a) The ON-off traffic model and plot the following waveform
i. User numbers Vs ON period.
ii. Time slot Vs number of users.
iii. Time slot Vs bandwidth allotted.
b) To simulate voice traffic model and obtain
i. Time slot Vs bandwidth plot.
ii. Time slot Vs error plot.
iii. Average error rate.
iv. The optimum buffer size for which error rate will be less than stipulated
Value.
Tool Used:
• Matlab
Coding:
a) Generation of ON-OFF traffic model
clc;
clear all;
x=1:10;
t=1:100;
on=input('Enter the Average ON Time: ');
%Users Vs Average ON Time
ton=zeros(10,100);
for i=1:10
ton(i,:)=poissrnd((on*10),1,100);
end
a=ton';
b=mean(a);
c=b/1000;
figure(1);
bar(x,c,0.35);
xlabel('Users');
ylabel('Average ON Time');
%Timeslots Vs Number of Users
n=zeros(10,100);
for i=1:10
for j=1:100
if (ton(i,j)>=4.5)
n(i,j)=1;
end
5. end
end
d=sum(n);
figure(2);
bar(t,d);
xlabel('Time Slots');
ylabel('Number of Users');
%Time slots Vs Bandwidth
bw=64000*n;
for i=1:10
figure(3);
subplot(5,2,i);
bar(t,bw(i,:),0.2)
xlabel('Time Slots');
ylabel('BW Alloted');
end
B) Generation of Voice traffic
clc;
clear all;
use=input('Enter the no of users: ');
ts=input('Enter the no. of time slots: ');
on=0.35;
ton=zeros(use,ts);
n=ton;
for i=1:use
for j=1:ts
ton(i,:)=poissrnd((on*10),1,ts);
if (ton(i,j)>=3.5)
n(i,j)=1;
end
end
end
voice=64000*n;
% time slot vs bw
d=sum(voice);
figure(1);
bar(d);
xlabel('Timeslot');
ylabel('Bandwidth(bps)');
% time slots vs error rate
e=zeros(1,ts);
bm=1540000;
for i=1:ts
if d(i) > bm
e(i)=d(i)-bm;
end
end
figure(2);
bar(e);
7. Exp.No:2 Simulation of data traffic and video traffic model
Date:
Aim:
To simulate
a) The data traffic and multiple rate video traffic for multiple users and to obtain
i. Time slot Vs bandwidth plot.
ii. Time slot Vs BER plot.
iii. The optimum buffer size for which error rate will be less than stipulated value.
Tool Used:
• Matlab
Coding:
Data Traffic model
clear all;
clc;
use=input('Enter the no. of users: ');
ts=input('Enter the no. of time slots: ');
on=0.35;
ton=zeros(use,ts);
n=ton;
for i=1:use
for j=1:ts
ton(i,:)=poissrnd((on*10),1,ts);
if (ton(i,j)>=3.5)
n(i,j)=1;
end
end
end
test=randint(use,ts,[1,1000]);
data=n;
for i=1:use
for j=1:ts
if n(i,j)==1
if test(i,j)>=1 & test(i,j)<=980
data(i,j)=64000;
elseif test(i,j)>980 & test(i,j)<=990
data(i,j)=128000;
elseif test(i,j)>990 & test(i,j)<=998
data(i,j)=256000;
else
data(i,j)=512000;
end
end
8. end
end
%timeslot vs bandwidth
d= sum(data);
figure(1);
bar(d);
xlabel('Time slot');
ylabel('Bandwidth(bps)');
%timeslot vs error rate
e=zeros(1,ts);
bm=1540000;
for i=1:ts
if d(i)>bm
e(i)=d(i)-bm;
end
end
figure(2);
bar(e);
xlabel('Timeslot');
ylabel('Error rate (bps)');
avg=sum(e')/ts;
ber=avg/bm;
buff=0;
disp('Average bit error rate without buffering');
disp(ber);
while (ber)>1e-6
buff=buff+10;
bm=bm+10;
for i=1:ts
if e(i)>0
e(i)=d(i)-bm;
end
end
s=sum(e');
ber=s/(ts*bm);
end
disp('Bit error rate with buffer');
disp(ber);
disp('Optimum buffer size');
disp(buff);
Generation of Video traffic
clc;
clear all;
use=input('Enter The Number Of Users: ');
ts=input('Enter The Number Of Time Slots: ');
on=0.35;
ton=zeros(use,ts);
n=ton;
for i=1:use
9. for j=1:ts
ton(i,:)=poissrnd((on*10),1,ts);
if(ton(i,j)>=3.5)
n(i,j)=1;
end
end
end
test=randint(use,ts,[1,1000]);
data=n;
for i=1:use
for j=1:ts
if n(i,j)==1
if test(i,j)>=1 && test(i,j)<=980
data(i,j)=64000;
else
data(i,j)=384000;
end
end
end
end
%Time Slot Vs Bandwidth
d=sum(data);
figure(1);
bar(d);
xlabel('Time Slot');
ylabel('Bandwidth (bps)');
%Time Slots Vs Error Rate
e=zeros(1,ts);
bm=1540000;
for i=1:ts
if d(i)>bm
e(i)=d(i)-bm;
end
end
figure(2);
bar(e);
xlabel('Time Slot');
ylabel('Error Rate (bps)');
avg=sum(e)/ts;
ber=avg/bm;
buff=0;
disp('Average Bit Error Rate without Buffering: ');
disp(ber);
while ber>1e-6
buff =buff+10;
bm=bm+10;
for i=1:ts
if e(i)>0
e(i)=d(i)-bm;
end
11. Exp.No:3 Simulation of ISDN traffic model
Date:
Aim:
To simulate the ISDN traffic model for multiple users and to obtain
i. Time slot VS bandwidth plot.
ii. Time slot Vs BER plot.
iii. Time slot Vs un-served video user.
iv. Time slot Vs un-served data user.
Tool Used:
• Matlab
Coding:
Generation of Integrated (ISDN) traffic Model
clc;
clear all;
use=input('Enter the Number of users: ');
ts=input('Enter the Number of Time Slots: ');
on=0.35;
voiceuser=0;
datauser=0;
voipuser=0;
ton=zeros(use,ts);
n=ton;
for i=1:use
for j=1:ts
ton(i,:)=poissrnd((on*10),1,ts);
if (ton(i,j)>=3.5)
n(i,j)=1;
end
end
end
userprob=randint(1,use,[1,10]);
useriden=ones(1,use);
for i=1:use
if (userprob(i)>=1 & userprob<=5)
useriden(i)=1;
voiceuser=voiceuser+1;
elseif (userprob(i)>5 & userprob(i)<=8)
useriden(i)=2;
voipuser=voipuser+1;
else
useriden(i)=3;
datauser=datauser+1;
end
12. end
newuseriden=sort(useriden);
isdn=64000*n;
test=randint(voipuser,ts,[1,1000]);
for i=voiceuser+1:voipuser+voiceuser
for j=1:ts
if n(i,j)==1
if test(i-voiceuser,j)>=1 & test(i-voiceuser,j)<=800
isdn(i,j)=64000;
else
isdn(i,j)=384000;
end
end
end
end
test1=randint(datauser,ts,[1,1000]);
for i=voiceuser+voipuser+1:use
for j=1:ts
if n(i,j)==1
if test1(i-(voiceuser+voipuser),j)>=1 & test1(i-(voiceuser+voipuser),j)<=800
isdn(i,j)=64000;
elseif test1(i-(voiceuser+voipuser),j)>800 & test1(i-(voiceuser+voipuser),j)<=900
isdn(i,j)=128000;
elseif test1(i-(voiceuser+voipuser),j)>900 & test1(i-(voiceuser+voipuser),j)<=950
isdn(i,j)=256000;
else
isdn(i,j)=512000;
end
end
end
end
%Time Slots Vs Bandwidth
d=sum(isdn);
figure(1);
bar(d);
xlabel('Time Slots');
ylabel('Bandwidth(bps)');
%Time Slots Vs Error Rate
e=zeros(1,ts);
bm=1984000;
for i=1:ts
if d(i)>bm
e(i)=d(i)-bm;
end
end
figure(2);
bar(e);
xlabel('Time Slots');
ylabel('Error Rate(bps)');
buff=0;
14. Exp.No:4 PN sequence generation and testing
Date:
Aim:
To generate maximal and non-maximal length PN sequence and test its randomness
Properties
Tool Used:
• Matlab
Coding:
Generation of PN sequence and verification of randomness properties
clc;
clear all;
len = input ('Enter the length of the sequence: ');
disp ('Generator Polynomial Example [1 0 0 1...1] ');
poly = input ('Enter the polynomial: ');
disp ('Initial state Example [1 0 0 1...0]');
ini = input ('Enter the initial state: ');
ff = log2(len+1);
%pn sequence generation
a = zeros(len,ff);
a(1,(1:ff)) = ini ;
for i = 1:(len-1)
x = 0;
for j = 2:(ff+1)
if (poly (1,j) == 1)
x = xor (x,a(i,(j-1)));
end
end
a ((i+1),1:ff) = circshift(a(i,1:ff),[0 1]);
a ((i+1),1) = x;
end
for i = 1:len
h(1,i) = a(i,ff);
end
fprintf ('The generated sequence is: n');
disp (h);
%balance property
check = 0;
one = 0;
zero = 0;
for i = 1:len
if ( h(1,i) == 0)
zero= zero+1;
15. else
one = one+1;
end
end
disp ('BALANCE PROPERTY');
disp ('Number of ones: ');
disp (one);
disp ('Number of zeros: ');
disp (zero);
if ((one-zero) == 1)
fprintf ( 'Balance property is satisfiednn');
else
fprintf ( 'Balance property is not satisfiednn');
check = 2;
end
%autocorelation property
while (check == 0)
for i= 1:len
y(i,:) = xor (h,circshift(h,[0 i]));
end
for i = 1:len
one = 0;
zero = 0;
for j = 1:len
if ( y(i,j) == 0 );
zero = zero+1;
else
one = one+1;
end
end
z(i,1) = zero - one;
end
for i = 1: (len-1)
g(i,1) = -1;
end
g (len,1) = len;
disp ('AUTOCORRELATION PROPERTY');
disp (z);
t=1:1:(len);
plot(t,z);
if(z == g);
fprintf ( 'Auto correlation property is satisfiednn');
check = 3;
else
fprintf ( 'Auto correlation property is satisfiednn');
check = 2;
end
end
% run property
while( check == 3);
16. runs = ((len+1)/2);
u = ff;
r = zeros (1,u);
count = 1;
for i = 1:len-1
if (h(1,i) == h(1,i+1))
count = count+1;
else
r(1,count) = r(1,count)+1;
count = 1;
end
end
r(1,count) = r(1,count)+1;
s = zeros(1,u);
for i = 1:(u-1)
s(1,i) = runs / (2.^i) ;
end
s(1,u) = 1;
disp ('RUN PROPERTY');
fprintf ('Runsttt Run Length n');
for i = 1:u
fprintf ('%dtttt %dn',r(1,i),i);
end
if (r == s)
fprintf ('Run Property is satisfiednn');
check = 4;
else
fprintf ('Run Property is not satisfiednn');
check = 2;
end
end
if (check == 2)
disp ('The given sequence is not a PN sequence');
else
disp ('The given sequence is a PN sequence');
end
17. Exp.No:5 M/M/I queuing model
Date:
Aim:
To simulate M/M/I queuing model and obtain
i. Time slot Vs packet loss plot.
ii. Maximum and average packet loss without buffer.
iii. Buffer size for the given loss.
iv. Maximum and average packet loss with buffer
Tool Used:
• Matlab
Coding:
Generation of M|M|1 model
clc;
clear all;
arrival_rate = input('Enter the arrival rate : ');
service_rate = input('Enter the service rate : ');
error_rate = input('Enter the max acceptable packet loss : ');
timeslots = input('Enter the number of timeslots : ');
t = 1:timeslots;
tarr = zeros (1,timeslots);
tser = zeros (1,timeslots);
tarr(1,:) = poissrnd( arrival_rate, 1, timeslots);
tser(1,:) = poissrnd( service_rate, 1, timeslots);
%Timeslot vs Packet loss
n = zeros (1,timeslots);
for j = 1:timeslots
if ( tarr(1,j) > tser(1,j) )
n(1,j) = ( tarr(1,j) - tser(1,j) ) ;
end
end
bar (t,n,.01);
xlabel ('Timeslot');
ylabel ('Packet loss');
disp ('The max packet loss is :');
disp (max(n));
disp ('The average packet loss before buffering is :');
avg = mean(n);
disp (avg);
%Buffer size vs Packet loss
buff = 0;
count = 1;
avg_loss(1,count) = avg ;
18. buffer_size(1,count) = buff;
while (avg > error_rate)
count = count+1;
buff = buff+1;
tser = tser+1;
for j = 1:timeslots
if (n(1,j) > 0)
n(1,j) = (tarr(1,j) - tser(1,j));
end
end
avg = mean(n);
avg_loss (1,count) = avg;
buffer_size (1,count) = buff;
end
disp('The maximum packet loss after buffering is :');
disp(avg);
disp('The maximum buffer size for the given error rate is :');
disp(buff);
figure(2);
line (buffer_size,avg_loss);
xlabel('Buffer size');
ylabel('Packet loss');
19. Exp.No:6 M/G/I and G/G/I queuing model
Date:
Aim:
To simulate a M/G/I and G/G/I queuing model and obtain
i. Time slot Vs packet loss plot.
ii. Maximum and average packet loss without buffer.
iii. Buffer size for the given loss.
iv. Maximum and average packet loss with buffer
Tool Used:
• Matlab
Coding:
Generation of M|G|1 model
clc;
clear all;
arrival_rate=input('Enter the Data Arrival Rate: ');
service_rate=input('Enter the Data Service Rate: ');
error_rate=input('Enter the maximum acceptable Packet Loss Rate: ');
timeslots=100;
t=1:timeslots;
tarr=zeros(1,timeslots);
tser=zeros(1,timeslots);
tarr(1,:)=poissrnd((arrival_rate),1,timeslots);
tser1(1,:)=exprnd((service_rate),1,timeslots);
tser=round(tser1);
%Time Slots Vs Packet Loss
n=zeros(1,timeslots);
for j=1:timeslots
if (tarr(1,j)>tser(1,j))
n(1,j)=tarr(1,j)-tser(1,j);
end
end
bar(t,n,0.01);
xlabel('Time Slots');
ylabel('Packet Loss');
disp('The maximum Packet Loss is: ');
disp(max(n));
disp('The Average Packet Loss before Buffering: ');
avg=mean(n);
disp(avg);
%Buffer Size Vs Packet Loss
buff=0;
count=1;
20. avg_loss (1,count)=avg;
buffer_size (1,count)=buff;
while (avg>error_rate)
count=count+1;
buff=buff+1;
tser=tser+1;
for j=1:timeslots
if (n(1,j)>0)
n(1,j)=tarr(1,j)-tser(1,j);
end
end
avg=mean(n);
avg_loss(1,count)=avg;
buffer_size(1,count)=buff;
end
disp('The maximum Packet Loss after Buffering is: ');
disp(max(n));
disp('The Average Packet Loss after Buffering is: ');
disp(avg);
disp('The maximum Buffer Size for the given Error Rate: ');
disp(buff);
figure(2);
line(buffer_size,avg_loss);
xlabel('Buffer Size');
ylabel('Packet Loss');
Generation of G|G|1 model
clc;
clear all;
arrival_rate=input('Enter the Data Arrival Rate: ');
service_rate=input('Enter the Data Service Rate: ');
error_rate=input('Enter the maximum acceptable Packet Loss Rate: ');
timeslots=100;
t=1:timeslots;
tarr=zeros(1,timeslots);
tser=zeros(1,timeslots);
tarr1(1,:)=normrnd((arrival_rate),5,1,timeslots);
tarr=round(tarr1);
tser1(1,:)=exprnd((service_rate),1,timeslots);
tser=round(tser1);
%Time Slots Vs Packet Loss
n=zeros(1,timeslots);
for j=1:timeslots
if(tarr(1,j)>tser(1,j));
n(1,j)=tarr(1,j)-tser(1,j);
end
end
bar(t,n,0.01);
xlabel('Time Slots');
ylabel('Packet Loss');
21. disp('The maximum Packet Loss is: ');
disp(max(n));
disp('The Average Packet Loss before Buffering is: ');
avg=mean(n);
disp(avg);
%Buffer Size Vs Packet Loss
buff=0;
count=1;
avg_loss(1,count)=avg;
buffer_size(1,count)=buff;
while(avg>error_rate)
count=count+1;
buff=buff+1;
tser=tser+1;
for j=1:timeslots
if n(1,j)>0
n(1,j)=tarr(1,j)-tser(1,j);
end
end
avg=mean(n);
avg_loss(1,count)=avg;
buffer_size(1,count)=buff;
end
disp('The maximum Packet Loss after Buffering is: ');
disp(max(n));
disp('The Average Packet Loss after Buffering is: ');
disp(avg);
disp('The maximum Buffer Size for the given Error Rate is: ');
disp(buff);
figure(2);
line(buffer_size,avg_loss);
xlabel('Buffer Size');
ylabel('Packet Loss');
22. Exp.No:7 Encryption and decryption
Date:
Aim:
To simulate and test the following encryption and decryption algorithm
i. Mono alphabetic cipher- caeser cipher.
ii. Poly alphabetic cipher- Trithemius key, Vigenere key, Vigenere plain and cipher
key.
iii. RSA with and without digital signature.
Tool Used:
• Matlab
Coding:
Data Encryption and Decryption
clc;
clear all;
pt=input('Enter the PlainText: ');
asc=double(pt);
disp(' ');
disp('Monoalphabetic (Caeser Cipher)');
disp(' ');
shift=input('Enter the Number of End-Around Shifts(key): ');
%Encryption
mt=asc;
for i=1:length(mt)
mt(i)=mt(i)+shift;
if mt(i)>127
corr=mt(i)-127;
mt(i)=32+corr-1;
end
end
disp(' ');
disp('ENCRYPTED TEXT: ');
disp(char(mt));
%Decryption
for i=1:length(mt)
mt(i)=mt(i)-shift;
if mt(i)<32
corr=32-mt(i);
mt(i)=127-corr+1;
end
end
disp(' ');
disp('DECRYPTED TEXT: ');
disp(char(mt));
disp(' ');
23. disp('Polyalphabetic(Trithemius Progressive Key): ');
%Forming the trithemius key table
disp(' ');
type=input('Enter the Leftshift(+1) or Rightshift(-1): ');
start=32:127;
for i=1:96
if type==1
k=96-i+1;
elseif type==-1
k=i+1;
if i==96
k=1;
end
end
for j=1:96
tri(i,j)=start(k);
if k==96
k=0;
end
k=k+1;
end
end
%Encryption
mt=asc;
for i=1:length(mt)
col=mt(i)-31;
mt(i)=tri(i,col);
end
disp(' ');
disp('ENCRYPTED TEXT: ');
disp(char(mt));
%Decryption
for i=1:length(mt)
col=mt(i)-31;
mt(i)=tri(96-i,col);
end
disp(' ');
disp('DECRYPTED TEXT: ');
disp(char(mt));
disp(' ');
disp('Vignere Key Method: ');
disp(' ');
key=input('Enter the Key Word: ');
keyasc=double(key);
keylen=length(key);
%Encryption
mt=asc;
x=1;
for i=1:length(mt)
col=mt(i)-31;
24. if type==1
row=96-(keyasc(x)-31)+1;
if row==0
row=96;
end
else
row=keyasc(x)-31-1;
if row==0
row=96;
end
end
mt(i)=tri(row,col);
if x==keylen
x=0;
end
x=x+1;
end
disp(' ')
disp('ENCRYPTED TEXT: ');
disp(char(mt));
%Decryption
x=1;
for i=1:length(mt)
col=mt(i)-31;
if type==1
row=(keyasc(x)-31)-1;
if row==0
row=96;
end
else
row=96-(keyasc(x)-31-1);
if row==0
row=96;
end
end
mt(i)=tri(row,col);
if x==keylen
x=0;
end
x=x+1;
end
disp(' ')
disp('DECRYPTED TEXT: ');
disp(char(mt));
disp(' ');
disp('Vignere Auto(plain) Key Method: ');
disp(' ');
auto1=input('Enter the Key Letter: ');
%Encryption
autoasc=double(auto1);
25. mt=asc;
for i=1:length(mt)
col=mt(i)-31;
if type==1
row=96-(autoasc-31)+1;
if row==0
row=96;
end
else
row=autoasc-31-1;
if row==0
row=96;
end
end
mt(i)=tri(row,col);
autoasc=asc(i);
end
disp(' ')
disp('ENCRYPTED TEXT: ');
disp(char(mt));
%Decryption
autoasc=double(auto1);
for i=1:length(mt)
col=mt(i)-31;
if type==1
row=(autoasc-31)-1;
if row==0
row=96;
end
else
row=96-(autoasc-31-1);
if row==0
row=96;
end
end
mt(i)=tri(row,col);
autoasc=asc(i);
end
disp(' ')
disp('DECRYPTED TEXT: ');
disp(char(mt));
disp(' ');
disp('Vignere Auto(cipher) Key Method: ');
disp(' ');
auto1=input('Enter the Key Letter: ');
%Encryption
autoasc=double(auto1);
mt=asc;
for i=1:length(mt)
col=mt(i)-31;
26. if type==1
row=96-(autoasc-31)+1;
if row==0
row=96;
end
else
row=autoasc-31-1;
if row==0
row=96;
end
end
mt(i)=tri(row,col);
autoasc=mt(i);
end
disp(' ')
disp('ENCRYPTED TEXT: ');
disp(char(mt));
%Decryption
autoasc=double(auto1);
for i=1:length(mt)
col=mt(i)-31;
if type==1
row=(autoasc-31)-1;
if row==0
row=96;
end
else
row=96-(autoasc-31-1);
if row==0
row=96;
end
end
cipkey=mt(i);
mt(i)=tri(row,col);
autoasc=cipkey;
end
disp(' ')
disp('DECRYPTED TEXT: ');
disp(char(mt));
disp(' ')
disp('RSA Method: ');
disp(' ');
mt=asc;
n=input('Enter the value of n(public): ');
eA=input('Enter the value of eA(public): ');
dA=input('Enter the value of dA(secrer): ');
eB=input('Enter the value of eB(public): ');
dB=input('Enter the value of dB(secrer): ');
%Signing
for i=1:length(mt)
27. f=mt(i);
mt(i)=1;
for x=1:dA
mt(i)=mod(mt(i)*f,n);
end
end
disp(' ');
disp('SIGNED TEXT: ');
disp(mt);
%Encryption
for i=1:length(mt)
f=mt(i);
mt(i)=1;
for x=1:eB
mt(i)=mod(mt(i)*f,n);
end
end
disp(' ');
disp('ENCRYPTED TEXT: ');
disp(mt);
%Authenitication
for i=1:length(mt)
f=mt(i);
mt(i)=1;
for x=1:dB
mt(i)=mod(mt(i)*f,n);
end
end
disp(' ');
disp('AUTHENICATED TEXT: ');
disp(mt);
%Decryption
for i=1:length(mt)
f=mt(i);
mt(i)=1;
for x=1:eA
mt(i)=mod(mt(i)*f,n);
end
end
disp(' ');
disp('DECRYPTED TEXT: ');
disp(char(mt));
28. Exp.No:8 Flow control
Date:
Aim:
To simulate and test
i. Stop and wait protocol
ii. Go back N protocol
iii. Selective repeat protocol
Tool Used:
• Matlab
Coding:
Stop and Wait Protocol
clc;
clear all;
disp('SAMPLE INPUT AND OUTPUT: ');
n=input('Number of Frames: ');
frame=1;
while frame<=n
fprintf('Transmitting Frame %dn',frame);
s=randint(1,1,15);
if s<3
fprintf('TIME OUTn Re-');
elseif s>6
fprintf('PAK of Frame %d Receivedn',frame);
frame=frame+1;
else
fprintf('NAK of Frame %d Receivedn Re-',frame);
end
end
Go back N Protocol
clc;
clear all;
n=input('Number Of Frames: ');
w=input('Window Size: ');
pt=1;
flag=0;
flag2=0;
a=1:n;
while flag==0
if flag2==0
%Transmitting The Frames In A Window
29. for i=1:w
fprintf('Frame %d Transmittedn',a(pt));
pt=pt+1;
end
flag2=1;
end
s=randint(1,1,10);
if s>3
fprintf('PAK of Frame %d Receivedn',a(pt-w));
fprintf('Frame %d Transmittedn',a(pt));
if a(pt)==n
flag=1;
end
pt=pt+1;
else
fprintf('NAK Of Frame %d Receivedn',a(pt-w));
for j=0:w-1
fprintf('Frame %d Discardedn',a(pt-w+j));
end
pt=pt-w;
flag2=0;
end
end
%Last 'W' Frames are dealt seperately
i=n-w+1;
while (i<=n)
s=randint(1,1,10);
if s>4
fprintf('PAK of Frame %d Receivedn',a(i));
i=i+1;
else
fprintf('NAK of Frame %d Received n',a(i));
for j=i:n
fprintf('Frame %d Discardedn',a(j));
end
for k=i:n
fprintf('Frame %d Transmittedn',a(k));
end
end
end
Selective Repeat Protocol
clc;
clear all;
n=input('Enter the number of frames: ');
w=input('Window Size: ');
pt=w+1;
flag=0;
ext=0;
30. flag1=0;
flag2=0;
a=1:n;
for i=1:w
fprintf('Frame %d Transferredn',a(i));
end
while flag==0
s=randint(1,1,10);
if s>3
fprintf('PAK of frame %d receivedn',a(pt-w));
else
fprintf('NAK of frame %d receivedn',a(pt-w));
ext=ext+1;
for i=n+ext:-1:pt+1
a(i)=a(i-1);
end
a(pt)=a(pt-w);
end
fprintf('Frame %d Transferredn',a(pt));
if a(pt)==n
flag=1;
end
pt=pt+1;
end
k=pt-w;
while flag2==0
test=randint(1,1,[1 7]);
if flag1==1
fprintf('Frame %d Transmittedn',a(k));
flag1=0;
end
if test>3
fprintf('PAK of frame %d receivedn',a(k));
k=k+1;
else
fprintf('NAK of frame %d receivedn',a(k));
flag1=1;
end
if k==n+ext+1
flag2=1;
end
end
31. Exp.No:9 Error control protocol
Date:
Aim:
To simulate and test
i. Cyclic redundancy check
ii. Hamming code
Tool Used:
• Matlab
Coding:
32. Exp.No:10 Routing algorithms
Date:
Aim:
To simulate and test
i. Shortest path routing algorithm
ii. Hierarchical routing algorithm
Tool Used:
• Matlab
Coding:
Shortest Path Routing
clc;
clear all;
n=input('enter the number of nodes: ');
conn=input('enter the connected nodes: ');
delarr=ones(n);
delarr=10000*delarr;
len=length(conn);
delay2=randint(1,(len/2),[10 50]);
k=1;
for i=1:2:len;
delarr(conn(i),conn(i+1))=delay2(k);
delarr(conn(i+1),conn(i))=delay2(k);
k=k+1;
end
for i=1:n
delarr(i,i)=0;
end
disp('....Delay time.....');
disp(delarr);
gr=delarr;
v=[1:n];
p=perms(v);
start=input('enter the source node: ');
dest=input('enter the destination node: ');
%finding all possible paths and thier delays
paths=zeros(factorial(n-1),n);
index=0;
for i=1:factorial(n);
if p(i,1)~=start;
continue;
end
de=0;
33. temp=p(i,1);
index=index+1;
paths(index,1)=temp;
for j=2:n;
if(gr(temp,p(i,j))>0 && gr(temp,p(i,j))<1000);
flag=1;
de=de+gr(temp,p(i,j));
temp=p(i,j);
paths(index,j)=temp;
if temp == dest
delay(index)=de;
break;
end
else
flag=0;
index=index-1;
break;
end;
end;
end;
%removing the repeated paths
j=1;
delay1(j)= delay(1);
paths1(j,:) = paths(1,:);
for i=2:length(delay);
if delay(i-1)~=delay(i);
j=j+1;
delay1(j)=delay(i);
paths1(j,:)=paths(i,:);
shortind=j;
end;
end;
%displaying all paths and also the delay
for i=1:length(delay1);
for j=1:n;
if paths1(1,j)~=0;
fprintf('%d->',paths1(i,j));
else
break;
end;
end;
fprintf('bb:delay=%dn',delay1(i));
end;
temp=min(delay1(1));
for i=1:length(delay1)
if delay1(i)==temp
break;
34. end
end
disp('');
for j=1:n
if paths1(i,j)~=0
fprintf('%d->',paths1(i,j));
end
end
fprintf('bbtt delay=%dn',delay1(i));
Shortest & Distance Vector Routing
clc;
clear all;
n=input('enter the number of nodes');
conn=input('enter the connected nodes');
delarr=ones(n);
delarr=10000*delarr;
len=length(conn);
delay2=1;
for i=1:2:len;
delarr(conn(i),conn(i+1))=delay2;
delarr(conn(i+1),conn(i))=delay2;
end
for i=1:n
delarr(i,i)=0;
end
disp('....Delay time.....');
disp(delarr);
gr=delarr;
v=[1:n];
p=perms(v);
start=input('enter the source node');
dest=input('enter the destination node');
%finding all possible paths and thier delays
paths=zeros(factorial(n-1),n);
index=0;
for i=1:factorial(n);
if p(i,1)~=start;
continue;
end
de=0;
temp=p(i,1);
index=index+1;
paths(index,1)=temp;
35. for j=2:n;
if(gr(temp,p(i,j))>0 && gr(temp,p(i,j))<1000);
flag=1;
de=de+gr(temp,p(i,j));
temp=p(i,j);
paths(index,j)=temp;
if temp == dest
delay(index)=de;
break;
end
else
flag=0;
index=index-1;
break;
end;
end;
end;
%removing the repeated paths
j=1;
delay1(j)= delay(1);
paths1(j,:) = paths(1,:);
for i=2:length(delay);
if delay(i-1)~=delay(i);
j=j+1;
delay1(j)=delay(i);
paths1(j,:)=paths(i,:);
shortind=j;
end;
end;
%displaying all paths and also the delay
for i=1:length(delay1);
for j=1:n;
if paths1(1,j)~=0;
fprintf('%d->',paths1(i,j));
else
break;
end;
end;
fprintf('bb:delay=%dn',delay1(i));
end;
%shortest path and its delay
disp('');
disp('the shortest path is');
for j=1:n;
if paths1(shortind,j)~=0;
fprintf('%d->',paths1(shortind,j));
else
break;
end;
37. Exp.No:11 Routing algorithms
Date:
Aim:
To study, generate and trace the following PDF
i. Gaussian distribution
ii. Uniform distribution
iii. Exponential distribution
iv. Rayleigh distribution
v. Binomial distribution
vi. Negative binomial distribution
vii. Gamma distribution
viii. Poisson distribution
Tool Used:
• Matlab
Coding:
i. Gaussian distribution
clear x h b;
figure, hold on;
mu = [-3 -1 2];
beta = [1 5 2];
rho = [1 2 10];
delt = 0.15;
cents = -12:delt:12;
for k = 1:length(mu)
x(k,:) = gg6(1,100000,mu(k),beta(k),rho(k));
h(k,:) = histc(x(k,:),cents);
end
bar(cents,h(1,:)/(100000*delt),'b');
bar(cents,h(2,:)/(100000*delt),'g');
bar(cents,h(3,:)/(100000*delt),'r');
xlim([-8 8]);
set(gca,'XTick',-10:10);
set(gca,'fontsize',14);
xlabel('itx rm(bin)');
ylabel('normalized histogram');
ii) Uniform Distribution:
%Uniform Distribution
clc;
close all;
38. clear all;
n=input('Input the end value of x = ');
a=input('Input the starting value of uniform distribution, a=');
b=input('Input the ending value of uniform distribution, b= ');
y=1/(b-a);
m=(a+b)/2;
s=((b-a)^2)/12;
disp('mean is ');m
disp('variance is ');s
disp('value of f(x) is ');y
u=[zeros(1,(a-1)) ones(1,(b-a)) zeros(1,(n-b))];
z=y*u;
stem(z);
axis([0 n 0 1]);
iii) Hyper-exponential distribution:
t=0:0.01:6; miu=1; pi1=.0526; miu1=.1; miu2=2.0; pi2=1-p1;
F=pi1*(1-exp(-miu1*t))+pi2*(1-exp(-miu2*t)); E=1-exp(-t/miu);
f=pi1*miu1*exp(-miu1*t)+pi2*miu2*exp(-miu2*t);
e=1/miu*exp(-t/miu); subplot(2,1,1); plot(t,F,'k'); hold on;
plot(t,E,'k'); xlabel('t'); ylabel('F(t)'); title('A two-stage
hyper-exponential distribution'); text(.3,.8,'H_{2}');
text(1,.5,'Exp'); subplot(2,1,2); plot(t,f,'k'); hold on;
plot(t,e,'k'); xlabel('t'); ylabel('f(t)'); text(.3,1.4,'H_{2}');
text(1,.5,'Exp');
iv) Rayliegh Distribution:
%Rayliegh Distribution
clc;
close all;
clear all;
x=input('Enter the input sequence ');
s=input('Enter the standard deviation ');
n=length(x);
a=(x.^2)./(2*(s^2));
p=x./s;
q=exp(-a);
y=p.*q;
t=0:n-1;
plot(t,y);
title('Rayliegh Distribution');
grid on;
v) Binomial Distribution:
Distribution in stem:
k=0:20;
y=binopdf(k,20,0.5);
39. stem(k,y)
Distribution in stair:
k=0:20;
y=binocdf(k,20,0.5);
stairs(k,y)
grid on
vi Negative binomial distribution:
p=.5; j=0:35; jj=0:.1:35; i=1;
for r=[0.5 1 2 4 8 16 32]
P=gamma(r+j)./gamma(r)./gamma(j+1).*(p^r).*((1-p).^j);
PP=gamma(r+jj)./gamma(r)./gamma(jj+1).*(p^r).*((1-p).^jj);
plot(j,P,'.k',jj,PP,'k');
hold on;
end text(.4, 0.65,'r=0.5'); text(1.2, 0.3,'r=1'); text(2,0.22,'r=2');
text(3.8, 0.17,'r=4'); text(8, 0.13,'r=8'); text(17,0.1,'r=16'); text(32, 0.08,'r=32');
ylabel('P[X_{r}=j]');
xlabel('j');
title('The generalized negative binomial distribution');
vii) Gamma distribution:
y=0:0.01:4.5; for b = [0.2 1 5]
a=b;
f=a*(a*y).^(b-1)/gamma(b).*exp(-a*y);
if b==.2
plot(y,f,'--k');
else
plot(y,f,'k');
end
hold on;
end;
axis([0,4.5,0,2]); xlabel('y'); ylabel('f_{Ybeta}(y)');
text(.1,1.6,'beta=alpha=0.2'); text(.17,.95,'beta=alpha=1');
text(1.2,.8,'beta=alpha=5');
viii) Poisson distribution:
k=0:25; kk=0:.1:25; P=zeros(1,26);
for l=[0.5 1 2 4 8 16]
P=l.^k./gamma(k+1)*exp(-l);
PP=l.^kk./gamma(kk+1)*exp(-l);
plot(k,P,'k.',kk,PP,'k');
hold on;
end
axis([0, 25, 0, 0.65]); text(0.6,0.47,'lambda=0.5');
text(1.4,0.37,'lambda=1'); text(2.4,0.27,'lambda=2');
text(4.9,0.18,'lambda=4'); text(9,.145,'lambda=8');