0% found this document useful (0 votes)
32 views35 pages

19EC412 Networks Manual

Uploaded by

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

19EC412 Networks Manual

Uploaded by

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

Thandalam,Chennai–602105.

Department of Electronics and Communication Engineering

LAB MANUAL

COMMUNICATION NETWORKS (19EC412)

(VII SEM ECE)

1
LIST OF EXPERIMENTS:

1. Implementation of Error Detection / Error Correction Techniques


2. Implementation of Stop and Wait Protocol and sliding window
3. Implementation and study of Go-back-N and selective repeat protocols
4. Implementation of High Level Data Link Control
5. Study of Socket Programming and Client – Server model
6. Write a socket Program for Echo/Ping/Talk commands.
7. To create scenario and study the performance of network with CSMA / CA protocol and compare with
CSMA/CD protocols.
8. Network Topology – Star, Bus, Ring
9. Implementation of distance vector routing algorithm
10. Implementation of Link state routing algorithm
11. Study of Network simulator (NS 2) and simulation of Congestion Control Algorithms using NS 2
12. Encryption and decryption.

2
INDEX

S.NO DATE NAME OF EXPERIMENT MARKS SIGNATURE

3
CYCLE–I EXPERIMENTS

1. SIMULATION OF STAR TOPOLOGY NETWORK


2. IMPLEMENTATION OF DISTANCE VECTOR ROUTING PROTOCOL (RIP)
3. IMPLEMENTATION OF LINK STATE ROUTING PROTOCOL (OSPF)
4. CREATING A BUS, RING, STAR TOPOLOGY USING NS2
5. STUDY THE PERFORMANCE OF THE NETWORK WITH CSMA/CD
6. IMPLEMENTATION OF STOP AND WAIT PROTOCOL

4
EXPT.NO: 1
DATE:

SIMULATION OF STAR TOPOLOGY NETWORK

AIM:

To simulate a network with Topology, using Cisco Packet Tracer and to verify the connectivity between
computer using ICMP.

EQUIPMENTS REQUIRED:

Desktop computer
Cisco Packet Tracer 5.0 Software.

IP ASSIGNMENT:

NAME IP ADDRESS SUBNET MASK NETWORK CLASS


PCO 192.168.1.10 255.255.255.0 192.168.1.1 Class C
PC1 192.168.1.30 255.255.255.0 192.168.1.1 Class C
PC2 192.168.1.20 255.255.255.0 192.168.1.1 Class C
PC3 192.168.2.20 255.255.255.0 192.168.1.2 Class C
PC4 192.168.2.30 255.255.255.0 192.168.1.2 Class C
PC5 192.168.2.10 255.255.255.0 192.168.1.2 Class C

PROCEDURE:

STEP:1 Open a Packet Tracer Software.


STEP:2 Drag a 2950 Switch from tool bar and drop it in work area.
STEP:3 Drag a PC Terminal from tool bar and drop it in work area.
STEP:4 Repeat the Step:3 for four terminals.
STEP:5 Select Copper straight-through cable from tool bar and connect each PC Terminal with
2950 switch in different ports.
STEP:6 Click on the PC Terminal, Select the fast Ethernet Interface from configuration table
and set IP address and Subnet mask.
STEP:7 Repeat the Step:6 for all the PC Terminals.
STEP:8 click on the PC Terminal and Select Terminal from the Desktop tab to verify the
connectivity between the PC Terminals using Ping Command.
STEP:9 Select “add simple PDU” from tool bar and place it in source and destination PC
Terminals to verify the connectivity

5
IP CONNECTIVITY TABLE:

SENDER/RECEIVER PCO PC1 PC2 PC3 PC4 PC5


PC0
PC1
PC2
PC3
PC4
PC5

NETWORK DIAGRAM:

BASIC NETWORKING COMMANDS


IP Configuration Details:
(i) ipconfig Command(windows OS) (or) ifconfig command(Linux OS)
Syntax:
C:\> ipconfig
(ii) ipconfig/all Command:
Syntax:
C:\> ipconfig /all
Testing Connectivity:
(i) Self Ping Command:
Syntax:
c:\> ping <ipaddress>
Example:
C:\> ping 172.17.80.201
C:\> ping 127.0.0.1
(ii) Ping to Destination
Syntax:
c:\> ping <destination-ipaddress>

6
Example:
C:\ping 172.17.80.1
To Display IP to Physical address Translation Table and trace the route
i) Arp Command
Syntax:
C:\arp –a
(ii)To trace the route
Syntax:
C:\tracert <ipaddress (or) specific address>
Example:
C:\tracert 172.17.80.1
C:\tracert www.saveetha.ac.in

RESULT:

Thus, the computers in same network are able to communicate with each other and the communication
between computers is verified.

