You are on page 1of 50

EASWARI ENGINEERING COLLEGE

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

CS 6411 NETWORKS LAB MANUAL

II Year CSE A & B


2014 -2015 (EVEN SEM)
(REGULATION 2013)

CS6411

NETWORKS LABORATORY

LTPC

0032

OBJECTIVES:
The student should be made to:
Learn socket programming.
Be familiar with simulation tools.
Have hands on experience on various networking protocols.
LIST OF EXPERIMENTS:
1. Implementation of Stop and Wait Protocol and Sliding Window Protocol.
2. Study of Socket Programming and Client Server model
3. Write a code simulating ARP /RARP protocols.
4. Write a code simulating PING and TRACEROUTE commands
5. Create a socket for HTTP for web page upload and download.
6. Write a program to implement RPC (Remote Procedure Call)
7. Implementation of Subnetting .
8. Applications using TCP Sockets like
a. Echo client and echo server
b. Chat
c. File Transfer
9. Applications using TCP and UDP Sockets like
d. DNS
e. SNMP
f. File Transfer
10. Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS
11. Perform a case study about the different routing algorithms to select the network path with
its optimum and economical during data transfer.
i. Link State routing
ii. Flooding
iii. Distance vector
TOTAL: 45 PERIODS
REFERENCE:
spoken-tutorial.org.

OUTCOMES:
At the end of the course, the student should be able to
Use simulation tools
Implement the various protocols.
Analyse the performance of the protocols in different layers.
Analyze various routing algorithms

LIST OF EQUIPMENT FOR A BATCH OF 30 STUDENTS


SOFTWARE:
C / C++ / Java / Equivalent Compiler 30
Network simulator like NS2/Glomosim/OPNET/ Equivalent
HARDWARE:
Standalone desktops 30 Nos

LIST OF EXPERIMENTS
S.no

Name of the Experiment

Introduction to Basic Networking Commands

Introduction to Socket Programming

Applications using TCP Sockets

Echo client and Echo server

Chat

File Transfer

Applications using TCP and UDP sockets like

DNS

SNMP

File Transfer

5a

Simulation of ARP Protocols

5b

Simulation of RARP Protocols

Implementation of RPC

7a

Implementation of Sliding Window Protocol

7b

Implementation of Stop and Wait Protocol

Socket Programming for Web page Upload and Download using HTTP

Simulation of PING and TRACEROUTE commands

10

Implementation of Subnetting

11a

Study of Network Simulator

11b

Simulation of Congestion Control Algorithms using NS

12

Performance comparison of different Routing Algorithms

Link State Routing

Flooding

Distance Vector
Content beyond syllabus

13

Implementation of Bit stuffing.

14

Simulation of Routing Protocol BGP

EX NO 1

BASIC NETWORKING COMMANDS

Aim:
To study the basic networking commands
Ping
ping sends an ICMP ECHO_REQUEST packet to the specified host. If the host responds,
we get an ICMP packet back. We can ping an IP address to see if a machine is alive. If there is
no response, we know something is wrong.
ping, a very useful day-to-day command. It provides a very quick way to see if a machine
is up and connected to the network. The basic syntax is:
Example:
Z:\> ping cse
pathping
Provides information about network latency and network loss at intermediate hops
between a source and destination. pathping sends multiple Echo Request messages to each router
between a source and destination over a period of time and then computes results based on the
packets returned from each router.
Example:
Z:\>pathping www.yahoo.com
Trace complete
nslookup
The nslookup command can be used in Windows and Unix to find various details relating
to the Domain Name System (DNS) like IP addresses of a particular computer.nslookup comes
with a number of subcommands to help us to get more information from the specific dns servers.
Example:
server NAME (where NAME is the name or ip address of the dns server we wish to
query). It is not always possible to query a specific dns server as often dns queries are
blocked to prevent denial of service attacks.
Using subcommands:
Z:\>nslookup 204.228.150.3
Server: eec.ac.in
Address: 10.1.1.2
Name:

www.computerhope.com

Address: 204.228.150.3
The first two lines are information about the server delivering the answer to the nslookup
requested by the user. The next two lines tell the user the name and IP address of the machine
being looked up.
arp
When we need an Ethernet (MAC) address we can use arp (address resolution protocol).In
other words it shows the physical address of a host.
6

Example:
Z:\>arp -a
Interface: 10.2.1.205 --- 0x10003
Internet Address

Physical Address

Type

10.1.1.2

00-04-23-dc-dd-d4

dynamic

10.1.1.4

00-15-17-53-53-59

dynamic

10.1.1.5

00-02-b3-50-69-18

dynamic

10.2.1.201

00-16-76-87-01-0d

dynamic

netstat
The netstat command is used to display the TCP/IP network protocol statistics and
information (Shows network status).The netstat command symbolically displays the contents of
various network-related data structures for active connections.
The default display for active sockets shows the following items:
Local and remote addresses
Send and receive queue sizes (in bytes)
Protocol
Internal state of the protocol
Example:
Z:\>netstat
Active Connections
Proto Local Address

Foreign Address

State

TCP

EEC0205:1045

proxy.eec.ac.in:3128

ESTABLISHED

TCP

EEC0205:1068

eec.ac.in:microsoft-ds

ESTABLISHED

TCP

EEC0205:1074

proxy.eec.ac.in:3128

CLOSE_WAIT

TCP

EEC0205:1525

eec.ac.in:microsoft-ds

TIME_WAIT

TCP

EEC0205:1047

localhost:1048

ESTABLISHED

ipconfig
ipconfig (internet protocol configuration) is a DOS utility which can be used from MSDOS and a MS-DOS shell to display the network settings currently assigned and given by a

network. This command can be utilized to verify a network connection as well as to verify your
network settings.

Example:
Z:\>ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix : eec.ac.in
IP Address. . . . . . . . . . . . : 10.2.1.205
Subnet Mask . . . . . . . . . . . : 255.0.0.0
Default Gateway . . . . . . . . . : 10.1.1.4
hostname
Tells the user the host name of the computer they are logged into. Note: may be called host.
Example:
Z:\>hostname
EEC0205
dig(Try using Linux)
The "domain information groper" tool. More advanced then host... If you give a
hostname as an argument to output information about that host, including it's IP address,
hostname and various other information.To look up information about www.yahoo.com:
Example:
[vijay@linux ~]$ dig www.yahoo.com

tracert
traceroute will show the route of a packet. It attempts to list the series of hosts through
which your packets travel on their way to a given destination.
Example:
Z:\>tracert
Usage: tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name
Options:
-d

Do not resolve addresses to hostnames.

-h maximum_hops Maximum number of hops to search for target.


8

