0% found this document useful (0 votes)
26 views7 pages

PROGRAM 2&3.tcl

This program implements error detection coding using CRC-CCITT (16-bit). It takes in a data string and divisor as input, calculates the CRC checksum and appends it to the data to send. On the receiver side, it takes the received data, calculates the CRC again and compares it to the received CRC to check for errors. The key steps are: 1. The data and divisor are input and the CRC checksum is calculated by taking remainders modulo 2 division. 2. The checksum is appended to the data to send. 3. On receiving the data, the checksum is recalculated and compared to the received checksum. 4. If they match, no errors are detected

Uploaded by

Ginny Weasly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

PROGRAM 2&3.tcl

This program implements error detection coding using CRC-CCITT (16-bit). It takes in a data string and divisor as input, calculates the CRC checksum and appends it to the data to send. On the receiver side, it takes the received data, calculates the CRC again and compares it to the received CRC to check for errors. The key steps are: 1. The data and divisor are input and the CRC checksum is calculated by taking remainders modulo 2 division. 2. The checksum is appended to the data to send. 3. On receiving the data, the checksum is recalculated and compared to the received checksum. 4. If they match, no errors are detected

Uploaded by

Ginny Weasly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAM 2

2.Implement simple ESS and with transmitting nodes in wire-less LAN by simulation
and determine the throughput with respect to transmission of packets.

# Declare new Simulator


set ns [new Simulator]

# Open the trace file in write mode


set tf [open out.tr w]
$ns trace-all $tf

# Set name-trace for wireless network


set nf [open out.nam w]
$ns namtrace-all-wireless $nf 500 500

# Set new topography


set topo [new Topography]
$topo load_flatgrid 500 500

# Configure for a wireless node.


$ns node-config -adhocRouting DSDV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail \
-ifqLen 50 \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-propType Propagation/TwoRayGround \
-antType Antenna/OmniAntenna \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF

# Create a god object


create-god 3

################### Decide the topology ###############


# 500
# |
# |
# |
# 400 [sink2]
# | [n2]
# | .'
# | .'
# | .'
# | .'
# | .'
# | .'
# 100 [n1]
# | .' [sink1]
# | .' [tcp1]
# 10 [n0] [ftp1]
# | [tcp0]
# | [ftp0]
# |
# |____10______100_______________400_________500

# Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

# Locate the nodes on load_flatgrid


$n0 set X_ 10
$n0 set Y_ 10
$n0 set Z_ 0

$n1 set X_ 100


$n1 set Y_ 100
$n1 set Z_ 0

$n2 set X_ 400


$n2 set Y_ 400
$n2 set Z_ 0

# initial state
$ns at 0.0 "$n0 setdest 10 10 15"
$ns at 0.0 "$n1 setdest 100 100 15"
$ns at 0.0 "$n2 setdest 400 400 15"

# move n1 near to node n2 at 50s and come back near to node n0 at 100s
$ns at 50 "$n1 setdest 300 300 15"
$ns at 100 "$n1 setdest 100 100 15"

# Declare and attach transport layer protocol


set tcp0 [new Agent/TCP]
set tcp1 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
$ns attach-agent $n1 $tcp1

set sink1 [new Agent/TCPSink]


set sink2 [new Agent/TCPSink]
$ns attach-agent $n1 $sink1
$ns attach-agent $n2 $sink2

# Declare and attach appliction layer protocol


set ftp0 [new Application/FTP]
set ftp1 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ftp1 attach-agent $tcp1

# connect source to destination


$ns connect $tcp0 $sink1
$ns connect $tcp1 $sink2

proc finish { } {
global ns nf tf
$ns flush-trace
exec nam out.nam &
close $tf

set ctr1 0
set ctr2 0
set tf [open out.tr r]

while {[gets $tf line] != -1} {


# r->received, _1_ -> destination node
if {[string match "r*_1_*AGT*" $line]} {
set ctr1 [expr $ctr1 + 1]
}
if {[string match "r*_2_*AGT*" $line]} {
set ctr2 [expr $ctr2 + 1]
}
}
puts "\nThroughput from n0 to n1: $ctr1"
puts "Throughput from n1 to n2: $ctr2"
exit 0
}

# schedule events

# start ftp traffic


$ns at 1 "$ftp0 start"
$ns at 1 "$ftp1 start"
$ns at 150 "finish"
$ns run
Output

PROGRAM 3

3.Write program for error detecting code using CRC-CCITT(16-bits).

#include<stdio.h>
int rem(int,int);
void main()
{
int i,j,k,d,dl;
int data[10],div[5],newdata[15],crc[5],datacrc[15],revdata[15],remd[5];
printf("\n Enter the data length= ");
scanf("%d",&d);
printf("\n Enter the divisor length= ");
scanf("%d",&dl);
printf("\n Enter the data : ");
for(i=0;i<d;i++)
scanf("%d",&data[i]);
printf("\n Enter the divisor : ");
for(i=0;i<dl;i++)
scanf("%d",&div[i]);
printf("\n The new data is : ");
for(i=0;i<(d+dl-1);i++)
{
if(i<d)
newdata[i]=data[i];
else
newdata[i]=0;
printf("%d",newdata[i]);
}
for(j=0;j<=d;j++)
{
for(i=0;i<dl;i++)
{
crc[i]=newdata[i+j];
if(crc[0]==1)
newdata[i+j]=rem(newdata[i+j],div[i]);
else
newdata[i+j]=rem(newdata[i+j],0);
}
printf("\n The Crc is : ");
for(i=0;i<dl-1;i++)
printf("%d",crc[i]);
}

printf("\n The data to be send is : ");


for(i=0;i<(d+dl-1);i++)
{
if(i<d)
datacrc[i]=data[i];
else
datacrc[i]=crc[i-d];
printf("%d",datacrc[i]);
}
printf("\n Enter the receiver side data : ");
for(i=0;i<(d+dl-1);i++)
scanf("%d",&revdata[i]);
for(j=0;j<=d;j++)
{
for(i=0;i<dl;i++)
{
remd[i]=revdata[i+j];
if(remd[0]==1)
revdata[i+j]=rem(revdata[i+j],div[i]);
else
revdata[i+j]=rem(revdata[i+j],0);
}
printf("\n The reminder is : ");
k=0;
for(i=0;i<dl-1;i++)
{
printf("%d",remd[i]);
if(remd[i]==0)
k++;
}
}
if(k==dl-1)
printf("\n There is no error found.");
else
printf("\n There is error found.");
}

int rem(int x, int y)


{
if(x==y)
return 0;
else
return 1;
}

OUTPUT

Enter the data length=4

Enter the divisor length=2

Enter the data : 1 0 1 1

Enter the divisor : 1 1

The new data is : 10110


The crc is : 1
The crc is : 1
The crc is : 0
The crc is : 1
The crc is : 1
The data to be send is : 10111

Enter the receiver side data : 1 0 1 1 0

The reminder is : 1
The reminder is : 1
The reminder is : 0
The reminder is : 1
The reminder is : 1
There is error found.

You might also like