7
EXPT.NO: 2
DATE:

IMPLEMENTATION OF DISTANCE VECTOR ROUTING PROTOCOL (RIP)

AIM:

To connect computers in multiple networks using Distance Vector Routing Protocol and to verify the
connectivity between computers.

EQUIPMENTS REQUIRED:

SNO NAME QUANTITY


1 Desktop computer 4
2 Cisco 1800 router 2
3 Usb to serial converter 2
4 Cisco 2900 switch 2
5 CAT 6 patch cable 10
6 Console cable 2

IP ASSIGNMENT:

NAME IP ADDRESS SUBNET NETWORK CLASS GATEWAY


MASK
PC0 192.168.0.1 255.255.255.0 192.168.0.0 C 192.168.0.200
PC1 192.168.0.2 255.255.255.0 192.168.0.0 C 192.168.0.200
PC2 192.168.1.1 255.255.255.0 192.168.1.0 C 192.168.1.200
PC3 192.168.1.2 255.255.255.0 192.168.1.0 C 192.168.1.200
PC4 192.168.2.1 255.255.255.0 192.168.2.0 C 192.168.2.200
PC5 192.168.2.2 255.255.255.0 192.168.2.0 C 192.168.2.200
ROUTER0 192.168.0.200 255.255.255.0 192.168.0.0 C
INTER F 0/0
ROUTER 0 192.168.1.200 255.255.255.0 192.168.1.0 C
SERIAL2/0
ROUTER1 192.168.1.201 255.255.255.0 192.168.1.0 C
INTER F 0/0
ROUTER 1 192.168.2.200 255.255.255.0 192.168.2.0 C
SERIAL2/0

8
NETWORK DIAGRAM:

PROCEDURE:

STEP:1 Open a Packet Tracer Software.


STEP:2 Drag two 2900 Switches, two Cisco 1800 Routers, four PC Terminals from tool bar
and drop it in work area.
STEP:3 Connect all the PC Terminals and Routers through Switches as shown in the network
diagram using CAT 6 Patch cables.
STEP:4 Configure IP address and Gateway in all PC Terminals.
STEP:5 Configure ROUTER0 and restart ROUTER0.
STEP:6 Configure ROUTER1 and restart ROUTER1.
STEP:7 Verify the connectivity between PC Terminals in different networks using Ping
command.

ROUTER CONFIGURATION:
Command: ROUTER0
Router >enable
Router#config
Router(config)#interface fast Ethernet 0/0
Router(config-if)#no shutdown
Router(config-if)#ip address
Router(config-if)#exit
Router(config)#interface serial 2/0
Router(config-if)#no shutdown
Router(config-if)#ip address

Router(config-if)#clock rate 64000


Router(config-if)#exit
///////////////////////////////////////////////////configuring RIP////////////////////////////////////////////////////////
Router(config)#router rip
Router(config-router)#network
Router(config-router)#network
9
Router(config)#exit
////////////////////////////////////////////////End configuring RIP//////////////////////////////////////////////////////
Router#show ip address

Command: ROUTER1
Router >enable
Router#config
Router(config)#interface fast Ethernet 0/0
Router(config-if)#no shutdown
Router(config-if)#ip address
Router(config-if)#exit
Router(config)#interface serial 2/0
Router(config-if)#no shutdown
Router(config-if)#ip address
Router(config-if)#exit
///////////////////////////////////////////////////configuring RIP////////////////////////////////////////////////////////
Router(config)#router rip
Router(config-router)#network
Router(config-router)#network
Router(config)#exit
////////////////////////////////////////////////End configuring RIP//////////////////////////////////////////////////////
Router#show ip address

RESULT:

Thus, the computers in multiple networks using Distance Vector Routing Protocol is connected and the
connectivity between the computers is verified.

10
EXPT.NO: 3
DATE:

IMPLEMENTATION OF LINK STATE ROUTING PROTOCOL (OSPF)

AIM:

To connect computers in multiple networks using Open Shortest Path First Routing Protocol and to verify
the connectivity between computers.

EQUIPMENTS REQUIRED:

S.NO NAME QUANTITY


1 Desktop computer 4
2 Cisco 1800 router 2
3 DCE-DTE cable 1
4 Cisco 2900 switch 2
5 CAT 6 patch cable 6
6 Console cable 2

IP ASSIGNMENT:

NAME IP ADDRESS SUBNET NETWORK CLASS GATEWAY


