Professional Documents
Culture Documents
“COMPUTER NETWORKS”
(21CST502)
Laboratory Record
Certificate
This is to certify that SNEHA SATYAPPA MUCHANDI [1DA21CS137] has satisfactorily
completed the course of experiments in practical “Computer Networks (21CST502)”
prescribed by the Dr. Ambedkar Institute of Technology, university VTU in the Laboratory
of this college in the year 2023-2024.
Sl No Experiment Page No
1 Topology (Bus, 4-9
Ring, Star)
2 Simulate a Simple Topology-TCP/UDP Traffic 10-13
3 Hamming Distance Program 14
4 CRC (Cyclic Redundancy Check) Program 15-17
5 Stop and Wait Program 18-19
6 Client and Server Program 20-24
7 Simulation of Link State Routing Algorithm 25-27
8 Simulation of Distance Vector Routing 28-30
Algorithm
nf [open out.nam w]
$ns flush-trace
close $nf
exit 0
[$ns node]
set lan0 [$ns newLan "$n0 $n1 $n2 $n3 $n4" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd Channel]
#set lan0 [$ns newLan “$node0 $node1$node2 $node3 $node4” 0.5Mb 40ms LL Queue/FQ MAC/Csma/Cd
Channel]
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
$ns run
Output:
Ring Topology:
finish {} { global ns nf
$ns flush-trace
close $nf
exit0
[$ns node]
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3 set
$ns run
Output:
Star Topology:
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0 }
[$ns node]
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
$ns run
Output:
proc finish {} {
global ns nf
$ns flush-trace
# Close the NAM trace file
close $nf
# Execute NAM on the trace file
exit 0
}
# Create four nodes
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"
# Call the finish procedure after
$ns run
#include<iostream.h>
#include<string.h>
int main() {
int i, length, count = 0;
char v1[8], v2[8];
clrscr();
Output:
#include<string.h>
#define N strlen(gen_poly)
check_value[28];
gen_poly[10];
// variables
int data_length,i,j;
void XOR(){
void receiver(){
scanf("%s", data);
printf("\n-----------------------------\n");
crc();
void crc(){
// initializing check_value
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);
}
int main()
{
scanf("%s",data);
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----------------------------------------");
crc();
for(i=data_length;i<data_length+N-1;i++)
data[i]=check_value[i-data_length];
printf("\n----------------------------------------");
receiver();
return 0;
Output:
# destructor proc
finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
$ns at 3.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $tcpsink "
$ns run
Output:
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int main(void)
// Clean buffers:
// Create socket:
return -1;
server_addr.sin_port = htons(2000);
server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
{
Department of CSE, Dr AIT Page | 22
printf("Couldn't bind to the port\n");
return -1;
return -1;
// Respond to client:
printf("Can't send\n");
return -1;
Client-Side Program:
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int main(void)
// Clean buffers:
// Create socket:
return -1;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(2000);
server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
return -1;
if(listen(socket_desc, 1) < 0)
return -1;
// Respond to client:
close(client_sock);
close(socket_desc);
return 0;
Output:
proc finish {} {
global ns nf $ns
flush-trace
close $nf
exec nam out.nam &
exit 0
}
Output:
$ns rtproto DV
Output: