SlideShare a Scribd company logo
SCHOOL OF ENGINEERING AND TECHNOLOGY
Programme: B.Tech.
Lab Record for
Data Communication & Computer Networks
(4CSGC2061)
Semester VI (2023- 24)
Submitted by:
SWAPNIL SUNIL HERAGE
21BBTCS241
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:admin.soet@cmr.edu.in 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
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
packetsdropped.
1-4
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.
5-9
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.
10-14
4
Simulate an Ethernet LAN using N-nodes change
error rate and data rate and compare throughput.
15-18
5
Simulate an Ethernet LAN using N nodes and set
multiple traffic nodes and plot congestion window
for different source/destination.
19-23
6 Write a program for distance vector algorithm to
find suitable path for transmission.
24-26
7
Error Detection Techniques 27-31
A) Write a program for Hamming code/CRC. 27-28
B) Program for cyclic Redundancy Check in C 29-31
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.
32-35
9
Program for congestion control using leaky bucket
algorithm
36-39
1
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 packetsdropped.
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"
2
$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"
3
$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: %dnn”,count)
}
OUTPUT:
4
5
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
}
6
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
$ftp set type FTP
7
#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 ]"
8
AWK File:
BEGIN{
count=0;
} {
if($1=="")
count++
}
END{
printf("The Total no of Packets Drop is %dnn", count)
}
OUTPUT:
9
10
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
11
$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 &
12
$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"
13
$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 :%dnn", count)
}
14
OUTPUT:
15
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
16
$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
17
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:
18
19
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
20
$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_
21
# 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("%ft%ftn",$1,$7);
22
}
END {}
OUTPUT:
23
24
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 nodesn");
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])
{
25
g[i][k]=g[i][j]+g[j][k];
via[i][k]=j;
}
for(i=0;i<n;i++)
{
printf(“table for router %cn”,i+97);
for(j=0;j<n;j++)
printf("%c:: %d via %cn",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("%ct",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;
}}}
26
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
27
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 onen");
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 isn");
for(i=0;i<7;i++)
printf("%d",data[i]);
printf("nnEnter received data bits one by onen");
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;
if(c==0) {
28
printf("nNo error while transmission of datan");
} 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 isn");
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.
29
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 detectednn");
else
printf("nNo error detectednn");
30
}
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();
printf("nCRC or Check value is : %s",check_value);
31
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
32
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 datan");
printf("------------------------”);
/* keep printing any data received from the server */
33
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));
34
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: %sn", fname);
/* open the file in read-only mode */
fd = open(fname, O_RDONLY);
{
if (fd < 0)
send(sock, "InFile not foundn", 15, 0); // strlen(nFile not found)=15
}
else
while ((n= read(fd, buffer, sizeof(buffer))) > 0)
{
send(sock, buffer, n, 0);
}
} printf("nFile content sentn");
close(fd);
return 0;
}
35
OUTPUT:
36
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 bytest", 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("nnIncoming packet size (%dbytes) is Greater than bucket capacity (%dbytes)-
PACKET REJECTED", packet_sz[i], b_size);
37
else
printf("nnBucket capacity exceeded-PACKETS REJECTED!!");
else {
p_sz_rm += packet_sz[i]:
printf("nnIncoming 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!!");
}
}}}}
38
OUTPUT:
39

More Related Content

Similar to B.Tech. Lab Record for Data Communication & Computer Networks

Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
Jaipur National University, Jaipur, Rajasthan, India
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
Rohini Sharma
 
Chapter3 transport
Chapter3 transportChapter3 transport
Chapter3 transport
Diego Corrales
 
NP-lab-manual (1).pdf
NP-lab-manual (1).pdfNP-lab-manual (1).pdf
NP-lab-manual (1).pdf
RaviRajput416403
 
NP-lab-manual.pdf
NP-lab-manual.pdfNP-lab-manual.pdf
NP-lab-manual.pdf
RaviRajput416403
 
NP-lab-manual.docx
NP-lab-manual.docxNP-lab-manual.docx
NP-lab-manual.docx
RaviRajput416403
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
srinivasa gowda
 