MASK
PC0 192.168.0.1 255.255.255.0 192.168.0.0 C 192.168.0.200
PC1 192.168.0.2 255.255.255.0 192.168.0.0 C 192.168.0.200
PC2 192.168.2.1 255.255.255.0 192.168.2.0 C 192.168.1.200
PC3 192.168.2.2 255.255.255.0 192.168.2.0 C 192.168.1.200
ROUTER 0/ 192.168.0.200 255.255.255.0 192.168.0.0 C
INTER F 0/0
ROUTER 0 192.168.1.1 255.255.255.0 192.168.1.0 C
SERIAL2/0
ROUTER1/ 192.168.2.200 255.255.255.0 192.168.2.0 C
INTER F0/0
ROUTER 1 192.168.1.2 255.255.255.0 192.168.1.0 C
SERIAL2/0

11
NETWORK DIAGRAM:

PROCEDURE:

STEP:1 Open a Packet Tracer Software.


STEP:2 Drag two 2900 Switches, two Cisco 1800 Routers, four PC Terminals from tool bar
and drop it in work area.
STEP:3 Connect all the PC Terminals and Routers through Switches as shown in the network
diagram using CAT 6 Patch cables.
STEP:4 Configure IP address and Gateway in all PC Terminals.
STEP:5 Configure Delhi router IP address, Save configuration and restart Delhi router.
STEP:6 Configure Chennai router IP address, Save configuration and restart Chennai router.
STEP:7 Check the connectivity between the computers in network.
STEP:8 Configure OSPF in Delhi router , Save configuration and restart Delhi router.
STEP:9 Configure OSPF in Chennai router , Save configuration and restart Chennai router.
STEP:10 Verify the connectivity between PC Terminals in different networks using Ping
command.
STEP:11 Check the routing table in Delhi router and Chennai router using show ip route
command.

ROUTER CONFIGURATION:

Command: ROUTER0 (Delhi)


IP Configuration:
Router >enable
Router#configure terminal
Router(config)#hostname Delhi
Delhi(config)#interface fast Ethernet 0/0
Delhi(config-if)#ip address
Delhi(config-if)#no shutdown
Delhi(config-if)#exit
Delhi(config)#interface serial 2/0
12
Delhi(config-if)#ip address
Delhi(config-if)#clock rate 64000
Delhi(config-if)#no shutdown
Delhi(config-if)#exit

Command: ROUTER1 (Chennai)


IP Configuration:
Router >enable
Router#configure terminal
Router(config)#hostname Chennai
Chennai(config)#interface serial 2/0
Chennai (config-if)#ip address
Chennai (config-if)#no shutdown
Chennai (config-if)#exit
Chennai (config)#interface fast Ethernet 0/0
Chennai (config-if)#ip address
Chennai (config-if)#no shutdown
Chennai (config-if)#exit
Chennai (config)#exit

OSPF Configuration to Delhi Router:


Router >enable
Router# configure terminal
Router(config)#hostname Delhi
Delhi(config)#router ospf 1
Delhi(config-router)#network
Delhi(config-router)#network
Delhi(config-router)#end

OSPF Configuration to Chennai Router:


Router >enable
Router#configure terminal
Router(config)#hostname Chennai
Chennai (config)#router ospf 1
Chennai (config-router)#network
Chennai (config-router)#network

Chennai (config-router)#end

RESULT:

Thus, the computers in multiple networks using Open Shortest Path First Routing Protocol is connected
and the connectivity between the computers is verified.

13
EXPT.NO: 4
DATE:

CREATING A BUS TOPOLOGY USING NS2


AIM:

To create and monitor Bus Topology and effective data transmission using NS2 Software.

APPARATUS REQUIRED:

PC System with linux OS,NS2 software.

ALGORITHM:

STEP:1 Start the program.


STEP:2 Declare the global variables ns for creating a new simulator.
STEP:3 Open the network animator file in the write mode.
STEP:4 Open the trace file in the write mode.
STEP:5 Transfer the packets in network.
STEP:6 Create the capable no of nodes.
STEP:7 Create the duplex-link between the nodes including the delay time, bandwidth and
dropping queue mechanism.
STEP:8 Set a tcp connection for source node.
STEP:9 Set the destination node using tcp sink.
STEP:10 Set the window size and the packet size for the tcp.
STEP:11 Set up the ftp over the tcp connection.
STEP:12 Create the traffic generator CBR for the source and destination files.
STEP:13 Define the plot window and finish procedure.
STEP:14 In the definition of the finish procedure declare the global variables.
STEP:15 Close the trace file and namefile and execute the network animation file.
STEP:16 At the particular time call the finish procedure.
STEP:17 Stop the program.

PROGRAM:

BUS
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
14
}
#Create five nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
#Create Lan between the nodes
set lan0 [$ns newLan "$n0 $n1 $n2 $n3 $n4" 0.5Mb 40ms LL Queue/DropTail MAC/Csma/Cd
Channel]
#Create a TCP agent and attach it to node n0
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $n1 $tcp0
#Create a TCP Sink agent (a traffic sink) for TCP and attach it to node n3
set sink0 [new Agent/TCPSink]
$ns attach-agent $n3 $sink0
#Connect the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Create a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.01
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run