-j host-list

Loose source route along host-list.

Z:\>tracert www.yahoo.com
Tracing route to www-real.wa1.b.yahoo.com [209.131.36.158]
over a maximum of 30 hops:
1

<1 ms

<1 ms

<1 ms rmkec.rmk.ac.in [10.1.1.14]

<1 ms

<1 ms

<1 ms 121.240.153.1.static-chennai.vsnl.net.in [121.240.153.1]

6 ms

7 ms

4 ms 121.240.156.78.static-chennai.vsnl.net.in [121.240.156.78]

54 ms

18 ms

26 ms 202.54.65.86

5 290 ms 274 ms 249 ms 59.163.16.130.static.vsnl.net.in [59.163.16.130]


6 295 ms 233 ms 269 ms if-11-0-2.mcore3.PDI-PaloAlto.as6453.net [64.86.84.129]
7 298 ms 234 ms 262 ms ix-11-0-1.mcore3.PDI-PaloAlto.as6453.net [64.86.84.146]
8 322 ms 259 ms 250 ms ae0-p150.msr2.sp1.yahoo.com [216.115.107.73]
9 231 ms 238 ms 265 ms te-9-1.bas-a2.sp1.yahoo.com [209.131.32.23]
10 248 ms 243 ms 238 ms f1.www.vip.sp1.yahoo.com [209.131.36.158]
Trace complete.
finger
Displays information about a user on a specified system running the Finger service. Output
varies based on the remote system.
FINGER [-l] [user]@host [...]
-l
Displays information in long list format.
user Specifies the user you want information about. Omit the user
parameter to display information about all users on the
specifed host.
@host Specifies the server on the remote system whose users you
want information about.
df
Display filesystem information
Most common use: df -h
Great way to keep tabs on how much hard disk space you have on each mounted file system.
du
Display usage
Most common use, under a specific directory: du -a
9

Easily and quickly identify the size of files/programs in certain directories. A word of caution is
that you should not run this command from the / directory. It will actually display size for every
file on the entire Linux harddisk.
find
Find locations of files/directories quickly across entire filesystem
Most common use: find / -name appname -type d -xdev
ps
Lists all existing processes on the server
Most common uses: ps and also ps -A |more
top
Displays many system statistics and details regarding active processes
Most common use: top
traceroute
Traces the existing network routing for a remote or local server
Most common use: traceroute hostname
(replace hostname with the name of your server such as reallylinux.com)
w
An extension of the who command that displays details of all users currently on the
server
Most common uses: w
who
Tool used to monitor who is on the system and many other server related
characteristics
Most common uses: who and also who -q and also who -b
The plain command just lists the names of users currently on the server. Using the -q option
allows you to quickly view just the total number of users on the system. Using the -b option
reminds you how long it has been since you rebooted that stable Linux server! One of my
servers had a -b of almost three years! Yes, that's really Linux!
Result:
Thus the basic Networking Commands are studied.

10

EX NO 2

INTRODUCTION TO SOCKET PROGRAMMING

Aim:
To study about the basics of Socket in Network Programming
Network Programming
Network programming involves writing programs that communicate with other programs
across a computer N/W. One program is normally called the client, and the other the server.
Common examples in the TCP/IP are web clients (browsers) & Web Servers, FTP clients & server
and Telnet clients & servers.
To facilitate communication between unrelated processes, and to standardize network
programming, an API is needed. There are two such APIs:
1. Sockets, sometimes called Berkeley Sockets
2. XTI (X/open transport interface)
Socket
In TCP/IP, an addressable point that consists of an IP address and a TCP or UDP port
member that provides application with access to TCP/IP protocol is called Socket.
A socket is an abstraction that represents an endpoint of communication. The operations
that can be performed on a socket include control operations (such as associating a port number
with the socket, initiating or accepting a connection on the socket, or destroying the socket), data
transfer operations (such as writing data through the socket to some other application, or reading
data from some other application through the socket) and status operations (such as finding the IP
address associated with the socket). The complete set of operations that can be performed on a
socket constitutes the Sockets API (Application Programming Interface).
Structures
Structures are used in socket programming to hold information about the address. The
generic socket address structure is defined below:
struct sockaddr
{
unsigned short sa_family;
/* address family */
char sa_data[14];
/* 14 bytes of protocol address*/
};
IPv4 Socket Address Structure
This structure is also called as Internet socket address structure. It is defined by
including the <netinet/in.h> header.
struct in_addr {
in_addr_t
s_addr;
/* 32-bit IPv4 address, network byte ordered */
};
struct sockaddr_in{
unit_t sin_len;
/* length of structure (16 byte) */
sa_family_t sin_family; /*AF_INET*/
in_port_t
sin_port;
/* 16-bit TCP or UDP port number */
/* network byte ordered */
struct in_addr sin_addr;
/*32-bit Ipv4 address, network byte ordered */
char
sin_zero[8]; /* unused initialize to all zeroes */
};
11

Important functions
1.socket()
This function is called by both TCP server and client process to create an empty socket.
#include <sys/socket.h>
int socket (int family, int type, int protocol);
family: specifies the protocol family and is one of the constants below:
Family
description
AF_INET

IPv4 protocols

AF_INET6

IPv6 protocols

AF_LOCAL

Unix domain protocols

AF_ROUTE

Routing sockets

AF_KEY

Key sockets

type: indicates communications semantics


SOCK_STREAM - stream socket
SOCK_DGRAM - datagram socket
SOCK_RAW - raw socket
protocol: set to 0 except for raw sockets.
Returns on success: socket descriptor (a small nonnegative integer), on error: -1
2. bind()
The bind function assigns a local protocol address to a socket. The protocol address is the
combination of either a 32-bit IPV4 address or a 128-bit IPV6 address, along with a 16-bit TCP or
UDP port number.
#include <sys/socket.h>
int bind(int sockfd, const struct sockaddr *myaddr, socklen_t addrlen);
sockfd: a socket descriptor returned by the socket function.
*myaddr: a pointer to a protocol-specific address.
addrlen: the size of the socket address structure.
Returns on success: 0, on error: -1
3. connect()
The connect function is used by a TCP client to establish a connection with a TCP server.
#include <sys/socket.h>
int connect(int sockfd, const struct sockaddr *servaddr, socklen_t addrlen);
sockfd: a socket descriptor returned by the socket function
*servaddr: a pointer to a socket address structure
addrlen: the size of the socket address structure
Returns on success: 0, on error: -1
12