June 28 Presentation
June 28 PresentationJune 28 Presentation
June 28 Presentation
Andrew McGarry
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
Wajath
 
Glomosim scenarios
Glomosim scenariosGlomosim scenarios
Glomosim scenarios
Kathirvel Ayyaswamy
 
Week10 transport
Week10 transportWeek10 transport
Week10 transport
kapilpahwabnb
 
IP Utilites
IP UtilitesIP Utilites
IP Utilites
hariprasadnr
 
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecasesLF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
LF_OpenvSwitch
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
SanjayDharmaraj
 
Chapter 3. sensors in the network domain
Chapter 3. sensors in the network domainChapter 3. sensors in the network domain
Chapter 3. sensors in the network domain
Phu Nguyen
 
FEC & File Multicast
FEC & File MulticastFEC & File Multicast
FEC & File Multicast
Yoss Cohen
 
Questrtyuitc mhkkljdghion set- CN lab.doc
Questrtyuitc mhkkljdghion set- CN lab.docQuestrtyuitc mhkkljdghion set- CN lab.doc
Questrtyuitc mhkkljdghion set- CN lab.doc
suriyakalavinoth
 
Chapter_3_V6.01.ppt
Chapter_3_V6.01.pptChapter_3_V6.01.ppt
Chapter_3_V6.01.ppt
HarisAli552157
 
Quantifying the impact of flood attack on
Quantifying the impact of flood attack onQuantifying the impact of flood attack on
Quantifying the impact of flood attack on
ijcsa
 
UNit-4 Transport Layer and its protocols.pdf
UNit-4 Transport Layer  and its protocols.pdfUNit-4 Transport Layer  and its protocols.pdf
UNit-4 Transport Layer and its protocols.pdf
ManimegalaM3
 

Similar to B.Tech. Lab Record for Data Communication & Computer Networks (20)

Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
 
Ns2 introduction 2
Ns2 introduction 2Ns2 introduction 2
Ns2 introduction 2
 
Chapter3 transport
Chapter3 transportChapter3 transport
Chapter3 transport
 
NP-lab-manual (1).pdf
NP-lab-manual (1).pdfNP-lab-manual (1).pdf
NP-lab-manual (1).pdf
 
NP-lab-manual.pdf
NP-lab-manual.pdfNP-lab-manual.pdf
NP-lab-manual.pdf
 
NP-lab-manual.docx
NP-lab-manual.docxNP-lab-manual.docx
NP-lab-manual.docx
 
NS2-tutorial.pdf
NS2-tutorial.pdfNS2-tutorial.pdf
NS2-tutorial.pdf
 
June 28 Presentation
June 28 PresentationJune 28 Presentation
June 28 Presentation
 
NS2-tutorial.ppt
NS2-tutorial.pptNS2-tutorial.ppt
NS2-tutorial.ppt
 
Glomosim scenarios
Glomosim scenariosGlomosim scenarios
Glomosim scenarios
 
Week10 transport
Week10 transportWeek10 transport
Week10 transport
 
IP Utilites
IP UtilitesIP Utilites
IP Utilites
 
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecasesLF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
LF_OVS_17_OVS/OVS-DPDK connection tracking for Mobile usecases
 
NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
 
Chapter 3. sensors in the network domain
Chapter 3. sensors in the network domainChapter 3. sensors in the network domain
Chapter 3. sensors in the network domain
 
FEC & File Multicast
FEC & File MulticastFEC & File Multicast
FEC & File Multicast
 
Questrtyuitc mhkkljdghion set- CN lab.doc
Questrtyuitc mhkkljdghion set- CN lab.docQuestrtyuitc mhkkljdghion set- CN lab.doc
Questrtyuitc mhkkljdghion set- CN lab.doc
 
Chapter_3_V6.01.ppt
Chapter_3_V6.01.pptChapter_3_V6.01.ppt
Chapter_3_V6.01.ppt
 
Quantifying the impact of flood attack on
Quantifying the impact of flood attack onQuantifying the impact of flood attack on
Quantifying the impact of flood attack on
 
UNit-4 Transport Layer and its protocols.pdf
UNit-4 Transport Layer  and its protocols.pdfUNit-4 Transport Layer  and its protocols.pdf
UNit-4 Transport Layer and its protocols.pdf
 

Recently uploaded

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 

B.Tech. Lab Record for Data Communication & Computer Networks

  • 1. SCHOOL OF ENGINEERING AND TECHNOLOGY Programme: B.Tech. Lab Record for Data Communication & Computer Networks (4CSGC2061) Semester VI (2023- 24) Submitted by: SWAPNIL SUNIL HERAGE 21BBTCS241 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:admin.soet@cmr.edu.in www.cmr.edu.in
  • 2. 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
  • 3. 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.
  • 4. INDEX Expt No. Name of Experiment Page No. Remarks 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 packetsdropped. 1-4 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. 5-9 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. 10-14 4 Simulate an Ethernet LAN using N-nodes change error rate and data rate and compare throughput. 15-18 5 Simulate an Ethernet LAN using N nodes and set multiple traffic nodes and plot congestion window for different source/destination. 19-23 6 Write a program for distance vector algorithm to find suitable path for transmission. 24-26 7 Error Detection Techniques 27-31 A) Write a program for Hamming code/CRC. 27-28 B) Program for cyclic Redundancy Check in C 29-31 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. 32-35 9 Program for congestion control using leaky bucket algorithm 36-39
  • 5. 1 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 packetsdropped. 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"
  • 6. 2 $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"
  • 7. 3 $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: %dnn”,count) } OUTPUT:
  • 8. 4
  • 9. 5 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 }
  • 10. 6 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 $ftp set type FTP
  • 11. 7 #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 ]"
  • 12. 8 AWK File: BEGIN{ count=0; } { if($1=="") count++ } END{ printf("The Total no of Packets Drop is %dnn", count) } OUTPUT:
  • 13. 9
  • 14. 10 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
  • 15. 11 $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 &
  • 16. 12 $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"
  • 17. 13 $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 :%dnn", count) }
  • 19. 15 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
  • 20. 16 $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
  • 21. 17 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:
  • 22. 18
  • 23. 19 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
  • 24. 20 $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_
  • 25. 21 # 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("%ft%ftn",$1,$7);
  • 27. 23
  • 28. 24 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 nodesn"); 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]) {
  • 29. 25 g[i][k]=g[i][j]+g[j][k]; via[i][k]=j; } for(i=0;i<n;i++) { printf(“table for router %cn”,i+97); for(j=0;j<n;j++) printf("%c:: %d via %cn",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("%ct",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; }}}
  • 30. 26 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
  • 31. 27 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 onen"); 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 isn"); for(i=0;i<7;i++) printf("%d",data[i]); printf("nnEnter received data bits one by onen"); 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; if(c==0) {
  • 32. 28 printf("nNo error while transmission of datan"); } 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 isn"); 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.
  • 33. 29 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 detectednn"); else printf("nNo error detectednn");
  • 34. 30 } 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(); printf("nCRC or Check value is : %s",check_value);
  • 35. 31 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
  • 36. 32 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 datan"); printf("------------------------”); /* keep printing any data received from the server */
  • 37. 33 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));
  • 38. 34 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: %sn", fname); /* open the file in read-only mode */ fd = open(fname, O_RDONLY); { if (fd < 0) send(sock, "InFile not foundn", 15, 0); // strlen(nFile not found)=15 } else while ((n= read(fd, buffer, sizeof(buffer))) > 0) { send(sock, buffer, n, 0); } } printf("nFile content sentn"); close(fd); return 0; }
  • 40. 36 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 bytest", 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("nnIncoming packet size (%dbytes) is Greater than bucket capacity (%dbytes)- PACKET REJECTED", packet_sz[i], b_size);
  • 41. 37 else printf("nnBucket capacity exceeded-PACKETS REJECTED!!"); else { p_sz_rm += packet_sz[i]: printf("nnIncoming 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!!"); } }}}}
  • 43. 39