RESULT:

Thus, the Bus, Topology using NS2 software is created and monitored.

15
EXPT.NO: 5
DATE:

STUDY THE PERFORMANCE OF THE NETWORK WITH CSMA/CD

AIM:

To write a NS2 program to Study the performance of the network with Carrier Sense Multiple
Access/Collision Detection
.
APPARATUS REQUIRED:

PC System with Linux OS, NS2 software.

ALGORITHM:

STEP:1 Start the program.


STEP:2 Declare the global variables ns for creating a new simulator.
STEP:3 Set the color for packets.
STEP:4 Open the network animator file in the write mode.
STEP:5 Open the trace file and the win file in the write mode.
STEP:6 Transfer the packets in network.
STEP:7 Create the capable no of nodes.
STEP:8 Create the duplex-link between the nodes including the delay time,bandwidth
and dropping queue mechanism.
STEP:9 Give the position for the links between the nodes.
Step:10 Set a tcp connection for source node.
STEP:11 Set the destination node using tcp sink.
STEP:12 Set the window size and the packet size for the tcp.
STEP:13 Set up the ftp over the tcp connection.
STEP:14 Set the udp and tcp connection for the source and destination.
STEP:15 Create the traffic generator CBR for the source and destination files.
STEP:16 Define the plot window and finish procedure.
STEP:17 In the definition of the finish procedure declare the global variables.
STEP:18 Close the trace file and namefile and execute the network
animation file.
STEP:19 At the particular time call the finish procedure.
STEP:20 Stop the program.

PROGRAM:

#Lan simulation – mac.tcl


set ns [new Simulator]
#define color for data flows
$ns color 1 blue
$ns color 2 red
#open tracefile
16
set tracefile1 [open out.tr w]
$ns trace-all $tracefile1
#open nam file
set namfile [open out.nam w]
$ns namtrace-all $namfile
#define the finish procedure
proc finish {} {
global ns tracefile1 namfile
$ns flush-trace
close $tracefile1
close $namfile
exec nam out.nam&
exit 0
}
#create six 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]
#Specify color and shape for nodes
$n1 color Red
$n1 shape box
#create links between the nodes
$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
# Create a LAN
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTailMAC/Csma/Cd Channel]
#Give node position
set lan [$ns newLan "$n3 $n4 $n5" 0.5Mb 40ms LL Queue/DropTailMAC/Csma/Cd Channel]
#Give node position

$ns duplex-link-op $n0 $n2 orient right-down


$ns duplex-link-op $n1 $n2 orient right-up
$ns simplex-link-op $n2 $n3 orient right
$ns simplex-link-op $n3 $n2 orient left
#setup TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set packet_size_ 552
#set ftp over tcp connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
17
#setup a UDP connection
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $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_ 0.05Mb
$cbr set random_ false
#scheduling the events
$ns at 0.0 "$n0 label TCP_Traffic"
$ns at 0.0 "$n1 label UDP_Traffic"
$ns at 0.3 "$cbr start"
$ns at 0.8 "$ftp start"
$ns at 7.0 "$ftp stop"
$ns at 7.5 "$cbr stop"
$ns at 8.0"finish"
$ns run

RESULT:

Thus, the NS2 program to Study the performance of the network with Carrier Sense Multiple
Access/Collision Detection is written.

18
EX.NO:6
DATE

IMPLEMENTATION OF STOP AND WAIT PROTOCOL

AIM:
To implement stop and wait protocol using NS2 program.

EQUIPMENTS REQUIRED:
1. PC with ubuntu operating system
2. NS2 Software

ALGORITHM:
Step 1: Start the program.
Step 2: Declare the global variables ns for creating a new simulator.
Step 3: Open the network animator file in the write mode.
Step 4: Open the trace file in the write mode.
Step 5: Transfer the packets in network.
Step 6: Create the capable no of nodes.
Step 7: Create the duplex-link between the nodes including the delay time, bandwidth and dropping queue
mechanism.
Step 8: Set a tcp connection for source node.
Step 9: Set the destination node using tcp sink.
Step 10: Set the window size and the packet size for the tcp.
Step 11: Set up the ftp over the tcp connection.
Step 12: Define the plot window and finish procedure.
Step 13: In the definition of the finish procedure declare the global variables.
Step 14: Close the trace file and namfile and execute the network animation file.
Step 15: At the particular time call the finish procedure.
Step 16: Stop the program.

PROGRAM:
set ns [new Simulator]
set namfile [open out.nam w]
$ns namtrace-all $namfile
proc finish {} {
global ns namfile
$ns flush-trace
close $namfile
exec nam out.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n1 2Mb 200ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 2Mb 10ms DropTail
$ns queue-limit $n0 $n1 15
19
set tcp [new Agent/TCP]
$tcp set window_ 1
$tcp set maxcwnd_ 1
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
set sink [new Agent/TCPSink]
$ns attach-agent $n1 $sink
$ns connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns add-agent-trace $tcp tcp
#$ns moniter-agent-trace $tcp
$tcp tracevar cwnd_
$ns at 0.1 "$ftp start"
$ns at 3.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n1 $sink"
$ns at 3.5 "finish"
$ns at 0.0 "$ns trace-annotate \"Stop and Wait with normal operation\""
$ns at 0.05 "$ns trace-annotate \"FTP starts at 0.1\""
$ns at 0.11 "$ns trace-annotate \"Send Packet_0\""
$ns at 0.35 "$ns trace-annotate \"Recive Ack_0\""
$ns at 0.56 "$ns trace-annotate \"Send Packet_1\""
$ns at 0.79 "$ns trace-annotate \"Recive Ack_1\""
$ns at 0.99 "$ns trace-annotate \"Send Packet_2\""
$ns at 1.23 "$ns trace-annotate \"Recive Ack_2\""
$ns at 1.43 "$ns trace-annotate \"Send Packet_3\""
$ns at 1.67 "$ns trace-annotate \"Recive Ack_3\""
212215106298
$ns at 1.88 "$ns trace-annotate \"Send Packet_4\""
$ns at 2.11 "$ns trace-annotate \"Recive Ack_4\""
$ns at 2.32 "$ns trace-annotate \"Send Packet_5\""
$ns at 2.55 "$ns trace-annotate \"Recive Ack_5\""
$ns at 2.75 "$ns trace-annotate \"Send Packet_6\""
$ns at 2.99 "$ns trace-annotate \"Recive Ack_6\""
$ns at 3.1 "$ns trace-annotate \"FTP stops\""
$ns at 0.0 "$n0 label Sender"
$ns at 0.0 "$n1 label Reciver"
$ns run

RESULT:
Thus the stop and wait protocol is implemented and the output is executed and verified
successfully.

20
CYCLE–II EXPERIMENTS

7. IMPLEMENTATION OF GO-BACK-N PROTOCOL


8. STUDY OF SOCKET PROGRAMMING AND CLIENT SERVER MODEL
9. IMPLEMENTATION OF ERROR DETECTION USING CRC-CCITT[16 BIT] TECHNIQUE
10. IMPLEMENTATION OF ENCRYPTION AND DECRYPTION
11. STUDY OF NETWORK SIMULATOR AND CONGESTION CONTROL USING NS

21
EX.NO:7
DATE
IMPLEMENTATION OF GO-BACK-N PROTOCOL

AIM:
To write and execute a program for Go-Back-N protocol.

EQUIPMENTS REQUIRED:
Personal Computer
Turbo C Compiler

PROCEDURE:
1. Connect two computers in Wired/Wireless LAN.
2.Make sure that two computers are in one network and could able to ping each other.
3.In the codeblocker open new c file and type the program.
4.In the menu choose->Project->Properties->Project Build options->Linker settings->Add
netproto and pthread.
5. Execute the program in both server and client.
6. Enter the IP address of the remote machine, port address of both local & remote machine and
error rate.
7. Choose the file and verify the go back protocol operation.

PROGRAM:
#include<stdio.h>
/* Assume 7 frames of data are to sent using GO BACK N ARQW*/
void main()
{char frame[8][10];
int i,j;
printf("GO BACK N ARQ\n");
printf("Enter message in format\n");
for(i=1;i<=7;i++)
{
printf("Content for frame %d :",i);
scanf("%s",&frame[i]);
}
printf("Enter frame number with no ACK :");
scanf("%d",&j);
for(i=1;i<=7;i++)
{if(i<j)
printf("\n Sending frame %d \n FRAME ACKNOWLEDGED.....\n",i);
else
printf("\n Frame not Acknowledeged........\n");
}
printf("No Acknowlegement for frame %d ...\n",j);
for(i=j;i<=7;i++)
{
printf("Resending....Content from frame %d :%s\n\n",i,frame[i]);
}
}

22
RESULT:
Thus the Go-Back-N protocol was implemented and the output is verified successfully.

23
EX.NO:8
DATE

STUDY OF SOCKET PROGRAMMING AND CLIENT SERVER MODEL


AIM:
To write a Socket program to transfer data between Client and Server.
EQUIPMENTS REQUIRED:
1. PC with Linux operating system
PROCEDURE:
1. Connect two computers in Wired/Wireless LAN.
2. Make sure that two computers are in one network and could able to ping each other.
3. In the terminal type gedit filename.c for typing the program.
4. After typing to compile gcc filename.c
5. To execute type ./a.out
6. Execute the program in both server and client.
7. Enter the IP address of the server in client machine.
8. Enter the data to be transferred and verify the size of the data.
212215106298
PROGRAM:
SERVER
/*
C socket server example
*/
#include<stdio.h>
#include<string.h> //strlen
#include<sys/socket.h>
#include<arpa/inet.h> //inet_addr
#include<unistd.h> //write
int main(int argc , char *argv[])
{
int socket_desc , client_sock , c , read_size;
struct sockaddr_in server , client;
char client_message[2000];
//Create socket
socket_desc = socket(AF_INET , SOCK_STREAM , 0);
if (socket_desc == -1)
{
printf("Could not create socket");
}
puts("Socket created");
//Prepare the sockaddr_in structure
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons( 8888 );
//Bind
if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
{
//print the error message
perror("bind failed. Error");
return 1;
24
}
puts("bind done");
//Listen
listen(socket_desc , 3);
//Accept and incoming connection
puts("Waiting for incoming connections...");
c = sizeof(struct sockaddr_in);
212215106298
//accept connection from an incoming client
client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
if (client_sock < 0)
{
perror("accept failed");
return 1;
}
puts("Connection accepted");
//Receive a message from client
while( (read_size = recv(client_sock , client_message , 2000 , 0)) > 0 )
{
//Send the message back to client
write(client_sock , client_message , strlen(client_message));
}
if(read_size == 0)
{
puts("Client disconnected");
fflush(stdout);
}
else if(read_size == -1)
{
perror("recv failed");
}
return 0;
}
CLIENT
/*
C ECHO client example using sockets
*/
#include<stdio.h> //printf
#include<string.h> //strlen
#include<sys/socket.h> //socket
#include<arpa/inet.h> //inet_addr
int main(int argc , char *argv[])
{
int sock;
struct sockaddr_in server;
char message[1000] , server_reply[2000];
//Create socket
sock = socket(AF_INET , SOCK_STREAM , 0);
if (sock == -1)
{
25
printf("Could not create socket");
}
puts("Socket created");
server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_family = AF_INET;
server.sin_port = htons( 8888 );
//Connect to remote server
if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0)
{
perror("connect failed. Error");
return 1;
}
puts("Connected\n");
//keep communicating with server
while(1)
{
printf("Enter message : ");
scanf("%s" , message);
//Send some data
if( send(sock , message , strlen(message) , 0) < 0)
{
puts("Send failed");
return 1;
}
//Receive a reply from the server
if( recv(sock , server_reply , 2000 , 0) < 0)
{
puts("recv failed");
break;
}
puts("Server reply :");
puts(server_reply);
}
close(sock);
return 0;
}

