0% found this document useful (0 votes)
30 views44 pages

DCCN Lab Record DINO-1

The document outlines the lab record for the Data Communication & Computer Networks course (4CSGC2061) at CMR University, detailing the course framework, objectives, outcomes, and syllabus for Semester VI (2023-24). It includes a series of laboratory experiments focusing on network simulations and programming tasks using various tools and languages. The document is submitted by Suraj Bhojkar and supervised by Dr. Umesharaddy, Associate Professor in the Department of Computer Science & Engineering.

Uploaded by

shaheedapinjar15
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)
30 views44 pages

DCCN Lab Record DINO-1

The document outlines the lab record for the Data Communication & Computer Networks course (4CSGC2061) at CMR University, detailing the course framework, objectives, outcomes, and syllabus for Semester VI (2023-24). It includes a series of laboratory experiments focusing on network simulations and programming tasks using various tools and languages. The document is submitted by Suraj Bhojkar and supervised by Dr. Umesharaddy, Associate Professor in the Department of Computer Science & Engineering.

Uploaded by

shaheedapinjar15
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/ 44

SCHOOL OF ENGINEERING AND TECHNOLOGY

Programme: B.Tech.

Lab Record for


Data Communication & Computer Networks
(4CSGC2061)
Semester VI (2023- 24)

Submitted by:
SURAJ BHOJKAR
21BBTCS237

Lab Incharge
Dr. Umesharaddy,
Associate Professor, CMR University.

Department of Computer Science & Engineering


Hennur-Bagalur Main Road, Chagalatti, Bagalur, Bengaluru-562149

KARNATAKA, INDIA

Tel: 7022007672 Email:[email protected]


www.cmr.edu.in
4CSGC2061: DATA COMMUNICATION AND COMPUTER NETWORKS

Course Framework:

Credits: L-T-P: 2 – 0 – 1 Total Credits: 3

Contact Hours/Week: 4 Direct Teaching Hours: 45 Total Contact Hours: 75

Course Learning Objectives:

The course aims to introduce the concepts, terminologies and technologies used in data communication
and computer networking, familiarize students with division of network functionalities into layers,
components required to build different types of networks, functionality of each layer and learn the flow
control and congestion control algorithms.

Course Outcomes:

On successful completion of the course, Students will be able to,

1) Outline basic concepts in data communications, OSI and TCP/IP Protocol Stack. (L2)
2) Demonstrate design issues, flow control and error control (L2)
3) Understand the transfer of data from source to the destination using different protocols and
addressing. (L2)
4) Summarize the functions of Application layer protocols and how to meet the QoS requirements in
networking. (L2)
5) Identify the limits and importance of compression, encoding, sampling, quantization methods. (L3)

Syllabus Hours

Module – 1 09

Overview of data communication and Networking: Introduction; Data communications: components,


data representation(ASCII,ISO etc.),direction of data flow(simplex, half duplex, full duplex); Networks:
distributed processing, network criteria, physical structure (type of connection, topology), categories of
network (LAN, MAN,WAN);Internet: brief history, internet today; The Internet, Protocols & Standards, Layered
Tasks, The OSI model, Layers in OSI model, TCP/IP Protocol suite, Addressing.

Module – 2 09

Design Issues: Services to Network Layer, Framing, Error Control and Flow Control. Error Control: Parity Bits, Hamming
Codes and CRC. Flow Control Protocols: Unrestricted Simplex, Stop and Wait, Sliding Window Protocol, Medium
Access Control: Pure and Slotted ALOHA, CSMA, WDMA, CSMA/CD,

CSMA/CA.

Module – 3 09

TCP/IP: TCP/IP architecture, The Internet Protocol, IPv6, UDP, TCP, Internet Routing Protocols, Multicast Routing.
Module – 4 09

Applications Layer : Application layer overview, Domain Name System (DNS), Remote Login
Protocols, E- mail, File Transfer and FTP, World Wide Web and HTTP, Network management,
Overview of QoS, Integrated Services QoS, Differentiated services QoS, Virtual Private Networks.

