ACN Practical File[1]
ACN Practical File[1]
1
LIST OF EXPERIMENTS
Sr. Title of Experiment Pg. Date Signature
No. No.
1 Write a program for distance vector algorithm to find suitable path 3-5
for transmission.
2 Using TCP/IP sockets, write a client, server program to 6-10
make the client send the file name and to make the server
send back the contents of the requested file if present.
3 Write a program for Hamming code generation for error 11-14
detection and correction.
2
EXPERIMENT NO.: 1
Title of Experiment: Write a program for distance vector algorithm to find suitable path for transmission
#include <stdio.h>
struct Router {
};
int i, j, k;
// Initialize routers
routers[i].cost[j] = graph[i][j];
int updated;
do {
updated = 0;
3
routers[i].nextHop[j] = k;
updated = 1;
printf("Destination\tCost\tNext Hop\n");
printf("%d\t\t%d\t%d\n", j + 1, routers[i].cost[j],
routers[i].nextHop[j] == -1 ? -1 : routers[i].nextHop[j] + 1) }
printf("\n"); }}
int main() {
int graph[10][10], n, i, j;
scanf("%d", &n);
scanf("%d", &graph[i][j]);
distanceVectorRouting(graph, n);
return 0;
Output :-
4
5
EXPERIMENT NO.: 2
Title of Experiment: Using TCP/IP sockets, write a client, server program to make the client send the
file name and to make the server send back the contents of the requested file if present.
// Server.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
int main() {
// Create socket
perror("Socket failed");
exit(EXIT_FAILURE);
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
6
address.sin_port = htons(PORT);
perror("Bind failed");
exit(EXIT_FAILURE);
if (listen(server_fd, 3) < 0) {
perror("Listen failed");
exit(EXIT_FAILURE);
while (1) {
(socklen_t*)&addr_len)) < 0) {
perror("Accept failed");
exit(EXIT_FAILURE);
if (file == NULL) {
7
// Send "File not found" message to client
} else {
char file_buffer[BUFFER_SIZE];
fclose(file);
return 0;
// Client.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
8
#define BUFFER_SIZE 1024
int main() {
int sock = 0;
char filename[BUFFER_SIZE];
// Create socket
exit(EXIT_FAILURE);
server_address.sin_family = AF_INET;
server_address.sin_port = htons(PORT);
exit(EXIT_FAILURE);
// Connect to server
perror("Connection failed");
exit(EXIT_FAILURE);
printf("Connected to server.\n");
9
scanf("%s", filename);
memset(buffer, 0, BUFFER_SIZE);
close(sock);
return 0;
10
EXPERIMENT NO.: 3
Title of Experiment: Write a program for Hamming code generation for error detection and
correction.
#include <stdio.h>
#include <math.h>
int hammingCode[totalBits];
hammingCode[i] = 0;}
int j = 0;
continue;}
hammingCode[i] = data[j++];}
int parity = 0;
parity ^= hammingCode[k];}}
11
hammingCode[i] = parity;}
printf("%d", hammingCode[i]);}
printf("\n");}
int errorPos = 0;
int parity = 0;
parity ^= hammingCode[k];}}
if (parity != 0) {
errorPos += (i + 1);}}}
if (errorPos == 0) {
12
hammingCode[errorPos - 1] ^= 1; // Correct the error
printf("%d", hammingCode[i]);}
printf("\n");}}
int main() {
int dataBits;
scanf("%d", &dataBits);
int data[dataBits];
scanf("%d", &data[i]);}
int hammingCode[totalBits];
generateHammingCode(data, dataBits);
int errorPos;
scanf("%d", &errorPos);
detectAndCorrectError(hammingCode, totalBits);
return 0;}
13
14
EXPERIMENT NO.: 4
Title of Experiment: Write a program for congestion control using leaky bucket algorithm.
PARTB (Simulate the following Computer Networks concepts using any network simulators)
#include <stdio.h>
int main() {
scanf("%d", &bucket_size);
scanf("%d", &output_rate);
scanf("%d", &num_packets);
scanf("%d", &packet_size);
continue;}
current_bucket += packet_size;
15
printf("Packet %d of size %dKB added to the bucket. Current bucket size: %dKB\n", i,
packet_size, current_bucket);} else {
printf("Transmitting data...\n");
if (current_bucket > 0) {
printf("Sent %dKB from the bucket. Remaining bucket size: %dKB\n", output_rate,
current_bucket - output_rate);
current_bucket -= output_rate;} }
sleep(1);}
printf("Sent %dKB from the bucket. Remaining bucket size: %dKB\n", output_rate,
current_bucket - output_rate);
current_bucket -= output_rate;}
sleep(1);}
return 0;}
16
17
EXPERIMENT NO.: 5
Title of Experiment: Simulate a three nodes point -to-point network with duplex links between them.
Set the queue size and vary the bandwidth and find the number of packets dropped.
# Create duplex links between nodes with initial bandwidth and delay
18
$cbr set packetSize_ 1000
proc finish {} {
global ns tracefile
$ns flush-trace
close $tracefile
exit 0
global ns
$q queue-monitor
19
# Schedule simulation end
$ns run
ns script.tcl
2. Analyze Trace File: Use grep to filter packet drops from the trace file:
20
EXPERIMENT NO.: 6
Title of Experiment: Simulate the network with five nodes n0, n1, n2, n3, n4, forming a star topology.
The node n4 is at the center. Node n0 is a TCP source, which transmits packets to node n3 (a TCP sink)
through the node n4. Node n1 is another traffic source, and sends UDP packets to node n2 through n4.
The duration of the simulation time is 10 seconds.
21
# Create a UDP agent for the source and sink
proc finish {} {
global ns tracefile
$ns flush-trace
close $tracefile
exit 0
22
# Schedule end of simulation
$ns run
23
EXPERIMENT NO.: 7
Title of Experiment Simulate to study transmission of packets over Ethernet LAN and determine the
number of packets drop destination.
24
set cbr [new Application/Traffic/CBR]
proc finish {} {
global ns tracefile
$ns flush-trace
close $tracefile
exit 0
global ns
$q queue-monitor
25
$ns run
26
EXPERIMENT NO.: 8
Title of Experiment: Write a TCL Script to simulate working of multicasting routing protocol and
analyze the throughput of the network.
# Create nodes
27
$ns enable-mcast DVMRP ;# Dense Mode Routing Protocol
# Start traffic
# Finish procedure
proc finish {} {
$ns flush-trace
close $tracefile
28
close $namfile
exit 0
$ns run
29
EXPERIMENT NO.: 9
Title of Experiment: Simulate the different types of internet traffic such as FTP and TELNET over a
wired network and analyze the packet drop and packet delivery ratio in the network.
30
$ns attach-agent $n0 $tcp_ftp
# Finish procedure
proc finish {} {
$ns flush-trace
close $tracefile
31
close $namfile
exit 0
$ns run
32
EXPERIMENT NO.: 10
Title of Experiment: Simulate the different type of internet traffic such as FTP and TELNET over a
wired network and analyze the packet drop and packet delivery ratio in the network.
33
set sink_ftp [new Agent/TCPSink]
# Finish procedure
proc finish {} {
$ns flush-trace
close $tracefile
close $namfile
34
exit 0
# Run simulation
$ns run
Run the TCL Script: Save the provided TCL script as ftp_telnet_simulation.tcl. Execute it using NS2:
ns ftp_telnet_simulation.tcl
1. Generate Trace File: The simulation will produce a trace file named traffic_analysis.tr.
2. Open NAM File:
nam traffic_analysis.nam
Analyze Output
35