RESULT:
Thus a socket program is written to transfer data between client and server.

26
EX.NO:9
DATE

IMPLEMENTATION OF ERROR DETECTION USING CRC-CCITT[16 BIT] TECHNIQUE


AIM:
To write a program for error Detection using Cyclic Redundancy Check (CRC-16 bit) technique.

EQUIPMENTS REQUIRED:
1. Personal Computer
2. C++ compiler

ALGORITHM:
1] Open code blocks application and create a new file.
2] After creating the file type the codes.
3] After typing the codes save the file using the .c extension in the desired location.
4] Run the program using build and run.
5] Give polynomial values and the generated polynomial is obtained, and by other means arraive
at the desired output which uses the error detection technique.
6] Thus the output polynomial is obtained through this technique.

PROGRAM:
#include<stdio.h>
#include<string.h>
#define N strlen(g)
char t[128],cs[128],g[]="111";
int a,e,c;
void xor()
{
for(c=1;c<N;c++)
cs[c]=((cs[c]==g[c])?'0':'1');
}
void crc()
{
for(e=0;e<N;e++)
cs[e]=t[e];
212215106298
do{
if(cs[0]=='1')xor();
for(c=0;c<N-1;c++)
cs[c]=cs[c+1];
cs[c]=t[e++];
}
while(e<=a+N-1);
}
void main()
{
printf("\n Enter poly:");
scanf("%s",t);
printf("\nGen poly is : %s",g);
a=strlen(t);
27
for(e=a;e<a+N-1;e++)
t[e]='0';
printf("\nModfied t[u] :%s",t);
crc();
printf("\nChecksum is:%s",cs);
for(e=a;e<a+N-1;e++)
t[e]=cs[e-a];
printf("\nFinal code word is:%s",t);
printf("\nTest error detection 0(yes) 1(no)?:");
scanf("%d",&e);
if(e==0)
{
printf("Enter position where is to inserted");
scanf("%d",&e);
t[e]=(t[e]=='0')?'1':'0';
printf("erroneous data :%s\n",t);
}
crc();
for(e=0;(e<N-1)&&(cs[e]!='1');e++)
if(e<N-1)
printf("Error detected");
else printf("no error detected");
}