Module – 5 09

Multimedia Networking : Overview of data compression, Digital voice and compression, JPEG, MPEG, Limits of
compression with loss, Compression methods without loss, Overview of IP Telephony, VoIP signaling protocols,
Real-Time Media Transport Protocols, Stream control Transmission Protocol(SCTP).

LABORATORY EXPERIMENTS:

—Simulation Exercises.

7-10- Network programs.

IDE/Software’s used: NS2/Packet Tracer for Simulations and Turbo C for Windows/ gcc/ Sublime for Ubuntu. PART
A:

Simulation Exercises

1) Simulate a three nodes point-to-point network with duplex links between them. Set the queue size
vary the bandwidth and find the number of packets dropped.
2) Simulate a four-node point-to-point network, and connect the links as follows: n0-n2, n1-n2 and
n2-n3. Apply TCP agent between n0-n3 and UDP n1-n3. Apply relevant applications over TCP and
UDP agents changing the parameter and determine the number of packets by TCP/UDP.
3) Simulate the transmission of ping messaged over a network topology consisting of 6 nodes and
find the number of packets dropped due to congestion.
4) Simulate an Ethernet LAN using N-nodes (6-10), change error rate and data rate and compare the
throughput.
5) Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and plot congestion
window for different source/destination.
6) Configure RIP/OSPF routing protocols using packet tracer.
PART B:

The following experiments shall be conducted using C/C++.

7) Write a program for distance vector algorithm to find suitable path for transmission.
8) Write a program for Hamming code/CRC.
9) Using TCP/IP sockets, write a client server program to make client sending the file name and the
server to send back the contents of the requested file if present.
10) Write a program for congestion control using Leaky bucket algorithm.
INDEX
Expt No. Name of Experiment Page No. Remarks

Simulate a three nodes point-to-point network


1 with duplex links between them. Set the queue 1-4
size vary the bandwidth and find the number of
packets dropped.
Simulate a four-node point-to-point network, and
connect the links as follows: n0-n2, n1-n2 and n2-
n3. Apply TCP agent between n0-n3 and UDP n1-
2 5-9
n3. Apply relevant applications over TCP and UDP
agents changing the parameter and determine the
number of packets by TCP/UDP.

Simulate the transmission of ping messaged over a


3 network topology consisting of 6 nodes and find 10-14
the number of packets dropped due to congestion.

Simulate an Ethernet LAN using N-nodes change


4 15-18
error rate and data rate and compare throughput.

Simulate an Ethernet LAN using N nodes and set


5 multiple traffic nodes and plot congestion window 19-23
for different source/destination.

6 Write a program for distance vector algorithm to 24-26


find suitable path for transmission.
Error Detection Techniques 27-31

7 A) Write a program for Hamming code/CRC. 27-28

B) Program for cyclic Redundancy Check in C 29-31

Using TCP/IP sockets, write a client server


program to make client sending the file name and
8 32-35
the server to send back the contents of the
requested file if present.

Program for congestion control using leaky bucket


9 36-39
algorithm
EXPERIMENT NO 1

Simulate a three nodes point-to-point network with duplex links between them. Set the
queue size vary the bandwidth and find the number of packets dropped.

TCL file:

set ns[new Simulator]

set tf[open lab1.tr w]

$ns trace-all $tf

set nf[open lab1.nam w]

$ns namtrace-all $nf

proc finish {} {

global ns nf tf

$ns flush-trace

exec nam lab1.nam &

close $tf

close $nf

exit

set n0[$ns node]

set n1[$ns node]

set n2[$ns node]

set n3[$ns node]

$ns color 1 "red"

$ns color 2 "blue"

$n0 label "source/udp0"

$n1 label "source/udp1"

$n2 label "router"

1
$n3 label "Destination/Null"

$ns duplex-link $n0 $n2 100Mb 300ms DropTail

$ns duplex-link $n1 $n2 100Mb 300ms DropTail

$ns duplex-link $n2 $n3 1Mb 300ms DropTail

$ns set queue-limit $n0 $n2 50

$ns set queue-limit $n1 $n2 50

$ns set queue-limit $n2 $n3 5

set udp0[new Agent/UDP]

$ns attach-agent $n0 $udp0

set cbr0[new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp

set udp1[new Agent/UDP]

$ns attach-agent $n1 $udp1

set cbr1[new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set interval_ 0.005

$cbr1 attach-agent $udp1

# Use Agent/TCP or Agent/Null depending on your requirements

set tcpAgent[new Agent/TCP]

$ns attach-agent $n3 $tcpAgent

$ns connect $udp0 $tcpAgent

$ns connect $udp1 $tcpAgent

$ns at 0.5 "$cbr0 start"

$ns at 1.0 "$cbr1 start"

$ns at 4.0 "$cbr1 stop"

2
$ns at 4.5 "$cbr0 stop"

$ns at 5.0 "finish"

$ns run

AWK file:

BEGIN{

count = 0;

} {

If ($1==”d”)

count++

END{

printf(“The Total no of packets Drop is: %d\n\n”,count)

OUTPUT:

3
4
EXPERIMENT NO 2

Simulate a four-node point-to-point network, and connect the links as follows: n0-n2, n1-n2
and n2-n3. Apply TCP agent between n0-n3 and UDP n1-n3. Apply relevant applications over
TCP and UDP agents changing the parameter and determine the number of packets by
TCP/UDP.

TCL File:

#Create a simulator object

set ns [new Simulator]

#Define different colors for data flows (for NAM)

$ns color 1 Blue

$ns color 2 Red

set tf [open out1.tr w]

$ns trace-all $tf

#Open the NAM trace file

set nf [open out1.nam w]

$ns namtrace-all Snf

#Define a 'finish' procedure

proc finish {} {

global ns tf nf

$ns flush-trace

close $tf

#Close the NAM trace file

close Snf

#Execute NAM on the trace file

exec nam out.nam &

exit e

5
}

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

#Create links between the nodes

$ns duplex-link $no $n2 2Mb 10ms DropTail 35

$ns duplex-link $n1 $n2 2Mb 10ms DropTail

$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail

#Set Queue Size of link (n2-n3) to 16

$ns queue-limit $n2 $n3 10

#Give node position (for NAM)

$ns duplex-link-op $ne $n2 orient right-down 43 $ns duplex-link-op $n1 $n2 orient right-up

$ns duplex-link-op $n2 $n3 orient right

#Monitor the queue for link (n2-n3). (for NAM)

$ns duplex-link-op $n2 $n3 queuePos 0.5

#Setup a TCP connection

set tcp [new Agent/TCP]

$tcp set class_2

$ns attach-agent $no $tcp

set sink [new Agent/TCPSink] 55 $ns attach-agent $n3 $sink

ns connect Stcp $sink

$tcp set fid 1

#Setup a FTP over TCP connection

set ftp [new Application/FTP]

$ftp attach-agent $t.cp

6
$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 $n3 $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 imb

$cbr set random false

#Schedule events for the CBR and FTP agents

$ns at 0.1 "Scbr start"

$ns at 1.0 "Sftp start"

$ns at 4.0 "Sftp stop"

$ns at 4.5 "Scbr stop"

#Detach tcp and sink agents (not really necessary)

$ns at 4.5 "$ns detach-agent Sno Stcp; Sns detach-agent $n3 $sink" 90

#Call the finish procedure after 5 seconds of simulation time

$ns at 5.0 "finish

#Print CBR packet size and interval 95 puts CBR

packet size = [Scbr set packet_size_]"

puts "CBR interval = [Scbr set interval ]"

7
AWK File:

BEGIN{

count=0;

}{

if($1=="")

count++

END{

printf("The Total no of Packets Drop is %d\n\n", count)

OUTPUT:

8
9
EXPERIMENT NO 3

Simulate the transmission of ping messaged over a network topology consisting of 6 nodes
and find the number of packets dropped due to congestion.

TCL file:

#Create a simulator object

set ns [new SimulatOT] set tf [open lab2.tr w]

$ns trace-all $tf

set nf [open lab2.nam w]

$ns namtrace-all $nf

set n0 [$ns node] set nl [$ns node] set n2 [$ns node] set n3 [$ns node] set n4 [$ns node] set
n5 [$ns node] set n6 [$ns node]

$n0 label "Ping0"

$n4 label "Ping4"

$n5 label "Ping S"

$n6 labcl "Ping6"

$n2 label "Router"

$ns color 1 "red"

$ns color 2 "green"

$ns duplex-link $n0 $n2 l00Mb 300ms DropTail

$ns duplex-link $n1 $n2 lMb 300ms DropTail

$ns duplex-link $n3 $n2 lMb 300ms DropTail

$ns duplex-link $n5 $n2 lO0Mb 300ms DropTail

$ns duplex link $n2 $n4 lMb 3O0ms DropTail

$ns duplex-link $n2 $n6 lMb 300ms DropTail

$ns queue-limit $nO $n2 5

$ns queue-limit $n2 $n4 3

10
$ns queue-limit $n2 $n6 2

$ns queue-limit $n5 $n2 S

#The below code is used to connect between the ping agents to the node n0, #n4 , n5 and n6.

set ping0 [new Agent/Ping]

$ns attach-agent Sn0 $ping0

set ping4 [new AgentHing}

$ns attach-agent Sn4 $ping4

set ping 5 [new Agent/Ping]

$ns attach-agent Sn5 $ping 5

set ping6 [new Agent/Ping]

$ns attach-agent Sn6 $ping6

$ping0 set packctSizc_ 50000

$ping0 set interval_ 0.0001

$ping5 set packetSize_ 60000

$pingS set interval_ 0.00001

$ping0 set class_ 1

$ping5 set class_ 2

$ns connect $ping0 $ping4

$ns connect $ping 5 $ping6

#Define a 'recv' function for the class 'Agent/Ping'

#The below function is executed when the ping agent receives a reply from the destination

Agent/Ping instproc recv {from rtt} (

$self instvar node_

puts " The node [Snode id] received an reply from $from with round trip time of $rtt”

proc finish (} ( global ns nf tf exec nam lab2.nam &

11
$ns flush-trace close $t1 close $nf exit 0

#Schedule events

$ns at 0.1 ”$ping0 send"

$ns at 0.2 ”$ping0 send"

$ns at 0.3 ”$ping0 send"

$ns at 0.4 ”$ping0 send"

$ns at 0.5 "$pingo send"

$ns at 0.6 "$ping0 send"

$ns at 0.7 "$ping0 send"

$ns at 0.8 "$ping0 send"

$ns at 0.9 "$ping0 send"

$ns at 1.0 "$ping0 send"

$ns at 1.1 "$ping0 send"

$ns at 1.2 "$ping0 send"

$ns at 1.3 "$ping0 send"

$ns at 1.4 "$ping0 send"

$ns at 1.5 "$ping0 send"

$ns at 1.6 "$ping0 send"

$ns at t.7 "$ping0 send"

$ns at 1.8 "$ping0 send"

$ns at 0.1 "$ping 5 send"

$ns at 0.2 "$ping 5 send"

$ns at 0.3 "$ping 5 send"

$ns at 0.4 "$ping 5 send"

$ns at 0.5 "$ping 5 send"

$ns at 0.6 "$ping 5 send"

$ns at 0.7 "$ping 5 send"

12
$ns at 0.8 "$ping S send"

$ns at 0.9 "$ping S send"

$ns at 1.0 "$ping 5 scnd"

$ns at 1.1 "$ping S send"

$ns at 1.2 "$ping 5 send"

$ns at 1.3 "$ping 5 send"

$ns at 1.4 "$ping 5 send"

$ns at 1.5 "$ping 5 send"

$ns at 1.6 "$ping 5 send"

$ns at 1.7 "$ping 5 send"

$ns at 1.8 "$ping S send"

$ns at 5.0 "finish"

$ns run

Awk file:

Note: Create the file using gcdir command and save it with rhe extension o(. Awk in order to
find the number o(packets drop in thc trace file. We can name it as out1.awk.

BEGIN{

count=0;

}{

if($l=="d")

count++

END {

printf(”The Total no of Packets Drop is :%d\n\n", count)

13
OUTPUT:

14
EXPERIMENT NO 4

Simulate an Ethernet LAN using N-nodes (6-10), change error rate and data rate and compare
the throughput.

TCL File:

# Declare a new Simulator set ns [new Simulator]

# Open nam and trace file in write mode set tf [open out.tr w]

set nf [open out.nam w]

$ns trace-all $tf

$ns namtrace-all $nf

# Take value of error rate and data rate from std input puts "Enter error rate (<1) : "

gets stdin erate

puts "Enter data rate (in Mbps) : " gets stdin drate

# Create 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] set n6 [$ns node]

# set label and color (OPTIONAL)

$n1 label "udp/source"

$n5 label "udp/null"

$n0 color "blue"

$n1 color "blue"

$n2 color "blue"

$n3 color "blue"

$n4 color "red"

$n5 color "red"

$n6 color "red"

# Create two lans

$ns make-lan "$n0 $n1 $n2 $n3" 10Mb 10ms LL Queue/DropTail Mac/802_3

15
$ns make-lan "$n4 $n5 $n6" 10Mb 10ms LL Queue/DropTail Mac/802_3

# Setup Links

$ns duplex-link $n3 $n6 10Mb 10ms DropTail

$ns duplex-link-op $n3 $n6 orient right-down

# Declare the transport layer protocols set udp1 [new Agent/UDP]

set null5 [new Agent/Null]

$ns attach-agent $n1 $udp1

$ns attach-agent $n5 $null5

# Declare the application layer protocol set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

# Connect the source and destination

$ns connect $udp1 $null5

# Create error model

set err [new ErrorModel]

$ns lossmodel $err $n3 $n6

$err set rate_ $erate

# Define the data rate

$cbr1 set packetSize_ $drate.Mb

$cbr1 set interval_ 0.001 # Define procedure

proc finish { } {

global ns nf tf

$ns flush-trace exec nam out.nam & close $nf

close $tf

set count 0

set tr [open out.tr r]

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

# 8 denotes LAN at destination side and 5 denotes destination node

16
if {[string match "* 8 5 *" $line]} {

set count [expr $count+1]}

set thr [expr $count/7] puts "Throughput : $thr" exit 0

$ns at 0.1 "$cbr1 start"

$ns at 5.1 "finish"

$ns run

OUTPUT:

17
18
EXPERIMENT NO 5

Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and plot congestion
window for different source/destination.

TCL File:

set ns [new Simulator]

set tf [open lab3.tr w]

$ns trace-all $tf

set nf [open lab3.nam w]

$ns namtrace-all $nf

set n0 [$ns node]

$n0 color "magenta"

$n0 label "src1"

set n1 [$ns node]

$n1 color "red"

set n2 [$ns node]

$n2 color "magenta"

$n2 label "src2"

set n3 [$ns node]

$n3 color "blue"

$n3 label "dest2"

set n4 [$ns node]

$n4 shape square

set n5 [$ns node]

$n5 color "blue"

$n5 label "dest1"

$ns make-lan "$n0 $n1 $n2 $n3 $n4" 50Mb 100ms LL Queue/DropTail Mac/802_3

19
$ns duplex-link $n4 $n5 1Mb 1ms DropTail

$ns duplex-link-op $n4 $n5 orient right

set tcp0 [new Agent/TCP]

$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ftp0 set packetSize_ 500

$ftp0 set interval_ 0.0001

set sink0 [new Agent/TCPSink]

$ns attach-agent $n5 $sink0

$ns connect $tcp0 $sink0

set tcp1 [new Agent/TCP]

$ns attach-agent $n2 $tcp1

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ftp1 set packetSize_ 600

$ftp1 set interval_ 0.001

set sink1 [new Agent/TCPSink]

$ns attach-agent $n3 $sink1

# Direct traffic from "tcp1" to "sink1"

$ns connect $tcp1 $sink1

set file1 [open file1.tr w]

$tcp0 attach $file1

set file2 [open file2.tr w]

$tcp1 attach $file2

$tcp0 trace cwnd_

$tcp1 trace cwnd_

20
# Define a 'finish' procedure

proc finish { } {

global ns nf tf

$ns flush-trace

close $tf

close $nf

exec nam lab3.nam &

exit 0 }

# Schedule start/stop times

$ns at 0.1 "$ftp0 start"

$ns at 5 "$ftp0 stop"

$ns at 7 "$ftp0 start"

$ns at 0.2 "$ftp1 start"

$ns at 8 "$ftp1 stop"

$ns at 14 "$ftp0 stop"

$ns at 10 "$ftp1 start"

$ns at 15 "$ftp1 stop"

# Set simulation end time

$ns at 16 "finish"

$ns run

AWK File:

BEGIN {}

if($6=="cwnd_")

printf("%f\t%f\t\n",$1,$7);

21
}

END {}

OUTPUT:

22
23
EXPERIMENT NO 6

Write a program for distance vector algorithm to find suitable path for transmission.

C File:

#include<stdio.h>

#include<stdlib.h>

void rout_table();

int d[10][10],via[10][10], i, j, k, l, m, n, g[10][10], temp[10][10], ch, cost;

int main()

printf("enter the value of no. of nodes\n");

scanf("%d", &n);

rout_table();

for(i=0; i<n; i++)

for(j=0; j<n; j++)

temp[i][j] = g[i][j];

for(i=0; i<n; i++)

for(j=0; j<n; j++)

via[i][j]= i;

while(1)

for(i=0;i<n;i++)

for(j=0;j<n;j++)

if(d[i][j])

for(k=0;k<n;k++)

if(g[i][j]+g[j][k]<g[i][k])

24
{

g[i][k]=g[i][j]+g[j][k];

via[i][k]=j;

for(i=0;i<n;i++)

printf(“table for router %c\n”,i+97);

for(j=0;j<n;j++)

printf("%c:: %d via %c\n",j+97,g[i][j],via[i][j]+97);

break;

}}

void rout_table () {

printf("\nEnter the routing table: \n");

printf("\t|");

for(i=0;i<=n;i++)

printf("%c\t",i+96);

printf("\n");

for(i=0;i<=n;i++)

printf("------");

printf("\n");

for(i=0;i<n;i++) {

printf("%c|",i+97);

for(j=0;j<n;j++) {

scanf("%d",&g[i][j]);

if(g[i][j]!=999)

d[i][j]=1;

25
}}}

OUTPUT:

enter the value of no. of nodes: 4

Enter the routing table:

|a b c d

------------------------------

a|0 5 1 4

b|5 0 6 2

c|1 6 0 3

d|4 2 3 0

table for router a: a:: 0 via a, b:: 5 via a, c:: 1 via a, d:: 4 via a

table for router b: a:: 5 via b, b:: 0 via b, c:: 5 via d, d:: 2 via b

table for router c: a:: 1 via c, b:: 5 via d, c:: 0 via c, d:: 3 via c

table for router d: a:: 4 via d, b:: 2 via d, c:: 3 via d, d:: 0 via d

26
EXPERIMENT NO 7

a) Write a program for Hamming code.

C File:

#include<stdio.h>

void main() {

int data[10];

int dataatrec[10],c,c1,c2,c3,i;

printf("Enter 4 bits of data one by one\n");

scanf("%d",&data[0]);

scanf("%d",&data[1]);

scanf("%d",&data[2]);

scanf("%d",&data[4]);

data[6]=data[0]^data[2]^data[4];

data[5]=data[0]^data[1]^data[4];

data[3]=data[0]^data[1]^data[2];

printf("\nEncoded data is\n");

for(i=0;i<7;i++)

printf("%d",data[i]);

printf("\n\nEnter received data bits one by one\n");

for(i=0;i< 7;i++)

scanf("%d",&dataatrec[i]);

c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];

c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];

c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];

c=c3*4+c2*2+c1;

27
if(c==0) {

printf("\nNo error while transmission of data\n");

} else {

printf("\nError on position %d",&c);

printf("\nData sent : ");

for(i=0;i<7;i++)

printf("%d",data[i]);

printf("\nData received : ");

for(i=0;i<7;i++)

printf("%d",dataatrec[i]);

printf("\nCorrect message is\n");

if(dataatrec[7-c]==0)

dataatrec[7-c]=1;

else

dataatrec[7-c]=0;

for (i=0;i<7;i++){

printf("%d",dataatrec[i]);

}}}

OUTPUT:

Enter 4 bits of data one by one: 1010.

Encoded Data is 1010010

Enter received data bits one by one: 1000010.

Error on position 5

Data sent: 1010010.

Data received: 1000010.

Correct message is 1010010.

28
b) Program for cyclic Redundancy Check(CRC) in C.

C File:

#include<stdio.h>

#include<string.h>

#define N strlen(gen_poly)

char data[28];

char check_value[28];

char gen_poly[10];

int data_length,i,j;

void XOR(){

// if both bits are the same, the output is 0

// if the bits are different the output is 1

for(j = 1;j < N; j++)

check_value[j] = (( check_value[j] == gen_poly[j])?'0':'1');

void receiver(){

printf("Enter the received data: ");

scanf("%s", data);

printf("\n-----------------------------\n");

printf("Data received: %s", data);

crc();

for(i=0;(i<N-1) && (check_value[i]!='1');i++);

if(i<N-1)

printf("\nError detected\n\n");

else

29
printf("\nNo error detected\n\n");

void crc(){

for(i=0;i<N;i++)

check_value[i]=data[i];

do{

if(check_value[0]=='1')

XOR();

for(j=0;j<N-1;j++)

check_value[j]=check_value[j+1];

check_value[j]=data[i++];

}while(i<=data_length+N-1);

// loop until the data ends

int main()

printf("\nEnter data to be transmitted: ");

scanf("%s",data);

printf("\n Enter the Generating polynomial: ");

scanf("%s",gen_poly);

data_length=strlen(data);

for(i=data_length;i<data_length+N-1;i++)

data[i]='0';

printf("\n----------------------------------------");

printf("\n Data padded with n-1 zeros : %s",data);

printf("\n----------------------------------------");

crc();

30
printf("\nCRC or Check value is : %s",check_value);

for(i=data_length;i<data_length+N-1;i++)

data[i]=check_value[i-data_length];

printf("\n----------------------------------------");

printf("\n Final data to be sent : %s",data);

printf("\n----------------------------------------\n");

receiver();

return 0;

OUTPUT:

Enter data to be transmitted: 1001101

Enter the Generating polynomial: 1011

----------------------------------------

Data padded with n-1 zeros : 1001101000

----------------------------------------

CRC or Check value is : 101

----------------------------------------

Final data to be sent : 1001101101

----------------------------------------

Enter the received data: 1001101101

-----------------------------

Data received: 1001101101

No error detected

31
EXPERIMENT NO 8

Using TCP/IP sockets, write a client server program to make client sending the file name and
the server to send back the contents of the requested file if present.

Client Program:

/* Client Program */

#include <stdio.h>

#include <stdlib.h>

#include <fcntl.h

#include <arpa/inet.h>

#include <unistd.h>

int main()

int sock, n;

char buffer[1024] fname[50];

Sock= socket(AF_INET, SOCK_STREAM, 0)

struct sockaddr_in addr = { AF_INET, htons(1234), inet_addr("127.0.0.1") };

/* keep trying to esatablish connection with server */

while(connect(sock, (struct sockaddr *) &addr, sizeof(addr)));

printf("\nClient is connected to Server");

/* send the filename to the server */

printf("\nEnter file name: ");

scanf("%s", fname);

send(sock, fname, sizeof(fname), 0);

printf("\nRecieved file data\n");

printf("------------------------”);

/* keep printing any data received from the server */

32
while ((n = recv(sock, buffer, sizeof(buffer), 0)) > 0)

buffer[n] = '\0’;

printf("----------------------------------------\n");

return 0;

Server Program:

/* Server Program"/

#include <stdio.h>

#include <stdlib.h>

#include <fcntl.h>

#include <arpa/inet.h>

#include <unistd.h>

int main()

int sersock, sock, fd, n, reuse = 1;

char buffer[1024], fname[50];

/* sockfd = socket(domain, type, protocol) */

sersock = socket(AF_INET, SOCK_STREAM, 0);

struct sockaddr_in addr = (AF_INET, htons(1234), inet_addr("127.0.0.1"));

// Forcefully connecting to same port everytime

setsockopt(sersock, SOL SOCKET, SO_REUSEADDR, (char *)&reuse,

/* attaching socket to port */

bind(sersock, (struct sockaddr") &addr, sizeof(addr));

33
printf("\nServer is Online");

listen(sersock, 5); // listen(int sockfd, int backlog)

sock = accept(sersock, NULL, NULL);

/* receive the filename "/

recv(sock, fname, 50, 0);

printf("\nRequesting for file: %s\n", fname);

/* open the file in read-only mode */

fd = open(fname, O_RDONLY);

if (fd < 0)

send(sock, "InFile not found\n", 15, 0); // strlen(\nFile not found)=15

else

while ((n= read(fd, buffer, sizeof(buffer))) > 0)

send(sock, buffer, n, 0);

} printf("\nFile content sent\n");

close(fd);

return 0;

34
OUTPUT:

35
EXPERIMENT NO 9

Write a program for congestion control using leaky bucket algorithm.

C File:

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#define NOF PACKETS 10

int my_rand(int a) {

int rn (random() % 10) % a; return rn==0?1:m;

int main() {

int packet_sz[NOF_PACKETS], i, clk, b_size, o_rate, p_sz_rm = 0, p_sz, p_time,

op:

for (i=0; i<NOF_PACKETS; ++i)

packet_sz[i] = my_rand(6)*10;

for (i = 0; i < NOF_PACKETS; ++i)

printf("\npacket[%d]:%d bytes\t", i, packet_sz[i]);

printf("\nEnter the Output rate:");

scanf("%d", &o_rate);

printf("Enter the Bucket Size:");

scanf("%d", &b_size);

for (i = 0; i < NOF_PACKETS; ++i) {

if ((packet_sz[i] + p_sz_rm) > b_size)

if (packet_sz[i] > b_size)/compare the packet siz with bucket size/

printf("\n\nIncoming packet size (%dbytes) is Greater than bucket capacity (%dbytes)-


PACKET REJECTED", packet_sz[i], b_size);

36
else

printf("\n\nBucket capacity exceeded-PACKETS REJECTED!!");

else {

p_sz_rm += packet_sz[i]:

printf("\n\nIncoming Packet size: %d", packet_sz[i]);

printf("\nBytes remaining to Transmit: %d", p_sz_rm);

p_time = my_rand(4)*10;

printf("\nTime left for transmission: %d units", p_time); for (clk = 10; clk <=p_time; clk +=
10) {

sleep(1):

if (p_sz_rm) {

if (p_sz_rm <= o_rate)

//"packet size remaining comparing with output

rate"/

opp_sz_rm, p_sz_rm = 0;

else

op=o_rate, p_sz_rm -= o_rate;

printf("\nPacket of size %d Transmitted", op);

printf("--Bytes Remaining to Transmit: %d", p_sz_rm);

else {

printf("\nTime left for transmission: %d units", p_time-cik);

printf("\nNo packets to transmit!!");

}}}}

37
OUTPUT:

38
39

You might also like