Professional Documents
Culture Documents
1. Simulate a three nodes point — to — point network with duplex links between them. Set
the queue size and vary the bandwidth and find the number of packets dropped.
TCL Script
set ns [new Simulator]
set nf [open prog1.nam w]
$ns namtrace-all $nf
proc finish { } {
global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam prog1.nam &
#exec awk -f prog1.awk prog1.tr &
exit 0
}
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 {
dcount = 0;
rcount = 0;
}
{
event = $1;
if(event == "d")
{
dcount++;
}
if(event == "r")
{
rcount++;
}
}
END {
printf("The no.of packets dropped : %d\n ",dcount);
printf("The no.of packets recieved : %d\n ",rcount);
}
LAB PROGRAM 2
A. BIT STUFFING
#include<stdio.h>
#include<string.h>
int main()
{
int a[20],b[30],i,j,k,count,n;
printf("Enter frame size (Example: 8):");
scanf("%d",&n);
printf("Enter the frame in the form of 0 and 1 :");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
i=0;
count=1;
j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1; a[k]==1 && k<n && count<5; k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After Bit Stuffing :");
for(i=0; i<j; i++)
printf("%d",b[i]);
return 0;
}
B.CHARACTER STUFFING
#include<string.h>
#include<stdio.h>
void main()
{
char a[30],fs[50]=””,t[3],sd,ed,x[3],s[3],d[3],y[3];
int i,j,p=0,q=0;
printf(“enter characters to be stuffed:”);
scanf(“%s”,a);
printf(“\n Enter a character that represents ending delimiter:”);
scanf(“%c”,&ed);
x[0]=s[0]=s[1]=sd;
x[1]=s[2]=’\0’;
y[0]=d[0]=d[1]=ed;
d[2]=y[1]=’\0’;
strcat(fs,x);
for(i=0;i<strlen(a);i++)
{
t[0]=a[i];
t[1]=’\0’;
if(t[0]==sd)
strcat(fs,s);
else
if(t[0]==ed)
strcat(fs,d);
else
strcat(fs,t);
}
strcat(fs,y);
printf(“\n After stuffing : %s”,fs);
}
LAB PROGRAM 3
Implement the error correcting code Cyclic Redundancy Check (CRC) of data link layer using various polynomials like
CRC-CRC 12, CRC 16 and CRC CCIPP.
#include <stdio.h>
#include <string.h>
int main()
{
char ip[50], op[50], recv[50];
char poly[] = "10001000000100001";
return 0;
}
OUTPUT 1
Enter the input message in binary
1001
The transmitted message is: 1001,1001000100101001
10011001000100101001
No error in data
OUTPUT 2.
1001
10001001000100101001
LAB PROGRAM 4
LAB PROGRAM 5 –Dijsktra’s algorithm
#include<stdio.h>
Output:
Enter number of vertices:7
Enter cost matrix (for infinity, enter 999):
Source Code:
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
return m;
}
int rsa(char message[50])
long p=0,q=0,n=0,e=0,d=0,phi=0;
long nummes[100]={0};
long encrypted[100]={0},decrypted[100]={0};
long i=0,j=0,nofelem=0;
printf("\nenter value of p and q\n");
scanf("%d%d",&p,&q);
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<strlen(message);i++)
nummes[i]=message[i]-96;
nofelem=strlen(message);
for(i=0;i<nofelem;i++)
{
encrypted[i]=1;
for(j=0;j<e;j++)
encrypted[i] =(encrypted[i]*nummes[i])%n;
}
printf("\n Encrypted message\n");
for(i=0;i<nofelem;i++)
{
printf(" %ld ",encrypted[i]);
printf("%c",(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;
}
printf("\n Decrypted message\n ");
for(i=0;i<nofelem;i++)
printf("%c",(char)(decrypted[i]+96));
return 0;
}
int main()
{
char msg[50];
system("clear");
printf("Enter The Message To Be Encrypted\n");
scanf("%s",msg);
rsa(msg);
return 0;
}
Output:
Enter the text:
hello
Enter the value of P and Q :
5
7
Encrypted Text is: 8 h 10 j 17 q 17 q 15 o
Decrypted Text is: hello
LAB PROGRAM 7
Write a TCL script to simulate the network described below Consider a small network with five nodes n0, n1, n2, n3, n4, forming
a star topology. The node n4 is at the center. Node n0 is a TCP source, which transmits packets to node n3 (a TCP sink) through
the node n4. Node n1 is another traffic source, and sends UDP packets to node n2 through n4. The duration of the simulation time
is 10 seconds.
#Create 5 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam adc.nam &
exit 0
}
$ns at $val(stop) "finish"
$ns run
LAB PROGRAM-8
Simulate to study transmission of packets over Ethernet LAN and determine the number of packets drop at destination.
TCL Script
$ns newLan "$n3 $n4 $n5 $n6 $n7 $n8" 512Kb 40ms LL
Queue/DropTail
proc finish {} {
global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam prog4.nam &
exec awk -f prog4.awk prog4.tr &
exit 0
}
$ns at 0.5 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 5.0 "$ftp stop"
$ns at 5.0 "$cbr stop"
$ns at 5.5 "finish"
$ns run
Prog8.awk
BEGIN {
count=0;
count1=0;
}
{
event=$1;
if(event=="d")
{
count++;
}
if(event=="r")
{
count1++;
}
}
END {
printf("No of packets dropped and recieved : %d %d\n",count,count1);
}
LAB PROGRAM 9
Simulate the different types of internet traffic such as FTP and TELNET over a wired network and analyze the packet drop and
packet delivery ratio in the network.
proc finish {} {
global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam prog6a.nam &
exit 0
}
$ns at 0.2 "$ftp start"
$ns at 4.5 "$ftp stop"
$ns at 5.0 "finish"
$ns run
Prog9b.tcl
proc finish {} {
global ns nf nd
$ns flush-trace
close $nf
close $nd
exec nam prog6b.nam &
exit 0
}
$ns at 0.2 "$telnet0 start"
$ns at 4.5 "$telnet0 stop"
$ns at 5.8 "finish"
$ns run
Prog9.awk
BEGIN {
sSize =0 ;
startTime=5.0;
stopTime=0.1;
Tput=0;
}
{
event=$1;
time=$2;
from=$3;
to=$4;
pkt=$5;
size=$6;
fid=$7;
src=$8;
dst=$9;
seqn=$10;
pid=$11;
if(event == "+") {
if(time < startTime) { startTime=time; }
}
if(event == "r") {
if(time >stopTime) { stopTime =time; }
sSize+=size;
}
Tput=(sSize/(stopTimestartTime))*(
8/1000);
printf("%f\t%f\n",time,Tput);
}
END {
}