RESULT:
Thus the error detection using CRC-CCITT [16 BIT] technique is implemented and the output is
verified successfully.

28
EX.NO:10
DATE

IMPLEMENTATION OF ENCRYPTION AND DECRYPTION

AIM:
To implement encryption and decryption using C program.

EQUIPMENTS REQUIRED:

1.PC with Linux operating system

PROCEDURE:
1] Open code blocks and type the program for encryption and decryption.
2] Save the program using extension .c
3] Run the program using build and run.
4] Prime number is given as input. If it is not a prime number then wrong input is displayed.
5] Then a message is entered.
6] The encrypted form of the message is displayed.
7] The decrypted form is also displayed as final output.
8] Thus the output is obtained.

PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
longintp,q,n,t,flag,e[100],d[100],temp[100],j,m[100],en[100],i;
char msg[100];
int prime(longint);
void ce();
long int cd(longint);
void encrypt();
void decrypt();
void main()
{
printf("\nENTERFIRSTPRIMENUMBER\n");
scanf("%d",&p);
flag=prime(p);
if(flag=0)
{
printf("\nWRONGINPUT\n");
exit(1);
}
printf("\nENTERANOTHERPRIMENUMBER\n");
scanf("%d",&q);
flag=prime(q);
if(flag==0||p==q)
{
printf("\nWRONGINPUT\n");
29
exit(1);
}
printf("\nENTERMESSAGE\n");
fflush(stdin);
scanf("%s",msg);
for(i=0;msg[i]!=NULL;i++)
m[i]=msg[i];
n=p*q;
t=(p-1)*(q-1);
ce();
212215106298
printf("\nPOSSIBLEVALUESOFeANDdARE\n");
for(i=0;i<j-1;i++)
printf("\n%ld\t%ld",e[i],d[i]);
encrypt();
decrypt();
}
int prime(long int pr)
{
int i;
j=sqrt(pr);
for(i=2;i<=j;i++)
{
if(pr%i==0)return0;
}
return1;
}
Void ce()
{
int k;
k=0;
for(i=2;i<t;i++)
{
if(t%i==0)
continue;
flag=prime(i);
if(flag==1&&i!=p&&i!=q)
{
e[k]=i;
flag=cd(e[k]);
if(flag>0)
{
d[k]=flag;
k++;
}
if(k==99)break;
}
}
}
long int cd(long int x)
30
{
long int k=1;
while(1)
{
k=k+t;
if(k%x==0)return(k/x);
}
}
void encrypt()
{
longintpt,ct,key=e[0],k,len;
i=0;
len=strlen(msg);
while(i!=len)
{
pt=m[i];pt=pt-96;
k=1;
for(j=0;j<key;j++)
{
k=k*pt;
k=k%n;
}
temp[i]=k;
ct=k+96;
en[i]=ct;
212215106298
i++;
}
en[i]=-1;
printf("\nTHEENCRYPTEDMESSAGEIS\n");
for(i=0;en[i]!=-1;i++)
printf("%c",en[i]);
}
void decrypt()
{
long int pt,ct,key=d[0],k;
i=0;
while(en[i]!=-1)
{
ct=temp[i];
k=1;
for(j=0;j<key;j++)
{
k=k*ct;
k=k%n;
}
pt=k+96;m[i]=pt;
i++;
}
m[i]=-1;
31
printf("\nTHEDECRYPTEDMESSAGEIS\n");
for(i=0;m[i]!=-1;i++)
printf("%c",m[i]);
}

RESULT:
Thus the encryption and decryption is implemented and the output is obtained and verified
successfully.

32
EX.NO :11
DATE

STUDY OF NETWORK SIMULATOR AND CONGESTION CONTROL USING NS

AIM:
To study different types of network simulators and Congestion control using NS.

NETWORK SIMULATOR:
A network simulator is software that predicts the behavior of a computer network .Since communication
Networks have become too complex for traditional analytical methods to provide an accurate understanding of
system behavior network simulator are used. In simulators, the computer network is typically modeled with
devices, links, applications etc. and the performance is analyzed. Simulators typically come with support for the
most popular technologies and networks in use today.