4. listen()
The listen function is called only by a TCP server to converts an unconnected socket into a
passive socket, indicating that kernel should accept incoming connection requests directed to its
socket.
#include<sys/socket.h>
int listen (int sockfd, int backlog);
sockfd: a socket descriptor returned by the socket function.
backlog: maximum number of connections that the kernel should queue for this socket.
Returns on success: 0, on error: -1
5. accept()
The accept function is called by the TCP server to return the next completed connection from the
front of the completed connection queue.
#include<sys/socket.h>
int accept (int sockfd, struct sockaddr *cliaddr, socklen_t *addrlen);
sockfd: This is the same socket descriptor as in listen call.
*cliaddr: used to return the protocol address of the connected peer process
*addrlen: length of the address.
Returns on success: a new (connected)socket descriptor, on error:-1
6. close()
The close function is used to close a socket and terminate a TCP connection.
#include <unistd.h>
int close (int sockfd);
sockfd: This socket descriptor is no longer useable.
Returns on success: 0, on error: -1
7. read()
The read function is used to receive data from the specified socket.
#include <unistd.h>
ssize_t read(int sockfd, const void * buf, size_t nbytes);
sockfd: a socket descriptor returned by the socket function.
buf: buffer to store the data.
nbytes: size of the buffer
Returns: number of bytes read if OK,0 on EOF, -1 on error
8. write()
The write function is used to send the data through the specified socket.
#include <unistd.h>
ssize_t write(int sockfd, const void * buf, size_t nbytes);
sockfd: a socket descriptor returned by the socket function.
buf: buffer to store the data.
nbytes: size of the buffer
Returns: number of bytes written if OK,0 on EOF, -1 on error
13

9. sendto()
This function is similar to the write function, but additional arguments are required.
#include<sys/socket.h>
ssize_t sendto(int sockfd, const void *buff, size_t nbyte, int flag,
const struct sockaddr *to, socklen_t addrlen);
sockfd socket descriptor
*buff pointer to buffer to write from.
nbytes number of bytes to write.
to socket address structure containing the protocol address of where the data is to be sent.
addrlen size of the socket address structure
Returns: number of bytes read or written if OK,-1 on error
10. recvfrom()
This function is similar to the read function, but additional arguments are required.
#include<sys/socket.h>
ssize_t recvfrom(int sockfd, void *buff, size_t nbyte, int flag,
struct sockaddr *from, socklen_t *addrlen);
sockfd socket descriptor
*buff pointer to buffer to read.
nbytes number of bytes to read.
addrlen size of the socket address structure
from - socket address structure of who sent the datagram.
Returns: number of bytes read or written if OK,-1 on error

14

Socket functions for connection-oriented communication


TCP Server
socket()

bind()

listen()

accept()

TCP Client
socket()
Connection
establishment

blocks until connection from


client

conect()
data ( request)
write()

read()

read()

process request
data ( reply)
write()

close()

EOF notification
read()

close()

15

Socket functions for connection-less communication


UDP Server
socket()

bind()
UDP Client
socket()

sendto()

recvfrom()

Data (request)

Blocks until datagram


received from a client
Process request

Data (reply)
recvfrom()

sendto()

close()

Program to create a socket


/* Ex-1
Program To Create a Socket */
#include <stdio.h>
/* NEEDED HEADER FILES */
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
int main()
{
int sockfd1,sockfd2;
/* sokcet file descriptors */
sockfd1=socket(AF_INET,SOCK_STREAM,0); /* socket system call */
sockfd2=socket(PF_INET,SOCK_DGRAM,0);
if(sockfd1==-1)
/* error checking */
{
printf("Socket1 not Created\n");
}
else{
16

printf("Socket1 Created and \t Socket1 File Descriptor value is %d \n",sockfd1);


if(sockfd2==-1)
{
printf("socket2 creation error");
}
else
{
printf("Socket2 created and \t socket2 descriptor value is %d\n",sockfd2);
}
}}
Program to Bind a socket
/* Ex-2 Program to Bind a Socket */
#include<stdio.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#define PORTNO 2000
/* Type definition of a Port number */
int main()
{
int sockfd,i=PORTNO;
struct sockaddr_in myaddr;
/* Builtin structure for internet address */
if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1)
{printf("Socket Creation Error\n");}
myaddr.sin_family=AF_INET;
/* Structure variable definition */
myaddr.sin_port=htons(PORTNO);
myaddr.sin_addr.s_addr=INADDR_ANY;
memset(&(myaddr.sin_zero),'\0',8); /* fills with constant byte to remaining space */
/* socket Binding process and error checking */
if(bind(sockfd,(struct sockaddr *)&myaddr,sizeof(struct sockaddr))!=-1)
{
printf(" Socket is Binded at port %d\n",i);
}
else
{
printf("Binding Error\n");
}
}
Program to implement listen() system call

/* Ex-3 Program to implement LISTEN system call */


#include <stdio.h>
/* These are the usual header files */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
17

#define PORT 3550 /*Assigning Port number */


#define BACKLOG 12 /* Number of allowed connections */
main()
{
int fd;

/* file descriptors */

struct sockaddr_in server;


struct sockaddr_in client;

/* server's address information */


/* client's address information */

int sin_size;
int x;
if ((fd=socket(AF_INET, SOCK_STREAM, 0)) == -1 ){ /* calls socket() */
printf("socket() error\n");
exit(-1);
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
/* Remember htons() from "Conversions" section? =) */
server.sin_addr.s_addr = INADDR_ANY; /* INADDR_ANY puts your IP address
automatically */
bzero(&(server.sin_zero),8);
/* zero the rest of the structure */
if(bind(fd,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1) /* calls bind() */
{
printf("bind() error\n");
exit(-1);
}
x=listen(fd,BACKLOG) ;
/* calls listen() */
if(x==-1)
{
printf("listen() error\n");
exit(-1);
}
else
{
printf(Server is in listening mode \n );
}
close(fd);
/* close fd */
}

Program for accept() system call


/* Ex-3 Program to implement ACCEPT system calls */
#include <stdio.h>
/* These are the usual header files */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
18

#define PORT 3550 /* Assigning Port numbers */


#define BACKLOG 2 /* Number of allowed connections */
main()
{
int fd, fd2;

/* file descriptors */

struct sockaddr_in server;


struct sockaddr_in client;

/* server's address information */


/* client's address information */

int sin_size;
if ((fd=socket(AF_INET, SOCK_STREAM, 0)) == -1 ) /* calls socket() */
{
printf("socket() error\n");
exit(-1);
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
/* Remember htons() from "Conversions" section */
server.sin_addr.s_addr = INADDR_ANY; /* INADDR_ANY puts your IP address
automatically */
bzero(&(server.sin_zero),8);
/* zero the rest of the structure */
if(bind(fd,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1){ /* calls bind() */
printf("bind() error\n");
exit(-1);
}
if(listen(fd,BACKLOG) == -1)
/* calls listen() */
{
printf("listen() error\n");
exit(-1);
}
printf("server is in accept mode \n ");
while(1)
{
sin_size=sizeof(struct sockaddr_in);
if ((fd2 = accept(fd,(struct sockaddr *)&client,&sin_size))==-1){ /* calls accept() */
printf("accept() error\n");
exit(-1);
}
else
printf(" Server is in accept mode ");
printf("You got a connection from %s\n",inet_ntoa(client.sin_addr) ); /* prints client's IP */
close(fd2); /* close fd2 */
}
}
Result:
Thus the basics of socket with example peograms are studied.
19

EX NO 3a

TCP echo client-server

Aim
To write a program in C to implement TCP Echo Client Server .
Algorithm
Server
1. A TCP socket is created.
2. An Internet socket address structure is filled in with the wildcard address
(INADDR_ANY) and the servers well-known port (PORT).
3. The socket is converted into a listening socket by calling the listen function.
4. The server blocks in the call to accept, waiting for the client connection to complete.
5. When the connection is established, the server reads the line from the client using
readn and echoes it back to the client using writen.
6. Finally, the server closes the connected socket.
Client:
1. A TCP socket is created.
2. An Internet socket address structure is filled in with the servers IP address and the
same port number.
3. The connect function establishes the connection with the server.
4. The client reads a line of text from the standard input using fgets, writes it to the server
using writen, reads back the servers echo of the line using readline and outputs the
echoed line to the standard output using fputs.
OUTPUT:
//SERVER
$ cc iterserv.c
$ ./a.out
Message Received and Echoed : Good
//CLIENT
$ cc itercli.c
$ ./a.out 127.0.0.1
ENTER THE STRING TO ECHO :Good
Good
$
Result:
Thus the implementation of TCP Echo Client Server using C Program is executed and the
output is verified successfully.

20

Ex No : 3b

CHAT APPLICATION USING TCP SOCKETS

Aim
To perform the full duplex chat by sending and receiving the message from the client to server
and vice versa using TCP sockets.
Algorithm
Server
1. A TCP socket is created.
2. An Internet socket address structure is filled in with the wildcard address
(INADDR_ANY) and the servers well-known port (PORT).
3. The socket is converted into a listening socket by calling the listen function.
4. The server blocks in the call to accept, waiting for the client connection to complete.
5. When the connection is established, the server reads the line from the client using
connected socket and display the message in the standard output using fputs.
6. Then again the server reads a line of text from the standard input and writes it back to
the client through the connected socket.
7. The server went through the steps (5) and (6) until it receives 'bye' either from the
standard input or client.
8. Finally, the server closes the connected socket.
Client:
1. A TCP socket is created.
2. An Internet socket address structure is filled in with the servers IP address and the
same port number.
3. The connect function establishes the connection with the server.
4. When the connection is established, the client reads the line from the standard input
using fgets and send the message to the server through the socket.
5. Then again the client reads a line of text from the server through the connected socket
and writes it back to the standard output using fputs.
6. The client went through the steps (4) and (5) until it receives 'bye' either from the
standard input or server.
7. Finally, the client closes the connected socket.
OUTPUT
//Server
$ cd ..
$ cd TCPCHAT
$ cc tcpchatser.c
$ ./a.out
Server Socket Created Successfully.
Server Socket Binded.
Server Socket Listened...
From client :Hello
Server :Hi ..How are you?
From client :Fine. How Are You?
Server :Fine
From client :Bye
Server :bye
21

//Client
$ cc tcpchatcli.c
$ ./a.out 127.0.0.1
Client Socket Created Successfully.
Client Socket with Server Successfully.
Client. :Hello
From Server :Hi ..How are you?
Client. :Fine. How Are You?
From Server :Fine
Client. :Bye
From Server :bye
$
Result:
Thus the full duplex chat by sending and receiving the message from the client to server
and vice versa using TCP socket is executed and the output is verified successfully.

22

EX NO 3c

FILE TRANSFER

Aim:
To write a program for File Transfer Application using TCP socket.
Algorithm:
Server:
Step 1: Start
Step 2: Create a socket with address family AF_INET, type SOCK_STERAM and default
protocol.
Step 3: Initialize the socket and set its attributes.
Step 4: Bind the server to socket using bind function.
Step 5: wait for the client request on request establish a connection using accept() function.
Step 6: Read the source and destination files names from the client.
Step 7: Open the source and destination files.
Step 8: Read one line of source file and send it to client.
Step 9: Receive the line back from the client.
Step 10: Repeat steps 8&9 until the end of the source file.
Step 11: close the source and destination files.
Step 12: close the connection and goto step5.
Client:
Step 1: start
Step 2: Create a socket with address family AEINET type SOCK_STREAM and default protocol.
Step 3: Initialize the socket and set its attribute set required port no.
Step 4: Connect to server using connect () function to initiate the request.
Step 5: send the source and destination file names to server.
Step 6: Recive the string from the server and print it at the console.
Step 7: send the string to the server.
Step 8: Repeat step6&7 until the server terminates and connection.
Step 9: stop.
SAMPLE INPUT OUTPUT:
Server Side:
[cseb17@localhost cseb 17]$ cc trj3server.c
[cseb17@localhost cseb 17]$.a/out
Client requesting
Received:new.c
Stored in : thanga.c
Client side:
[cseb17@localhost cseb 17]$cc trj3client.c
[cseb17@localhost cseb 17]$./a.out 127.0.0.1 6142 new.c.thanga.c
connected...sending filename new.c
hai how are you?
Result:
Thus the C program for File Transfer Application using TCP socket is executed and the
output is verified successfully

23

EX NO 4a

SIMULATION OF DOMAIN NAME SYSTEM

Aim
To write a program in C to simulate the Domain Name System.
Algorithm
Server
1. A TCP socket is created.
2. An Internet socket address structure is filled in with the wildcard address
(INADDR_ANY) and the servers well-known port (PORT).
3. The socket is converted into a listening socket by calling the listen function.
4. The server blocks in the call to accept, waiting for the client connection to complete.
5. When the connection is established, the server reads the domain name from the client
using readn.
6. It then finds out the corresponding address using gethostbyname() and sends it back to the
client using writen.
24

7. Finally, the server closes the connected socket.


Client:
1. A TCP socket is created.
2. An Internet socket address structure is filled in with the servers IP address and the same
port number.
3. The connect function establishes the connection with the server.
4. The client reads the domain name from the standard input using fgets, writes it to the
server using writen.
5. It then reads back the server reply (IP address) using readline and outputs the same to the
standard output using fputs.
OUTPUT:
SERVER
$ cc DNSServer.c
$ ./a.out
SERVER...
Server Started
www.google.com
HOST : www.google.com --> IP ADDRESS --> 74.125.71.105
www.eec.ac.in
HOST : www.eec.ac.in --> IP ADDRESS --> 173.193.3.233
CLIENT
$ cc DNSClient.c
$ ./a.out 127.0.0.1
Enter the domain namewww.google.com
The host address is 74.125.71.105
$ ./a.out 127.0.0.1
Enter the domain namewww.eec.ac.in
The host address is 173.193.3.233
$
Result:
To write a program in C to simulate the Domain Name System is executed and the output is
verified successfully.
EX NO 4b
SIMPLE NETWORK MANAGEMENT PROTOCOL (SNMP)
Aim
To write a program in C to simulate the Simple Network Management Protocol.
Procedure:
1. Create a function called init_snmp() gets the ball olling.
2. snmp_sess_init() accepts a session structure address, this function will populate the
bulk of the session structure with default values. Once the session structure is primed we
can modify it to meet our needs, such as defining the SNMP version, community name,
and the hostname of agent referred to as the peername.
3. When the session structure is ready for use, we can open the session
with snmp_open() which will return a new session structure as a handle.
25

4. The add_mibdir() and read_mib() functions demonstrated how to add a directory to the
internal MIB path and then read a MIB into the MIB tree.
5. Now that the session is open and the MIBs we'll use are loaded into the tree we can
create and populate the PDU(s) we'll be sending.
6. snmp_pdu_create() will setup the base PDU information based on the supplied type of
PDU (specified in macro form) and return the populated PDU structure.
7.
Now
that
we
have
the
PDU
we
can
use
the read_objid() and snmp_add_null_var() functions to first read the OID from the MIB
and then add that OID as a variable to the variable list used by the PDU.
8. We can repeat this process several times to continue packing our PDU full of OIDs.
9. Once our session is open and our PDU is ready with all the OIDs we want crammed
into the variable list we can actually send the request and await the response. This action is
done in a single step using thesnmp_synch_response() function.
10. The function is passed the open session handle, the PDU to send, and an empty PDU
structure to accept the response which includes the populated values for each OID in the
variable list.
11. At this point you can extract and manipulate the returned data either by utilizing built
in functions such as print_value() or by simply directly accessing the structures. Other
convince functions for value output can be found in the net-snmp/library/mib.h header.
12. Finally, to properly clean up, the PDU(s) should be freed and the sessions closed
using the snmp_free_pdu() and snmp_close() functions.

Result:
Thus the C program to simulate the Simple Network Management Protocol is execute
and the output is verified successfully

EX NO 4c

FILE TRANSFER USING UDP

Aim:
To write a program for File Transfer Application using UDP socket.
Algorithm:
Server:
Step 1: Start
Step 2: Create a socket with address family AF_INET, type SOCK_DGRAM and default
Protocol 0.
Step 3: Initialize the socket and set its attributes.
Step 4: Bind the server to socket using bind function.
Step 5: Find the length of Client address and store it in a parameter called len.
26

Step 6: Read the file from the client by recvfrom() function and the required parameters.
Step 7: Write the file by sendto() function by setting up the required parameters.
Step 8: Close the connection.
Client:
Step 1: start
Step 2: Create a socket with address family AF_INET type SOCK_DGRAM and default
protocol 0.
Step 3: Initialize the socket and set its attribute set required port no.
Step 4:Type the UDP message from client
Step 5: Write the UDP message framed from client through sendto() function.
Step 6: The recvfrom() function then read the message sent by the client by setting the parameters
required.
Step 7: Close the connection.

Result:
Thus the C program for File Transfer Application using UDP socket is executed and the
output is verified successfully

EX NO 5a

SIMULATION OF ARP

Aim:
To write a program for the simulation of Address Resolution Protocol(ARP).
Algorithm: ARP
1. Include necessary header files.
2. Initialize the arpreq structure initially to zero.
3. Get the IPAddress of the system as command line argument.
4. Check whether the given IPAddress is valid.
5. Copy the IPAddress from sockaddr_in structure to arpreq structure using memcopy()system
call.
27

6. Create a socket of type SOCK_DGRAM.


7. Calculate the MAC address for the given IPAddress using ioctl() system call.
8. Display the IPAddress and MAC address in the standard output.
Result:
Thus the C program for the simulation of Address Resolution Protocol(ARP) is executed
and the output is verified successfully

EX NO 5b

SIMULATION OF RARP

Aim:
To write a program to implement the Reverse Address Resolution Protocol(RARP).
Algorithm:
1. Start the program. Declare the variables using arrays
2. Calculate the Ethernet address and IP address using et[i]=i*3; ip[i]=rand()%50
3. Calculate the address resolution protocol value using arp=rand()%6 function
4. Display the Ethernet address of the system
5. If the system is connected to the server, then display the sender IP address, otherwise
display No response
6.Compile and execute the program. Stop the program

Result:
Thus the C program for the simulation of Reverse Address Resolution Protocol(RARP) is
executed and the output is verified successfully

EX NO 6

IMPLEMENTATION OF REMOTE PROCEDURE CALL

AIM:
To perform addition and subtraction of two numbers using remote procedure call.
THEORY:

28

RPCGEN is the RPC Protocol Compiler. This compiler creates the network interface
portion of a distributed application, effectively hiding from the programmer the details of writing
and debugging low-level network interface code.
rpcgen tool generates four C files for the specification file (simp.x). The output file
contains C source code for both output and data declarations.
File Name
Description
simp_clnt.c
Client side communication stub procedure
simp _svc.c
Server side communication stub procedure
Declaration of constants and types used in the code
simp.h
generated for both client and server.
XDR-eXternal Data Representation. Contains XDR
simp_xdr.c
procedure calls used in the client and server to marshal
29

arguments.
STEPS
1.
2.
3.
4.
5.
6.

Create the specification file (simp.x).


Create the server file.(simpservice.c)
Create the client file.(simpclient.c)
Generate header files and stub files.
Compile Server file and run the server.
Compile client and Run the client application by specify argument list and hostname of the
server.

SIMP.X
1. This defines the protocol definition for the application.
2. Define two remote procedures - Each must be called with a single parameter, a structure
that holds 2 integers.
3. The return value of each procedure is an int.
simpclient.c
1.
2.
3.
4.

Define the wrapper function that takes care of calling the RPC procedure.
Gather everything into a single data structure to send to the server.
Call the client stub created by rpcgen.
Create a CLIENT data structure that reference the RPC procedure SIMP_PROG, version
SIMP_VERSION running on the host specified by the first command line arg.
5. Get the 2 numbers that should be added, from the user.
6. Pass the numbers to the server for calculation and prints the output in the terminal.
Simpservice.c
1. This file contains the definition of the remote add and subtract procedure used by simple
RPC example
2. The return value of the procedure must be a pointer to integer.
3. Declare the variable result as static so we can return a pointer to it.
4. Define implementation of the method add_1_svc as add two arguments.
5. Define implementation of the method sub_1_svc as subtract second argument from first
argument.

OUTPUT
GENERATION OF STUBS AND HEADER FILE
$rpcgen -C -a simp.x
//Make sure that the following files are generated by rpcgen tool
30

$ ls
a.out
simpclient.c simp_server.c simp.x
Makefile.simp simp_clnt.c simpservice.c simp_xdr.c
simp_client.c simp.h
simp_svc.c
SERVER
$ cc simpservice.c simp_svc.c simp_xdr.c
$ ./a.out
Got request: adding 6, 3
Got request: subtracting 6, 3
CLIENT
$ cc simpclient.c simp_clnt.c simp_xdr.c
$ ./a.out 127.0.0.1 6 3
6+3=9
6-3=3
$
Result:
Thus the addition and subtraction of two numbers using remote procedure call is executed
and the output is verified successfully.

EX NO 7a

SIMUALTION OF SLIDING WINDOW PROTOCOL

Aim
To write a program in C to simulate the Sliding Window Protocol.
31

Algorithm
Server
1. A TCP socket is created.
2. An Internet socket address structure is filled in with the wildcard address
(INADDR_ANY) and the servers well-known port (PORT).
3. The socket is converted into a listening socket by calling the listen function.
4. The server blocks in the call to accept, waiting for the client connection to complete.
5. When the connection is established, the server reads the source file name (which is to
be transferred) from the client using readn.
6. Then the contents of the source file are transferred byte by byte (assuming the window
size is 1) to the client.
7. Finally, the server closes the connected socket.
Client:
1. A TCP socket is created.
2. An Internet socket address structure is filled in with the servers IP address and the
same port number.
3. The connect function establishes the connection with the server.
4. The client reads a source file name and the destination file name from the user, sends
the source file name to the server using writen.
5. It then receives the byte by byte content of the file from the server and displays it.

OUTPUT
//sample.txt
GOOD DAY
//SERVER
$ cc slidingser.c
$ ./a.out
SERVER SOCKET BINDED
SERVER SOCKET listened
SERVER Socket accepted connection with a Client
File requested: sample.txt
Sending:GReceived ACK...
Sending:OReceived ACK...
Sending:OReceived ACK...
Sending:DReceived ACK...
Sending: Received ACK...
Sending:DReceived ACK...
Sending:AReceived ACK...
Sending:YReceived ACK...
Sending:
Received ACK...
$
//CLIENT
$ cc slidingcli.c
$ ./a.out 127.0.0.1
32

CLIENT SOCKED CREATEDCLIENT SOCKET CONNECTED


Enter filenamesample.txt
Received:G, sending ACK...
Received:O, sending ACK...
Received:O, sending ACK...
Received:D, sending ACK...
Received: , sending ACK...
Received:D, sending ACK...
Received:A, sending ACK...
Received:Y, sending ACK...
Received:
, sending ACK...
Received and signal(OVER) terminating
$
Result:
Thus the C program to simulate the Sliding Window Protocol is executed and the output
is verified successfully.

EX NO 7b

SIMUALTION OF STOP & WAIT PROTOCOL

Aim
To write a program in C to simulate the Stop & Wait Protocol.
33

Algorithm
Sender:
1. Start the Program
2. Get the Packet from Network Layer
3. Create the frame structure
4. Send the frame created
5. If it is not a good frame call the physical layer to initiate the event else get the packet from
Network Layer and continue the Process.
6. Stop the Program
Receiver:
1. Physical Layer receives the frame and check for the structure.
2. If not a good frame call the physical layer else pass the frame to Network Layer.
3. Send Empty frame as an acknowledgement to sender and repeat the process.

Result:
Thus the C program to simulate the Stop & Wait Protocol is executed and the output is
verified successfully.

EX NO 8

SOCKET PROGRAMMING FOR WEBPAGE DOWNLOAD


USING HTTP
34

AIM
To write a c program in UNIX to download a file from a HTTP server.
ALGORITHM
Server
1. Include necessary header files to support functions for Socket definitions,Socket Types, Internet
addresses, I/Ofunctions, Unix system calls.
2. Declare variables for Socket ID,Portnumber,Socket addresses, buffer,etc.
3. Create Socket for server.
4. Bind socket with addresses.
5. Specify number of allowed connections.
6. Wait for connection.
7. Accept connection (If any).
8. Repeat the steps 8and 9 until the socket is closed.
9. Read the requested file to be transmitted from the client
10. The requested file is transferred by write to the new location.
Client
1. Include necessary header files to support functions for Socket definitions, Socket types, Internet
addresses, I/O functions, Unix system calls.
2. Declare variables for Socket ID, Portnumber, Socket addresses, Character buffer, etc.
3. Create Socket for Client.
4. Connect client socket to the server socket addresses.
5. Repeat the steps 8and 9 until the socket is closed.
6. Send file name to the Connected Socket
7. Retrieve information from Connected Socket and display it..

Result:
Thus the c program in UNIX to download a file from a HTTP server is executed and the output
is verified successfully.

EX NO 9

SIMULATION OF PING AND TRACEROUTE COMMANDS

Aim
35

To simulate PING & TRACEROUTE Commands


(1) PING (Packet Internet Groper Command)
If any system (host or router) want to communicate with the other system (host or route)
then it is necesary to check the communication is posible or not? For this, first of al we have to
check for destination system is reachable or not. Due to hardware failure or any other reason it is
posible the system may on network but not reachable. How can we detect that he destination
system is reachable or not?
PING command is useful for checking the reachabilty of the system.
Algorithm
Server side
1. Start program & initialize the structure with two structure variables cadd, sadd.
2. Create a socket using the socket creating command. Initialize the server address structure.
3. Bind the server information.
4. Accept the data from the client.
5. If the server is getting successfully, print the data sends. Close the socket.
6. End the program.
Client side
1. Create the socket in client side.
2. Initialize the client address structure.
3. Connect the client to the server by getting the IP address.
4. If successfully connected , ask the server to enter the data.
5. Send data to server if value is negative, display error & exit.
6. Close socket & end the program.
(2)TRACERT:
Algorithm
1
Start the program and declare the variables
2
Create the document file path.txt and give the all details
3
Open the document file path.txt and compare the input with the details in the path.txt
4
Trace the route
5
Stop the program
Procedure:
When one system (host or router) send the packet of data to another system then there be
two possibilities, Packet directly reach to destination system or it pas through one or more routers.
TRACERT command is useful to trace the route through which packet passes.
Result:
Thus the simulation of ping and traceroute command is executed and the output
is verified successfully.
EX NO 10
IMPLEMENTATION OF SUBNETTING
Aim
To write a C program to implement subnetting for the given IP address
36

Algorithm:
1.Start the program. Declare the variables using arrays.
2. Read the network address ,the Number of subnets and the subnet mask from the user.
3. Convert the given dotted decimal IP address and subnet mask into the binary form.
4. A subnet mask (or number) is used to determine the number of bits used for the subnet and host
portions of the address.
5. To create subnets, we increase the mask into required octet by enough bits to get subnets.
6. Now print all the subnet addresses.
For eg)
Lets subnet 129.99.0.0 into seven subnets.
129.99.0.0 is a Class B address with a natural mask of 255.255.0.0. To create subnets, we
increase the mask into the third octet by enough bits to get seven subnets. we see that three bits
will give us seven subnets, using an extended mask (subnet mask) of 255.255.224.0, as shown
below.

Result:
Thus the implementation of Subnetting is done and the output is verified successfully

EX NO 11a

STUDY OF NS-2 WITH SAMPLE PROGRAMS

AIM:
37

To study the Network Simulator NS2.


NS-2
Ns-2 is a discrete event simulator targeted at networking research. Ns provides substantial
support for simulation of TCP, routing, and multicast protocols over wired and wireless (local and
satellite) networks.

NS-2 ARCHITECTURE
Downloading/Installing ns&nam
One can build ns either from the various packages (Tcl/Tk, otcl, etc.), or can download an 'all-inone' package. web page: http://www.isi.edu/nsnam/ns/ns-build.html
Starting ns
Start ns with the command 'ns <tclscript>', where '<tclscript>' is the name of a Tcl script file
which defines the simulation scenario (i.e. the topology and the events). Just start ns without any
arguments and enter the Tcl commands in the Tcl shell, but that is definitely less comfortable.
Everything else depends on the Tcl script. The script might create some output on stdout, it might
write a trace file or it might start nam to visualize the simulation.
Starting nam
One can either start nam with the command 'nam <nam-file>' where '<nam-file>' is the name of a
nam trace file that was generated by ns, or one can execute it directly out of the Tcl simulation
script for the simulation which you want to visualize.

38

First TCL Script


Now we are going to write a 'template' that you can use for all of the first Tcl scripts. You can
write your Tcl scripts in any text editor like joe or emacs. I suggest that you call this first example
'example1.tcl'.
First of all, you need to create a simulator object. This is done with the command
set ns [new Simulator]
Now we open a file for writing that is going to be used for the nam trace data.
set nf [open out.nam w]
$ns namtrace-all $nf
The first line opens the file 'out.nam' for writing and gives it the file handle 'nf'. In the second line
we tell the simulator object that we created above to write all simulation data that is going to be
relevant for nam into this file.
The next step is to add a 'finish' procedure that closes the trace file and starts nam.
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
39

exit 0
}
You don't really have to understand all of the above code yet. It will get clearer to you once you
see what the code does.
The next line tells the simulator object to execute the 'finish' procedure after 5.0 seconds of
simulation time.
$ns at 5.0 "finish"
You probably understand what this line does just by looking at it. ns provides you with a very
simple way to schedule events with the 'at' command.
The last line finally starts the simulation.
$ns run
Ns-2 MAIN CONSOLE WITH NETWORK ANIMATOR

Result:
Thus the Network Simulator NS2 is studied successfully.

40

EX No 12

PERFORMANCE COMPARISION OF ROUTING PROTOCOLS

AIM:
To implement different routing algorithms and compare their performance using network
simulator (ns2)
a ) LINK STATE ROUTING ALGORITHM
ALGORITHM:
1. Define new simualtor
2. Define different colors for data flows (for NAM)
3. Define a new Trace file and open it
4. Define a new NAM Trace file and open it
5. Define a 'finish' procedure to flush trace record in the `trace and trace output files.
6. Define the routing protocol as Link State (LS)
7. Create six nodes n0,n1,..n5
8. Create links between the nodes with 0.3Mb and 10 ms Link with DropTail option
9. Give node position (for NAM) to place six nodes in the layout
10. Setup a TCP connection attach TCP Source Agent to node n0 and TCP sink agent to
node n5
11. Setup a FTP over TCP connection
12. Define configuration such that link between nodes n1 and n4 to be failed at 1.0 interval,
and up again at 4.5 interval
13. Start the simulation
OUTPUT

Before Link failure between Nodes n1 and n4


41

While Link failure between Nodes n1 and n4

After failed link between Nodes n1 and n4 up

Sample Trace file


42

//routing1.tr
+ 0.00017 0 1 rtProtoDV 6 ------- 0 0.2 1.1 -1 0
- 0.00017 0 1 rtProtoDV 6 ------- 0 0.2 1.1 -1 0
+ 0.007102 2 1 rtProtoDV 6 ------- 0 2.1 1.1 -1 1
- 0.007102 2 1 rtProtoDV 6 ------- 0 2.1 1.1 -1 1
+ 0.007102 2 3 rtProtoDV 6 ------- 0 2.1 3.1 -1 2
- 0.007102 2 3 rtProtoDV 6 ------- 0 2.1 3.1 -1 2
r 0.01033 0 1 rtProtoDV 6 ------- 0 0.2 1.1 -1 0
r 0.017262 2 1 rtProtoDV 6 ------- 0 2.1 1.1 -1 1
+ 0.017262 1 0 rtProtoDV 6 ------- 0 1.1 0.2 -1 3
- 0.017262 1 0 rtProtoDV 6 ------- 0 1.1 0.2 -1 3
b) FLOODING
PROCEDURE
Flooding is a simple routing algorithm in which every incoming packet is sent through
every outgoing link except the one it arrived on.
Flooding is used in bridging and in systems such as Usenet and peer-to-peer file
sharing and as part of some routing protocols, includingOSPF, DVMRP, and those used in ad-hoc
wireless networks.
There are generally two types of flooding available, Uncontrolled Flooding and Controlled
Flooding.
Uncontrolled Flooding is the fatal law of flooding. All nodes have neighbours and route
packets indefinitely. More than two neighbours creates a broadcast storm.
Controlled Flooding has its own two algorithms to make it reliable, SNCF (Sequence
Number Controlled Flooding) and RPF (Reverse Path Flooding). In SNCF, the node attaches its
own address and sequence number to the packet, since every node has a memory of addresses and
sequence numbers. If it receives a packet in memory, it drops it immediately while in RPF, the
node will only send the packet forward. If it is received from the next node, it sends it back to the
sender.
There are several variants of flooding algorithm. Most work roughly as follows:
1. Each node acts as both a transmitter and a receiver.
2. Each node tries to forward every message to every one of its neighbours except the source
node.
This results in every message eventually being delivered to all reachable parts of the
network.Algorithms may need to be more complex than this, since, in some case, precautions have
to be taken to avoid wasted duplicate deliveries and infinite loops, and to allow messages to
eventually expire from the system. A variant of flooding called selective flooding partially
addresses these issues by only sending packets to routers in the same direction. In selective
43

flooding the routers don't send every incoming packet on every line but only on those lines which
are going approximately in the right direction.
c) DISTANCE VECTOR ROUTING ALGORITHM
ALGORITHM:
1. Define new simulator
2. Define different colors for data flows (for NAM)
3. Define a new Trace file and open it
4. Define a new NAM Trace file and open it
5. Define a 'finish' procedure to flush trace record in the `trace and trace output files.
6. Define the routing protocol as Distance Vector (DV)
7. Create six nodes n0,n1,..n5
8. Create links between the nodes with 0.3Mb and 10 ms Link with DropTail option
9. Give node position (for NAM) to place six nodes in the layout
10. Setup a TCP connection attach TCP Source Agent to node n0 and TCP sink agent to
node n5
11. Setup a FTP over TCP connection
12. Define configuration such that link between nodes n1 and n4 to be failed at 1.0 interval,
and up again at 4.5 interval
13. Start the simulation
PROGRAM:

Distance Vector Routing Algorithm


AWK Script
AWK is a language for processing files of text. A file is treated as a sequence of records, and
by default each line is a record. Each line is broken up into a sequence of fields, so we can think
of the first word in a line as the first field, the second word as the second field, and so on
//measure-loss.awk
1. Initialization.
2. Set two variables - fsDrops: packets drop., numFs: packets sent
44

3. Count the number of packets sent by checking the status of the packet (source and
destination) and flag as receive (r)
4. Count the number of packets dropped by checking the status of the packet (source and
destination) and flag as drop (d)
COMPARISION
1. Save the above file as measure-loss.awk
2. Open terminal
3. After running routing1.tcl and routing2.tcl
4. Run the awk script to count number of packets sent between nodes 0 and 1
Type the command
$gwak -f measure-loss.awk <filename.tr>
steps
1. save the above file as measure-loss.awk
2. Open terminal
3. after running routing1.tcl and routing2.tcl
4. Run the awk script to count number of packets sent between nodes 0 and 1
Type the command
$gwak -f measure-loss.awk routing1.tr
number of packets sent:616 lost:2
$
$gawk -f measure-loss.awk routing1.tr
number of packets sent:203 lost:0
*/
/*
Open routing1.tr
search the file
.
.
d 1 1 4 tcp 1040 ------ 1 0.0 5.0 17 62
..
.
You will have a trace log showing the dropped packet information
*/
Result :
Thus the implementation of different routing algorithms and compare their performance
using network simulator (ns2) is executed and the output is verified successfully.

45

(CONTENT BEYOND THE SYLLABUS)


EX No 13

BIT STUFFING

AIM
To write a program that takes a binary file as input and performs the bit stuffing.

ALGORITHM
Server
1. Include necessary header files to support functions for Socket definitions, Socket Types, Internet
addresses, I/Ofunctions, Unix system calls.
2. Declare variables for Socket ID,Portnumber,Socket addresses, buffer,etc.
3. Create Socket for server.
4. Bind socket with addresses.
5. Specify number of allowed connections.
6. Wait for connection.
7. Accept connection (If any).
8. Take the binary input file.
9. Perform a bit stuffing by replacing every sixth bit by 0, if it is 1 , else check the next sixth bit and repeat
the process
10. Repeat the steps 8and 9 until the socket is closed.
11. Retrieve information from Connected Socket and display it.
12. Send information to Connected Socket.
13. Close Connected socket.
Client
1. Include necessary header files to support functions for Socket definitions, Socket types, Internet
addresses, I/O functions, Unix system calls.
2. Declare variables for Socket ID, Portnumber, Socket addresses, Character buffer, etc.
3. Create Socket for Client.
4. Connect client socket to the server socket addresses.
5. Enter the source file name for which the bit stuffing is performed.
6. Repeat the steps 8and 9 until the socket is closed.
7. Send information to Connected Socket
8. Retrieve information from Connected Socket and display it..
9. Close Connected socket.
SAMPLE OUTPUT :
CLIENT MESSAGE
FILENAME :source.txt
Input 1111111111111
111110111110
SAMPLE OUTPUT
Source filename: source.txt
RESULT:
Thus a c program for bit stuffing is executed and the output is verified successfully.
46

EX No 14

SIMULATION OF ROUTING PROTOCOL BGP

Aim

To simulate the implementation of the routing protocol BGP (Border Gateway Protocol)
Objective
Many nodes are obtained to check which node has the shortest path to source node . The
measures compared are cost of the node matrix and the minimum distance.
How it is being achieved?
Read n number of nodes and the cost for the node matrix is found. Make one
node as source node.Compute the minimum distance of each node with the source node. Then
the node with shortest path to source node is printed as result.
Syntax & keywords
To get number of nodes
printf("\n Enter the number of nodes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\n Enter the distance between the host %d - %d:",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
EXECUTION OF THE SOURCE CODE

REQUIREMENTS FOR EXECUTION


S.No. Facilities required

Quantity

System

O/S

Windws 98

Compiler

47

EXPECTED OUTPUT AND ITS FORM

This program implements BGP to get host cost matrix and path as input and identifies
the shortest path from source as output .
ALGORITHM
1. Read the no. of nodes n.
2. Read the cost matrix for the path from each node to another node.
3. Initialize SOURCE to 1 and include 1.
4. Compute D of a node which is the distance from source to that corresponding node.
5. Repeat step 6 to step 8 for n-l nodes.
6. Choose the node that has not been included whose distance is minimum and include
the node.
7. For every other node not included compare the distance directly from the source with the
distance to reach the node using the newly included node.
8. Take the minimum value as the new distance.
9. Print all the nodes with shortest path cost from source node.

OUTPUT
Enter the number of nodes: 5
Enter the distance between the host: 10
The output matrix :
10 15 20 25 30

RESULT:
Thus the above program to simulate the Routing Protocols using border gateway
protocol is executed and the output is verified successfully.

48

49