SIMULATIONS:
Most of the commercial simulators are GUI driven, while some network simulators are CLI driven. The
network model / configuration describes the state of the network (nodes, routers, switches, and links) and the
events (data transmissions, packet error etc.). An important output of simulations are the trace files. Trace files
log every packet, every event that occurred in the simulation and are used for analysis. Network simulators can
also provide other tools to facilitate visual analysis of trends and potential trouble spots. Most network simulators
use discrete event simulation, in which a list of pending "events" is stored, and those events are processed in
order, with some events triggering future events—such as the event of the arrival of a packet at one node triggering
the event of the arrival of that packet at a downstream node. Simulation of networks is a very complex task. For
example, if congestion is high, then estimation of the average occupancy is challenging because of high variance.
To estimate the likelihood of a buffer overflow in a network, the time required for an accurate answer can be
extremely large. Specialized techniques such as "control variates" and "importance sampling"have been
developed to speed simulation.

NETWORK EMULATION:
A network emulator allows users to introduce real devices and applications into a test network (simulated)
that alters packet flow in such a way as to mimic the behavior of a live network. Live traffic can pass through the
simulator and be affected by objects within the simulation.The typical methodology is that real packets from a
live application reach the emulation server (where the virtual network is simulated. The real packet gets modulated
into a simulation packet.The Simulation packet gets demodulated into real packet after experiencing effects of
loss, errors, delay, jitter etc., thereby transferring these network effects into the real packet. Thus it is as-if the
real packet flowed through the real networks but in reality it flowed through the
simulated network. Emulation is widely used in the design stage for validating communication networks prior to
deployment.

EXAMPLES OF NETWORK SIMULATORS:


There are both free/open-source and proprietary network simulators available. Examples of
notable network simulators / emulators include:
ns (open source)
OPNET (proprietary software)
NetSim (proprietary software)

USES OF NETWORK SIMULATORS:


Network simulators provide a cost effective method for
a) Network design validation for enterprises / data centers /sensor networks etc.
33
b) Impact assessment for modification / additions to existing network
c) Network protocol R & D
d) Defense applications and Network-centric warfare

There are a wide variety of network simulators, ranging from the very simple to the very
complex. Minimally, a network simulator must enable a user to
1. Model the network topology specifying the nodes on the network and the links
between those nodes
2. Model the application flow (traffic) between the nodes
3. Providing network performance metrics as output
4. Visualization of the packet flow
5. Logging of packet / events for drill down analyses / debugging.

THE TCP CONGESTION CONTROL:


The TCP congestion control consists of four intertwined algorithms: slow start, congestion
avoidance, fast retransmit and fast recovery.

SLOW START AND CONGESTION AVOIDANCE:


The slow start and congestion avoidance algorithms are used by a TCP sender to control the amount of
outstanding data being injected into the network. To implement this, two state variables are added to TCP per-
connection state. The congestion window (cwnd) is a sender-side limit on the amount of data the sender can
transmit into the network before receiving an acknowledgement (ACK), while the receiver's advertised window
(rwnd) is a receiver-side limit on the amount of outstanding data. The minimum of cwnd and rwnd governs the
data transmission.
Another variable, the slow start threshold (sstresh), is used to determine wheteher slow start or congestion
avoidance is used. When a TCP connection starts, it tries to probe the network capacity by using a maximum
congestion window of one segment. The slow start algorithm is used when cwnd ssthresh, else congestion
avoidance is used.
During slow start, a TCP increments cwnd by one segment for every ACK received.The low start ends
when cwnd exceeds ssthresh, and congestion avoidance takes over. During congestion avoidance, cwnd is
increased linearly, i.e. by 1 segment per round-trip time (RTT).When a TCP sender detects segment loss using
retransmission timer, the value ofssthresh is halved, and the cwnd is reset to 1 segment. The lost segment is
retransmitted.

FAST RETRANSMIT/FAST RECOVERY:


A TCP-receiver immediately sends a duplicate ACK when an out-of-order segment arrives. In addition, a
TCP receiver should also send an immediate ACK when an incoming segment fills in all or part of a gap in the
sequence space.
The TCP-sender uses fast retransmit to detect and repair, loss based on incoming duplicate ACKs. After
receiving 3 duplicate ACKs, TCP retransmits the missing segment without waiting for retransmission timer to
expire.
After the fast retransmit, the fast recovery algorithm governs the transmission of new data until a non-
duplicate ACK is received. After the receipt of third duplicate ACK, the value of ssthresh is halved and cwnd is
set to ssthresh + 3 segments.

For each duplicate ACK received, the cwnd is inflated by 1 segment. A segment is transmitted if
allowed by the new value of congestion window and receivers advertised window. When the next ACK arrives
that acknowledges new data, cwnd is set to ssthresh. This is termed as “deflating" the window.

34
RESULT:
Thus different types of network simulators and Congestion control is studied using NS.

35

You might also like