Download as pdf or txt
Download as pdf or txt
You are on page 1of 51

LIST OF EXPERIMENTS

Exp. No. Title


1. NETWORKING COMMANDS
2. WEB PAGE DOWNLOADING
3. A.SOCKET PROGRAM FOR ECHO
B. CLIENT- SERVER APPLICATION FOR CHAT
C. FILE TRANSFER IN CLIENT & SERVER
4. SIMULATION OF DNS USING UDP SOCKETS
5. SIMULATION OF ARP/RARP PROTOCOLS
6.
STUDY OF NETWORK SIMULATOR AND CONGESTION CONTROL
ALGORITHM

7. STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL


8.
SIMULATION OF DISTANCE VECTOR/LINK STATE ROUTING
ALGORITHM

9.
PERFORMANCE EVALUATION OF ROUTING PROTOCOLS USING
SIMULATION TOOL

10. SIMULATION OF ERROR CORRECTION CODE


11. TCP CONGESTION CONTROL ALGORITHM
12. BIT STUFFING
13. CHARACTER STUFFING
14. IMPLEMENTATION OF REMOTE COMMAND EXECUTION
15. TCP MODULE IMPLEMENTATION

HARDWARE AND SOFTWARE REQUIREMENTS


1
HARDWARE REQUIREMENTS

INTEL PENTIUM 915 GV

80GB HDD

512MB DDR

SOFTWARE REQUIREMENT

ORACLE 8i,9i.

MY SQL,

DB2.

2
EXP NO1
NETWORKING COMMANDS

AIM
To study the basic networking commands.

C:\>arp –a: ARP is short form of address resolution protocol, It will show the IP address of
your computer along with the IP address and MAC address of your router.

C:\>hostname: This is the simplest of all TCP/IP commands. It simply displays the name of
your computer.

C:\>ipconfig: The ipconfig command displays information about the host (the computer
your sitting at)computer TCP/IP configuration.

C:\>ipconfig /all: This command displays detailed configuration information about your
TCP/IP connection including Router, Gateway, DNS, DHCP, and type of Ethernet
adapter in your system.

C:\>Ipconfig /renew: Using this command will renew all your IP addresses that you are
currently (leasing) borrowing from the DHCP server. This command is a quick problem
solver if you are having connection issues, but does not work if you have been configured
with a static IP address.

C:\>Ipconifg /release: This command allows you to drop the IP lease from the DHCP
server.

C:\>ipconfig /flushdns: This command is only needed if you’re having trouble with your
networks DNS configuration. The best time to use this command is after network
configuration frustration sets in, and you really need the computer to reply with flushed.

C:\>nbtstat –a: This command helps solve problems with NetBIOS name resolution.
(Nbt stands for NetBIOS over TCP/IP)

C:\>netdiag: Netdiag is a network testing utility that performs a variety of network diagnostic
tests, allowing you to pinpoint problems in your network. Netdiag isn’t installed by default,
but can be installed from the Windows XP CD after saying no to the install. Navigate to the
CD ROM drive letter and open the support\tools folder on the XP
CD and click the setup.exe icon in the support\tools folder.

C:\>netstat: Netstat displays a variety of statistics about a computers active TCP/IP


connections. This tool is most useful when you’re having trouble with TCP/IP applications
such as HTTP, and FTP.

C:\>nslookup: Nslookup is used for diagnosing DNS problems. If you can access a
resource by specifying an IP address but not it’s DNS you have a DNS problem.
C:\>pathping: Pathping is unique to Window’s, and is basically a combination of the Ping
and Tracert commands. Pathping traces the route to the destination address then launches a
25 second test of each router along the way, gathering statistics on the rate of data loss along
each hop.

C:\>ping: Ping is the most basic TCP/IP command, and it’s the same as placing a phone call
to your best friend. You pick up your telephone and dial a number, expecting your best friend
to reply with “Hello” on the other end. Computers make phone calls to each other over a
network by using a Ping command. The Ping commands main purpose is to place a phone
call to another computer on the network, and request an answer. Ping has 2 options it can use
to place a phone call to another computer on the network. It can use the computers name or
IP address.

C:\>route: The route command displays the computers routing table. A typical
computer, with a single network interface, connected to a LAN, with a router is fairly
simple and generally doesn’t pose any network problems. But if you’re having trouble
accessing other computers on your network, you can use the route command to make sure the
entries in the routing table are correct.

C:\>tracert: The tracert command displays a list of all the routers that a packet has to go
through to get from the computer where tracert is run to any other computer on the
internet.

C:\>tcpdump: It is a most powerful and widely used command-line packets sniffer or package
analyzer tool which is used to capture or filter TCP/IP packets that received or transferred
over a network on a specific interface.

RESULT
Thus the above list of primitive has been studied.
EXP: 2
WEB PAGE DOWNLOADING

AIM
To download a webpage using Java

ALGORITHM:

CLIENT SIDE:
1) Start the program.
2) Create a socket which binds the Ip address of server and the port address to acquire
service.
3) After establishing connection send the url to server.
4) Open a file and store the received data into the file.
5) Close the socket.
6) End the program.

SERVER SIDE
1) Start the program.
2) Create a server socket to activate the port address.
3) Create a socket for the server socket which accepts the connection.
4) After establishing connection receive url from client.
5) Download the content of the url received and send the data to client.
6) Close the socket.
7) End the program.

PROGRAM

import javax.swing.*;
import java.net.*;
import
java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Client{
public static void main(String args[]) throws Exception{
Socket soc;
BufferedImage img = null;
soc=new Socket("localhost",4000);
System.out.println("Client is running. ");
try {
System.out.println("Reading image from disk. ");
img = ImageIO.read(new File("digital_image_processing.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close(); System.out.println("Sending image to server. ");
OutputStream out = soc.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(bytes.length);
dos.write(bytes, 0, bytes.length);
System.out.println("Image sent to server. ");
dos.close();
out.close();
}catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
soc.close();
}
soc.close();
}
}
SERVER PROGRAM

import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class Server {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
System.out.println("Server Waiting for image");
socket=server.accept();
System.out.println("Client connected.");
InputStream in = socket.getInputStream();
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB");
byte[] data = new byte[len];
dis.readFully(data);
dis.close();
in.close();
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
l.setIcon(icon);
f.add(l);
f.pack();
f.setVisible(true); }}
OUTPUT

RESULT
The webpage is successfully downloaded and the contents are displayed and verified.
EXP: 3A
SOCKET PROGRAM FOR ECHO.
AIM
To write a socket program for implementation of echo.

ALGORITHM

CLIENT SIDE
1. Start the program.
2. Create a socket which binds the Ip address of server and the port address to acquire
service.
3. After establishing connection send a data to server.
4. Receive and print the same data from server.
5. Close the socket.
6. End the program.

SERVER SIDE
1. Start the program.
2. Create a server socket to activate the port address.
3. Create a socket for the server socket which accepts the connection.
4. After establishing connection receive the data from client.
5. Print and send the same data to client.
6. Close the socket.
7. End the program.

PROGRAM
ECHO CLIENT
import java.io.*;
import java.net.*;
public class eclient
{
public static void main(String args[])
{
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os;
try
{
c=new Socket("localhost",8080);
}
catch(IOException e)
{
System.out.println(e);
}
try
{
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in);
is1=new DataInputStream(c.getInputStream());
do
{
System.out.println("client");
line=is.readLine();
os.println(line);
if(!line.equals("exit"))
System.out.println("server:"+is1.readLine());
}while(!line.equals("exit"));
}
catch(IOException e)
{
System.out.println("socket closed");
}}}

Echo Server:
import java.io.*;
import java.net.*;
import java.lang.*;
public class eserver
{
public static void main(String args[])throws IOException
{
ServerSocket s=null;
String line;
DataInputStream is;
PrintStream ps;
Socket c=null;
try
{
s=new ServerSocket(8080);
}
catch(IOException e)
{
System.out.println(e);
}
try
{
c=s.accept();
is=new DataInputStream(c.getInputStream());
ps=new PrintStream(c.getOutputStream());
while(true)
{
line=is.readLine();
System.out.println("msg received and sent back to client");
ps.println(line);
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}

OUTPUT
CLIENT
Enter the IP address 127.0.0.1
CONNECTION ESTABLISHED
Enter the data SRM
Client received SRM

SERVER
CONNECTION ACCEPTED
Server received SRM

RESULT
Thus the program for simulation of echo server was written & executed
EXP: 3B
CLIENT- SERVER APPLICATION FOR CHAT

AIM
To write a client-server application for chat using TCP

ALGORITHM

CLIENT
1. Start the program
2. Include necessary package in java
3. To create a socket in client to server.
4. The client establishes a connection to the server.
5. The client accept the connection and to send the data from client to server.
6. The client communicates the server to send the end of the message
7. Stop the program.

SERVER
1. Start the program
2. Include necessary package in java
3. To create a socket in server to client
4. The server establishes a connection to the client.
5. The server accept the connection and to send the data from server to client and
6. vice versa
7. The server communicate the client to send the end of the message.
8. Stop the program.

PROGRAM

TCPserver1.java

import java.net.*;
import java.io.*;

public class TCPserver1


{
public static void main(String arg[])
{
ServerSocket s=null;
String line;
DataInputStream is=null,is1=null;
PrintStream os=null;
Socket c=null;
try
{
s=new ServerSocket(9999);
}
catch(IOException e)
{
System.out.println(e);
}
try
{
c=s.accept();
is=new DataInputStream(c.getInputStream());
is1=new DataInputStream(System.in);
os=new PrintStream(c.getOutputStream());
do
{
line=is.readLine();
System.out.println("Client:"+line);
System.out.println("Server:");
line=is1.readLine();
os.println(line);
}
while(line.equalsIgnoreCase("quit")==false);
is.close();
os.close();
}
catch(IOException e)
{
System.out.println(e);
}
}
}

TCPclient1.java

import java.net.*;
import java.io.*;
public class TCPclient1
{
public static void main(String arg[])
{
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os;
try
{
c=new Socket("10.0.200.36",9999);
}
catch(IOException e)
{
System.out.println(e);
}
try
{
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in);
is1=new DataInputStream(c.getInputStream());
do
{
System.out.println("Client:");
line=is.readLine();
os.println(line);
System.out.println("Server:" + is1.readLine());
}
while(line.equalsIgnoreCase("quit")==false);
is1.close();
os.close();
}
catch(IOException e)
{
System.out.println("Socket Closed!Message Passing is over");
}}

OUTPUT:

SERVER

C:\Program Files\Java\jdk1.5.0\bin>javac TCPserver1.java


Note: TCPserver1.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin>java TCPserver1

Client: Hai Server


Server:Hai Client
Client: How are you
Server:Fine
Client: quit
Server:quit
CLIENT

C:\Program Files\Java\jdk1.5.0\bin>javac TCPclient1.java


Note: TCPclient1.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin>java TCPclient1

Client:Hai Server
Server: Hai Client
Client:How are you
Server: Fine
Client:quit
Server: quit

RESULT
Thus the above program a client-server application for chat using TCP / IP was
executed and successfully.
EXP: 3C
FILE TRANSFER IN CLIENT & SERVER

AIM
To Perform File Transfer in Client & Server Using TCP/IP.

ALGORITHM

CLIENT SIDE
1. Start.
2. Establish a connection between the Client and Server.
3. Socket ss=new Socket(InetAddress.getLocalHost(),1100);
4. Implement a client that can send two requests.
i) To get a file from the server.
ii) To put or send a file to the server.
5. After getting approval from the server ,the client either get file from the server or send
6. file to the server.

SERVER SIDE
1. Start.
2. Implement a server socket that listens to a particular port number.
3. Server reads the filename and sends the data stored in the file for the‘get’ request.
4. It reads the data from the input stream and writes it to a file in theserver for the
‘put’ instruction.
5. Exit upon client’s request.
6. Stop.

PROGRAM

CLIENT SIDE

import java.net.*;
import java.io.*;

public class FileClient{


public static void main (String [] args ) throws IOException {
int filesize=6022386; // filesize temporary hardcoded
long start = System.currentTimeMillis();
int bytesRead;
int current = 0;
// localhost for testing
Socket sock = new Socket("127.0.0.1",13267);
System.out.println("Connecting...");
// receive file
byte [] mybytearray = new byte [filesize];
InputStream is = sock.getInputStream();
FileOutputStream fos = new FileOutputStream("source-copy.pdf");
BufferedOutputStream bos = new BufferedOutputStream(fos);
bytesRead = is.read(mybytearray,0,mybytearray.length);
current = bytesRead;
// thanks to A. Cádiz for the bug fix
do {
bytesRead =
is.read(mybytearray, current, (mybytearray.length-current));
if(bytesRead >= 0) current += bytesRead;
} while(bytesRead > -1);

bos.write(mybytearray, 0 , current);
bos.flush();
long end =
System.currentTimeMillis();
System.out.println(end-start);
bos.close();
sock.close();
}}

SERVER SIDE

import java.net.*;
import java.io.*;

public class FileServer


{
public static void main (String [] args ) throws IOException {
ServerSocket servsock = new ServerSocket(13267);
while (true) {
System.out.println("Waiting...");
Socket sock = servsock.accept();
System.out.println("Accepted connection : " + sock);
File myFile = new File ("source.pdf");
byte [] mybytearray = new byte [(int)myFile.length()];
FileInputStream fis = new FileInputStream(myFile);
BufferedInputStream bis = new BufferedInputStream(fis);
bis.read(mybytearray,0,mybytearray.length);
OutputStream os = sock.getOutputStream();
System.out.println("Sending...");
os.write(mybytearray,0,mybytearray.length);
os.flush();
sock.close();
}}}
OUTPUT

SERVER OUTPUT

C:\Program Files\Java\jdk1.6.0\bin>javac FServer.java


C:\Program Files\Java\jdk1.6.0\bin>java FServer

Waiting for clients...

Connection Established
Client wants file:network.txt

CLIENT OUTPUT

C:\Program Files\Java\jdk1.6.0\bin>javac FClient.java


C:\Program Files\Java\jdk1.6.0\bin>java FClient

Connection request Connected


Enter the filename: network.txt
Computer networks: A computer network, often simply referred to as a network, is
acollection of computers and devices connected by communications channels
thatfacilitates communications among users and allows users to shareresources with other
user

RESULT
Thus the File transfer Operation is done & executed successfully.
EXP: 4
SIMULATION OF DNS USING UDP SOCKETS

AIM
To establish a link between UDP Server and UDP client.

ALGORITHM

CLIENT SIDE
1. Create UDP socket.
2. Send message to server.
3. Wait until response from server is recieved.
4. Process reply and go back to step 2, if necessary.
5. Close socket descriptor and exit.

SERVER SIDE
1. Create UDP socket.
2. Bind the socket to server address.
3. Wait until datagram packet arrives from client.
4. Process the datagram packet and send a reply to client.
5. Go back to Step 3.

UDP SERVER:

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

public class udpBaseServer_2


{
public static void main(String[] args) throws IOException
{
// Step 1 : Create a socket to listen at port 1234
DatagramSocket ds = new DatagramSocket(1234);
byte[] receive = new byte[65535];

DatagramPacket DpReceive = null;


while (true)
{

// Step 2 : create a DatgramPacket to receive the data.


DpReceive = new DatagramPacket(receive, receive.length);

// Step 3 : revieve the data in byte buffer.


ds.receive(DpReceive);

System.out.println("Client:-" + data(receive));
// Exit the server if the client sends "bye"
if (data(receive).toString().equals("bye"))
{
System.out.println("Client sent bye.....EXITING");
break;
}

// Clear the buffer after every message.


receive = new byte[65535];
}
}

// A utility method to convert the byte array


// data into a string representation.
public static StringBuilder data(byte[] a)
{
if (a == null)
return null;
StringBuilder ret = new StringBuilder();
int i = 0;
while (a[i] != 0)
{
ret.append((char) a[i]);
i++;
}
return ret;
}
}

UDP CLIENT:

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class udpBaseClient_2


{
public static void main(String args[]) throws IOException
{
Scanner sc = new Scanner(System.in);

// Step 1:Create the socket object for


// carrying the data.
DatagramSocket ds = new DatagramSocket();

InetAddress ip = InetAddress.getLocalHost();
byte buf[] = null;

// loop while user not enters "bye"


while (true)
{
String inp = sc.nextLine();

// convert the String input into the byte array.


buf = inp.getBytes();

// Step 2 : Create the datagramPacket for sending


// the data.
DatagramPacket DpSend =
new DatagramPacket(buf, buf.length, ip, 1234);

// Step 3 : invoke the send call to actually send


// the data.
ds.send(DpSend);

// break the loop if user enters "bye"


if (inp.equals("bye"))
break;
}
}
}

OUTPUT:

$ ./server
Client : Hello from client
Hello message sent.
$ ./client
Hello message sent.
Server : Hello from server

RESULT
Thus the link was created between UDP Server and UDP client.
EXP: 5
SIMULATION OF ARP/RARP PROTOCOLS

Aim:

To write a java program for simulating ARP protocols using TCP

ALGORITHM:

Client

1. Start the program


2. Using socket connection is established between client and server.
3. Get the IP address to be converted into MAC address.
4. Send this IP address to server.
5. Server returns the MAC address to client.

Server

1. Start the program


2. Accept the socket which is created by the client.
3. Server maintains the table in which IP and corresponding MAC addresses are stored.
4. Read the IP address which is send by the client.
5. Map the IP address with its MAC address and return the MAC address to client.

Program

Client:

import java.io.*; import java.net.*; import java.util.*; class Clientarp


{ public static void main(String args[])
{ try
{ BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream()); DataOutputStream
dout=new DataOutputStream(clsct.getOutputStream()); System.out.println("Enter the
Logical address(IP):");
String str1=in.readLine(); dout.writeBytes(str1+'\n'); String str=din.readLine();
System.out.println("The Physical Address is: "+str); clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}}}

Server:

import java.io.*; import java.net.*; import java.util.*; class Serverarp


{
public static void main(String args[])

{
try
{
ServerSocket obj=new ServerSocket(139); Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream()); DataOutputStream
dout=new DataOutputStream(obj1.getOutputStream()); String str=din.readLine();
String ip[]={"165.165.80.80","165.165.79.1"}; String
mac[]={"6A:08:AA:C2","8A:BC:E3:FA"}; for(int i=0;i<ip.length;i++)
{
if(str.equals(ip[i]))
{
dout.writeBytes(mac[i]+'\n');
break;
}
}
obj.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

Output:

E:\networks>java Serverarp

E:\networks>java Clientarp
Enter the Logical address(IP): 165.165.80.80

The Physical Address is: 6A:08:AA:C2

RESULT
Thus the simulations of ARP/RARP protocols are executed successfully.
EXP: 6
STUDY OF NETWORK SIMULATOR AND CONGESTION CONTROL
ALGORITHM

Aim:

To Study of Network simulator (NS).and Simulation of Congestion Control Algorithms using


NS

NET WORK SIMULATOR (NS2)


Ns overview

 Ns programming: A Quick start

 Case study I: A simple Wireless network

 Case study II: Create a new agent in Ns

Ns functionalities

Routing, Transportation, Traffic sources,Queuing disciplines, QoS

Wireless

Ad hoc routing, mobile IP, sensor-MAC


Tracing, visualization and various utilitie
NS(Network Simulators)

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, 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.
Examples of network simulators

There are many both free/open-source and proprietary network simulators. Examples of
notable network simulation software are, ordered after how often they are mentioned in research
papers:

1. ns (open source)
2. OPNET (proprietary software)
3. NetSim (proprietary software)

Uses of network simulators

Network simulators serve a variety of needs. Compared to the cost and time involved in setting
up an entire test bed containing multiple networked computers, routers and data links, network
simulators are relatively fast and inexpensive. They allow engineers, researchers to test
scenarios that might be particularly difficult or expensive to emulate using real hardware - for
instance, simulating a scenario with several nodes or experimenting with a new protocol in the
network. Network simulators are particularly useful in allowing researchers to test new
networking protocols or changes to existing protocols in a controlled and reproducible
environment. A typical network simulator encompasses a wide range of networking
technologies and can help the users to build complex networks from basic building blocks such
as a variety of nodes and links. With the help of simulators, one can design hierarchical
networks using various types of nodes like computers, hubs, bridges, routers, switches, links,
mobile units etc.

Various types of Wide Area Network (WAN) technologies like TCP, ATM, IP etc. and Local
Area Network (LAN) technologies like Ethernet, token rings etc., can all be simulated with a
typical simulator and the user can test, analyze various standard results apart from devising
some novel protocol or strategy for routing etc. Network simulators are also widely used to
simulate battlefield networks in 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 represent a network topology,
specifying the nodes on the network, the links between those nodes and the traffic between the
nodes. More complicated systems may allow the user to specify everything about the protocols
used to handle traffic in a network. Graphical applications allow users to easily visualize the
workings of their simulated environment. Text-based applications may provide a less intuitive
interface, but may permit more advanced forms of customization.

Packet loss

occurs when one or morepacketsof data travelling across a computer networkfail to reachtheir
destination. Packet loss is distinguished as one of the three main error types encountered in
digital communications; the other two being bit errorand spurious packets caused due to noise.

Packets can be lost in a network because they may be dropped when a queue in the network
node overflows. The amount of packet loss during the steady state is another important property
of a congestion control scheme. The larger the value of packet loss, the more difficult it is for
transportlayer protocols to maintain high bandwidths, the sensitivity to loss of individual
packets, as well as to frequency and patterns of loss among longer packet sequences is strongly
dependent on the application itself.
Throughput

This is the main performance measure characteristic, and most widely used.
Incommunicationnetworks, such asEthernetorpacket radio, throughputor network throughputis
the average rate of successfulmessage delivery over a communication channel. The throughput
is usually measured inbitsper second (bit/s orbps), andsometimes indata packetsper second or
data packets pertime slotThis measure how soon the receiver is able to get a certain amount of
data send by the sender. It is determined as the ratio of the total data received to the end to end
delay. Throughput is an important factor which directly impacts the network performance

Delay

Delay is the time elapsed while a packet travels from one point e.g., source premise or network
ingress to destination premise or network degrees. The larger the valueof delay, the more
difficult it is for transport layer protocols to maintain highbandwidths. We will calculate end to
end delay

Queue Length

A queuing system in networks can be described as packets arriving for service, waiting for
service if it is not immediate, and if having waited for service, leaving thesystem after being
served. Thus queue length is very important characteristic to determine that how well the active
queue management of the congestion control algorithm has been working.

RESULT:

Thus the Simulation of Congestion control algorithm using NS was studied.


EXP: 7
STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL

Aim:

To Study the performance of TCP/UDP Performance using Simulation tool.

User Datagram Protocol (UDP) and Transmission Control Protocol (TCP) are a transportation
layer routing protocols which are considered of the core protocols of the internet protocol suite.
The behaviour of these routing protocols with different network metrics and scenarios is still not
very clear. Therefore, this paper presents a comparison of the performance of both TCP and
UDP to precisely determine which of these protocols is better. Network Simulator version 2.35
(NS2) is utilized to analyse and evaluate the performance for both TCP and UDP protocols
varying in the packet size and the bandwidth. In this study, we have used two scenarios, in the
first scenario the bandwidth has been changed with fixed packet size and in the second scenario
the packet size has been changed with fixed bandwidth to precisely verify the performance of
these protocols. These protocols were examined in terms of the rate end-to-end delay, rate
throughput, packet delivery ratio, and packet loss ratio

TCP is represented as a connection-oriented protocol, TCP presents end-to-end


communications. Moreover, when the communication is created among the transmitter and
receiver, the data can be send over that communication. While the UDP is a simple
connectionless protocol. UDP does not constitute a dedicated end-to-end communication among
the transmitter and the receiver before the real communication takes place. However, the data is
being transported in one trend from the transmitter to the receiver with no need to verifying the
receiver case. Figure 1 shows the segment fields of TCP and UDP.

Fig. 1. The Segment Fields of TCP and UDP

The UDP and TCP are various on the basic operations and applications. The differences in the
data transmission, the TCP presents ordered and reliable delivery of data from the user to the
server and vice versa. UDP considered as a connectionless protocol and does not provide the
reliable delivery for the data. UDP and TCP are various from each other in terms of the basic
features for the data transmission [13]. However, TCP is more reliable comparing to the UDP,
where TCP uses the retransmissions and the message acknowledgment if there is some loss in
the packets. Therefore, there is no losing data in the network. While in the case of UDP does
not guarantee that the data has arrived to the receiver or not. Also, in UDP there is no
retransmission, timeout and message acknowledgment. TCP transmits the messages in an order
and these messages are received in the same order at the destination. If the packets of the data
reach in the wrong order, TCP can reorder the data packets. Whilst in UDP, the sequence of the
message is not maintained over the transmission. TCP records the data as a stream of bytes and
sending the message as segments. The messages in UDP are sending as datagrams in the
network. So, both of TCP and UDP have various approaches of sending and receiving the data
Figure 2 shows a comparative among TCP and UDP.

RESULT:
Thus the Performance of TCP and UDP were studied..
EXP: 8
SIMULATION OF DISTANCE VECTOR/LINK STATE ROUTING
ALGORITHM

AIM
To study the link state routing

LINK STATE ROUTING


Routing is the process of selecting best paths in a network. In the past, the term
routing was also used to mean forwarding network traffic among networks. However this
latter function is much better described as simply forwarding. Routing is performed for
many kinds of networks, including the telephone network (circuit switching), electronic
data networks (such as the Internet), and transportation networks. This article is concerned
primarily with routing in electronic data networks using packet switching technology.
In packet switching networks, routing directs packet forwarding (the transit of
logically addressed network packets from their source toward their ultimate destination)
through intermediate nodes. Intermediate nodes are typically network hardware devices
such as routers, bridges, gateways, firewalls, or switches. General-purpose computers can
also forward packets and perform routing, though they are not specialized hardware and
may suffer from limited performance. The routing process usually directs forwarding on the
basis of routing tables which maintain a record of the routes to various network
destinations. Thus, constructing routing tables, which are held in the router's memory, is
very important for efficient routing. Most routing algorithms use only one network path at a
time. Multipath routing techniques enable the use of multiple alternative paths.
In case of overlapping/equal routes, the following elements are considered in order to
decide which routes get installed into the routing table (sorted by priority):
1. Prefix-Length: where longer subnet masks are preferred (independent of whether it
is within a routing protocol or over different routing protocol)
2. Metric: where a lower metric/cost is preferred (only valid within one and the same
routing protocol)
3. Administrative distance: where a lower distance is preferred (only valid between
different routing protocols)

Routing, in a more narrow sense of the term, is often contrasted with bridging in its
assumption that network addresses are structured and that similar addresses imply
proximity within the network. Structured addresses allow a single routing table entry to
represent the route to a group of devices. In large networks, structured addressing (routing,
in the narrow sense) outperforms unstructured addressing (bridging). Routing has become
the dominant form of addressing on the Internet. Bridging is still widely used within
localized environments.
ALGORITHM
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 Exp. No.ire 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 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.

DISTANCE VECTOR
In computer communication theory relating to packet-switched networks, a distance-
vector routing protocol is one of the two major classes of routing protocols, the other major
class being the link-state protocol. Distance-vector routing protocols use the Bellman–Ford
algorithm, Ford–Fulkerson algorithm, or DUAL FSM (in the case of Cisco Systems's
protocols) to calculate paths.
A distance-vector routing protocol requires that a router informs its neighbors of topology
changes periodically. Compared to link-state protocols, which require a router to inform all
the nodes in a network of topology changes, distance-vector routing protocols have less
computational complexity and message overhead.
The term distance vector refers to the fact that the protocol manipulates vectors
(arrays) of distances to other nodes in the network. The vector distance algorithm was the
original ARPANET routing algorithm and was also used in the internet under the name of
RIP (Routing Information Protocol).
Examples of distance-vector routing protocols include RIPv1 and RIPv2 and IGRP.
Method
Routers using distance-vector protocol do not have knowledge of the entire path to
a destination. Instead they use two methods:
1. Direction in which router or exit interface a packet should be forwarded.
2. Distance from its destination
Distance-vector protocols are based on calculating the direction and distance to any
link in a network. "Direction" usually means the next hop address and the exit interface.
"Distance" is a measure of the cost to reach a certain node. The least cost route between any
two nodes is the route with minimum distance. Each node maintains a vector (table) of
minimum distance to every node. The cost of reaching a destination is calculated using
various route metrics. RIP uses the hop count of the destination whereas IGRP takes into
account other information such as node delay and available bandwidth.
Updates are performed periodically in a distance-vector protocol where all or part of a
router's routing table is sent to all its neighbors that are configured to use the same distance-
vector routing protocol. RIP supports cross-platform distance vector routing whereas IGRP
is a Cisco Systems proprietary distance vector routing protocol. Once a router has this
information it is able to amend its own routing table to reflect the changes and then inform
its neighbors of the changes. This process has been described as ‗routing by rumor‘
because routers are relying on the information they receive from other routers and cannot
determine if the information is actually valid and true. There are a number of features which
can be used to help with instability and inaccurate routing information.

Method
Routers using distance-vector protocol do not have knowledge of the entire path to
a destination. Instead they use two methods:
1. Direction in which router or exit interface a packet should be forwarded.
2. Distance from its destination
Distance-vector protocols are based on calculating the direction and distance to any link in a
network. "Direction" usually means the next hop address and the exit interface. "Distance"
is a measure of the cost to reach a certain node. The least cost route between any two
nodes is the route with minimum distance. Each node maintains a vector (table) of
minimum distance to every

node. The cost of reaching a destination is calculated using various route metrics. RIP
uses the hop count of the destination whereas IGRP takes into account other information
such as node delay and available bandwidth. Updates are performed periodically in a
distance-vector protocol where all or part of a router's routing table is sent to all its
neighbors that are configured to use the same distance-vector routing protocol. RIP supports
cross-platform distance vector routing whereas IGRP is a Cisco Systems proprietary
distance vector routing protocol. Once a router has this information it is able to amend its
own routing table to reflect the changes and then inform its neighbors of the changes. This
process has been described as routing by rumor‘ because routers are relying on the
information they receive from other routers and cannot determine if the information is
actually valid and true. There are a number of features which can be used to help with
instability and inaccurate routing information.
EGP and BGP are not pure distance-vector routing protocols because a distance-vector
protocol calculates routes based only on link costs whereas in BGP, for example, the local
route preference value takes priorityover the link cost.

Count-to-infinity problem
The Bellman–Ford algorithm does not prevent routing loops from happening and suffers
from the count to infinity problem. The core of the count-to-infinity problem is that if A
tells B that it has a path somewhere, there is no way for B to know if the path has B as a part
of it. To see the problem clearly, imagine a subnet connected like A–B–C–D–E–F, and let
the metric between the routers be "number of jumps". Now suppose that A is taken offline.
In the vector-update-process B notices that the route to A, which was distance 1, is down –
B does not receive the vector update from A. The problem is, B also gets an update from
C, and C is still not aware of the fact that A is down – so it tells B that A is only two jumps
from C (C to B to A), which is false. This slowly propagates through the network until it
reaches infinity (in which case the algorithm corrects itself, due to the relaxation property of
Bellman–Ford).

Sample program:
set ns [new
Simulator] set
nr [open
thro.tr w]
$ns trace-all $nr
setnf [open thro.nam w]
$ns namtrace-
all $nf proc
finish { }
{global ns nr nf
$ns
flush-
trace
close
$nf
close
$nr
execnamthro.nam&
exit 0}
for { set i 0 }
{ $i < 12}
{ incr i 1 }
{set n($i) [$ns
node]} for
{set i 0}
{$i < 8}
{incr i}
{$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }

$ns duplex-link $n(11) $n(5) 1Mb 10ms


DropTail set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent
$udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0
$null0 set udp1
[new Agent/UDP]
$ns attach-agent $n(1)
$udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent
$udp1 set null0
[new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto DV
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run
SAMPLE OUTPUT:

RESULT:

Thus the simulation of Distance vector/Link State Routing algorithm was performed.
EXP: 9
PERFORMANCE EVALUATION OF ROUTING PROTOCOLS USING
SIMULATION TOOL

AIM
To learn the performance evaluation of Routing Protocols using Simulation tool.

ROUTING PROTOCOL:

Routing Protocol is used to find valid routes between communicating nodes. They do not use
any access points to connect to other nodes .It must be able to handle high mobility of the
nodes. Routing protocols can be mainly classified into 3 categories.

 Centralized versus Distributed


 Static versus Adaptive
 Reactive versus Proactive

In centralized algorithms, all route choices are made by central node, while in distributed
algorithms, the computation of routes is shared among the network nodes. In static algorithms
the route used by source destination pairs is fixed regardless of traffic condition. It can only
change in response to a node or link failure. This type of algorithm cannot achieve high
throughput under a broad variety of traffic input patterns. In adaptive routing, the routes used
to route between source destination pairs may change in response to congestion.

Routing is the process of finding a path from a source to destination among randomly
distributed routers. MANET routing protocols are classified as follows on the basis of the
way the network information is obtained in these routing protocols.

i. Proactive (or Table-driven) routing protocol

The Proactive routing protocols, consistent and up-to-date routing information to all nodes is
maintained at each node. For example
1.Optimized Link state Routing Protocols (OLSR)
2.Destination Sequenced Distance Vector Routing (DSDV)
ii. Reactive or On-demand routing protocol The reactive routing protocols look for the
routes and are created as and when required. When a source wants to send to a destination, it
invokes the route discovery mechanisms to find the path to the destination. It does not need
to search for and maintain the routes on which there is no route request. Reactive routing
protocols are very pleasing in the resource-limited environment. However the source node
should wait until a route to the destination is discovered. This approach is best suitable when
the network is static and traffic is very light. For example, 1. Ad-Hoc On-demand Distance
Vector (AODV) [9] 2. Dynamic Source Routing (DSR) iii. Hybrid Protocols These protocols
are using the best features of both the ondemand and table driven routing protocols. The Ad
Hoc network can use the hybrid routing protocols that have the advantage of both proactive
and reactive routing protocols to balance the delay and control overhead (in terms of control
packages). The difficulty of all hybrid routing protocols is the complexity of organizing the
network according to network parameters. The common disadvantage of hybrid routing
protocols is that the nodes that have high level topological information maintains more
routing information, which leads to more memory and power consumption. For example 1.
Temporally ordered routing algorithm (TORA) 2. Zone Routing Protocol (ZRP) There are
two approaches to evaluate routing protocols:  Network Environment Parameters like
network size, connectivity, mobility, link capacity etc.  General Performance Metrics of
Routing Protocols like message delivery ratio, control overhead, hop count, end to end delay,
etc. In this paper packet delivery ratio and average end to end delay performance parameters
are considered.

Overview of AODV:

Ad-hoc On Demand Distance Vector Routing Protocol (AODV) is one of the reactive protocol
in which source node initiates data packet to destination node only when requires the route
discovery is occur. there are no periodical exchanges of routing information.[9] The Protocol
consist of two phases: i) Route Discovery ii) Route Maintenance. i. Route Discovery AODV
routing protocol uses a broadcast route discovery mechanism and it depends on dynamically
established route. AODV builds routes by using a route request (RREQ)/ route reply (RREP)
query cycle. When a source node requires a destination route for which it does not have a route
already, it broadcasts RREQ packet across the network The nodes receiving this packet update
the information for the source node and sets up backward pointer information for the source
node in the routing table. A lifetime is associated with each reverse route entry, i.e. if the route
entry is not used within the lifetime it will be removed. AODV route discovery process ii. Route
Maintenance The second phase of the protocol is called route maintenance. It is performed by
the source node and can be subdivided into: i) source node moves: source node initiates a new
route discovery process, ii) destination or an intermediate node moves: a route error message
(RERR) is sent to the source node. Intermediate nodes receiving a RERR update their routing
table by setting the distance of the destination to infinity. If the source node receives a RERR it
will initiate a new route discovery. To prevent global broadcast messages AODV introduces a
local connectivity management. This is done by periodical exchanges of so called HELLO
messages which are small RREP packets containing a node's address and additional
information.

RESULT:

Thus the performance of routing protocols was examined.


EXP: 10
SIMULATION OF ERROR CORRECTION CODE

AIM:

To do the Simulation of Error Correction code.

General Algorithm of Hamming code –


The Hamming Code is simply the use of extra parity bits to allow the identification of an error.
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position in
binary form.
a. Parity bit 1 covers all the bits positions whose binary representation includes a 1 in the
least significant
position (1, 3, 5, 7, 9, 11, etc).
b. Parity bit 2 covers all the bits positions whose binary representation includes a 1 in the
second position from
the least significant bit (2, 3, 6, 7, 10, 11, etc).
c. Parity bit 4 covers all the bits positions whose binary representation includes a 1 in the
third position from
the least significant bit (4–7, 12–15, 20–23, etc).
d. Parity bit 8 covers all the bits positions whose binary representation includes a 1 in the
fourth position from
the least significant bit bits (8–15, 24–31, 40–47, etc).
e. In general each parity bit covers all bits where the bitwise AND of the parity position
and the bit position is
non-zero.
5. Since we check for even parity set a parity bit to 1 if the total number of ones in the
positions it checks is
odd.
6. Set a parity bit to 0 if the total number of ones in the positions it checks is even.

import java.io.*;
class crc_gen
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int[] data;
int[] div;
int[] divisor;
int[] rem;
int[] crc;
int data_bits, divisor_bits, tot_length;

System.out.println("Enter number of data bits : ");


data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];

System.out.println("Enter data bits : ");


for(int i=0; i<data_bits; i++)
data[i]=Integer.parseInt(br.readLine());

System.out.println("Enter number of bits in divisor : ");


divisor_bits=Integer.parseInt(br.readLine());
divisor=new int[divisor_bits];

System.out.println("Enter Divisor bits : ");


for(int i=0; i<divisor_bits; i++)
divisor[i]=Integer.parseInt(br.readLine());

/* System.out.print("Data bits are : ");


for(int i=0; i< data_bits; i++)
System.out.print(data[i]);
System.out.println();

System.out.print("divisor bits are : ");


for(int i=0; i< divisor_bits; i++)
System.out.print(divisor[i]);
System.out.println();

*/ tot_length=data_bits+divisor_bits-1;

div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
/*------------------ CRC GENERATION-----------------------*/
for(int i=0;i<data.length;i++)
div[i]=data[i];

System.out.print("Dividend (after appending 0's) are : ");


for(int i=0; i< div.length; i++)
System.out.print(div[i]);
System.out.println();

for(int j=0; j<div.length; j++){


rem[j] = div[j];
}

rem=divide(div, divisor, rem);

for(int i=0;i<div.length;i++) //append dividend and ramainder


{
crc[i]=(div[i]^rem[i]);
}
System.out.println();
System.out.println("CRC code : ");
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);

/*-------------------ERROR DETECTION---------------------*/
System.out.println();
System.out.println("Enter CRC code of "+tot_length+" bits : ");
for(int i=0; i<crc.length; i++)
crc[i]=Integer.parseInt(br.readLine());

/* System.out.print("crc bits are : ");


for(int i=0; i< crc.length; i++)
System.out.print(crc[i]);
System.out.println();
*/
for(int j=0; j<crc.length; j++){
rem[j] = crc[j];
}

rem=divide(crc, divisor, rem);

for(int i=0; i< rem.length; i++)


{
if(rem[i]!=0)
{
System.out.println("Error");
break;
}
if(i==rem.length-1)
System.out.println("No Error");
}

System.out.println("THANK YOU.... :)");


}

static int[] divide(int div[],int divisor[], int rem[])


{
int cur=0;
while(true)
{
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);

while(rem[cur]==0 && cur!=rem.length-1)


cur++;

if((rem.length-cur)<divisor.length)
break;
}
return rem;
}
}

OUTPUT :
Enter number of data bits :
7
Enter data bits :
1
0
1
1
0
0
1
Enter number of bits in divisor :
3
Enter Divisor bits :
1
0
1
Data bits are : 1011001
divisor bits are : 101
Dividend (after appending 0's) are : 101100100

CRC code :
101100111
Enter CRC code of 9 bits :
1
0
1
1
0
0
1
0
1
crc bits are : 101100101
Error
THANK YOU.... :)
Press any key to continue...

RESULT:

Thus the simulation of error correction code was performed.


EXP: 11
TCP CONGESTION CONTROL ALGORITHM

AIM:

To learn about the TCP Congestion control algorithm


Re-transmissions, Timeouts and Duplicate Acknowledgements

TCP is relegated to rely mostly upon implicit signals it learns from the network and
remote host. TCP must make an educated guess as to the state of network and trust the
information from the remote host in order to control the rate of data flow.

A sender's implicit knowledge of network conditions may be achieved through the use of a
timer. For each TCP segment sent the sender expects to receive an acknowledgement
within some period of time otherwise an error in the form of a timer expiring signals that
something is wrong.

Whenever the TCP transmits a segment the sender starts a timer which keeps track how
long it takes for an acknowledgement for that segment to return.
This timer is known as re-transmission timer.

 If acknowledgement is returned before the timer expires the timer is reset with no
consequence.
 If an acknowledgement for the segment does not return with in the timeout period,
the sender re-transmit the segment and double the re-transmission timeout period.

TCP keeps track of when data is sent and at what time acknowledgements covering those
sent bytes are returned. TCP uses this information to calculate an estimate of round trip
time.
As packets are sent and acknowledged, TCP adjusts its round trip time estimate and uses
this information to come up with a reasonable timeout value for packets sent.

Slow Start(Sender based flow control)


This is accomplished through return rate acknowledgement from the receiver. In other
words, the rate of acknowledgements returned from the receiver determine the rate at
which the sender can transmit data.
When a TCP connection first begins, the slow start algorithm initializes a congestion
window to one segment ,which is maximum segment size (1 MSS) initialized by the
receiver during the connection establishment phase when acknowledgements are returned
by the receiver, the congestion window increases by one segment for each
acknowledgement returned.
Thus the sender can transmit the minimum of the congestion window and the advertised
window of the receiver. which is simply called the transmission window.

For example: The first successful transmission and acknowledgement of TCP segment
increases the window to two segments. After successful transmission of two segments and
acknowledgement completes, the window is increased to four segments. doubling from
there on out up to the maximum window size is advertised by the receiver or until the
congestion finally does occur.

At some point the congestion window may become too large for the network or network
conditions may change such that packets may be dropped.Packet lost will trigger a time
out at the sender. When this happens, the sender goes into congestion mode.

Congestion Avoidance
A re-transmission timer expiring or the reception of duplicate acknowledgements can
implicitly signal the sender that a network congestion situation is occurring.
The sender immediately sets its transmission window to one half of the current window
size (the minimum of the congestion window and the receiver advertised windows), but to
at least two segments.

 If congestion was indicated by a timeout the congestion window is reset to one


segment, which automatically puts the sender into slow start mode
 If congestion was indicated by duplicate Acknowledgements the fast re-
transmit and fast recovery algorithms are invoked.

Fast Re-transmit

 When a duplicate acknowledgement is received the sender does not know if it is


because a TCP segment was lost or simply that a segment was delayed and
received out of order at the receiver.
 If more than two duplicate Acknowledgements are received by the sender, it is a
strong indication that at least one segment has been lost.
 When three or more duplicate acknowledgements are received, the sender does
not even wait for a re-transmission time to expire before re-transmitting the
segment ( the sender enters the congestion avoidance mode).
State Event TCP sender Congestion control action

Slow start Ack. receipt Congwin = Congwin + MSS


if ( Congwin >= threshold)
{
set state to "Congestion avoidance"
}

Congestion Ack. receipt Congwin = Congwin + MSS


Avoidance .(MSS/Congwin)
Slow start or lost event by triple Threshold = Congwin/2
Congestion duplicate Ack. Congwin = Threshold
Avoidance set state to congestion avoidance
Slow start or Time out Threshold = Congwin/2
Congestion Congwin = 1MSS
Avoidance set state to slow start
Slow start or Duplicate Ack. Increment duplicate Ack. count for segment
Congestion being acknowledged
Avoidance

Congwin = Congestion Window

RESULT
Thus the Congestion control algorithm was studied.
EXP: 12
BIT STUFFING

AIM:

To learn about the bit stuffing.

ALGORITHM:
1. Start
2. Initialize the array for transmitted stream with the special bit pattern 0111 1110 which
indicates the beginning of the frame.
3. Get the bit stream to be transmitted in to the array.
4. Check for five consecutive ones and if they occur, stuff a bit 0
5. Display the data transmitted as it appears on the data line after appending 0111 1110 at
the end
6. For de−stuffing, copy the transmitted data to another array after detecting the stuffed bits
7. Display the received bit stream
8. Stop

PROGRAM

#include<stdio.H>
#include<conio.H>
#include<string.h>
void main()
{
int a[20],b[30],i,j,k,count,n;
clrscr();
printf("enter frame length:");
scanf("%d",&n);
pritf("enter input frame(0's&1's
only):");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0;count=1;j=0;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;a[k]==1&&k<n&&count<5;k++)
{
j++;
b[j]=a[k];
count++;
if(count==5)
{
j++;
b[j]=0;
}
i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("After stuffing the frame is:");
for(i=0;i<j;i++)
printf("%d",b[i]);
getch();
}

OUTPUT

RESULT
Thus the Bit Stuffing was executed successfully.
EXP: 13
CHARACTER STUFFING.
AIM:
Write a C program to Implement the data link layer framing method such as character stuffing.

ALGORITHM
1. Start
2. Append DLE STX at the beginning of the string
3. Check the data if character is present; if character DLE is present in the string (example
DOODLE) insert another DLE in the string (ex: DOODLEDLE)
4. Transmit DLE ETXat the end of the string
5. Display the string
6. Stop
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
clrscr();
printf("enter string:\n");
scanf("%s",&a);
n=strlen(a);
printf("enter position\n");
scanf("%d",&pos);
if(pos>n)
{
printf("invalid position,Enter again:");
scanf("%d",&pos);
}
printf("enter the character\n");
ch=getche();
b[0]='d';
b[1]='l';
b[2]='e';
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
{
if(i==pos-1)
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
}
if(a[i]=='d'&&a[i+1]=='l'&& a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e;
j=j+3;
}
b[j]=a[i];
i++;
j++;
}
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("\n frame after stuffing: \n");
printf("%s",b);
getch();
}
OUTPUT:

RESULT
Thus the Bit Stuffing was executed successfully.
EXP: 14
IMPLEMENTATION OF REMOTE COMMAND EXECUTION

AIM

To implement Remote Command Execution(RCE).


ALGORITHM
CLIENT SIDE
1. Establish a connection between the Client and Server.
Socket client=new Socket("127.0.0.1",6555);
2. Create instances for input and output streams.
Print Stream ps=new Print Stream(client.getOutputStream());
3. BufferedReader br=newBufferedReader(newInputStreamReader(System.in));
4. Enter the command in Client Window.
Send themessage to its output
str=br.readLine();
ps.println(str);
SERVER SIDE
1. Accept the connection request by the client.
ServerSocket server=new ServerSocket(6555);
Socket s=server.accept();
2. Get the IPaddress fromits inputstream.
BufferedReader br1=newBufferedReader(newInputStreamReader(s.getInputStream()));
ip=br1.readLine();
3. During runtime execute the process
Runtime r=Runtime.getRuntime();
Process p=r.exec(str);
CLIENT PROGRAM
import java.io.*;
import java.net.*;
class clientRCE
{
public static void main(String args[]) throws IOException
{
try
{
String str;Socket client=new Socket("127.0.0.1",6555);
PrintStream ps=new PrintStream(client.getOutputStream());
BufferedReader br=newBufferedReader(newInputStreamReader(System.in));
System.out.println("\t\t\t\tCLIENT WINDOW\n\n\t\tEnter TheCommand:");
str=br.readLine();
ps.println(str);
}
catch(IOException e)
{
System.out.println("Error"+e); }}}
SERVER PROGRAM:
import java.io.*;
import java.net.*;
class serverRCE
{
public static void main(String args[]) throws IOException
{
try
{
String str;
ServerSocket server=new ServerSocket(6555);
Socket s=server.accept();
BufferedReader br=newBufferedReader(newInputStreamReader(s.getInputStream()));
str=br.readLine();
Runtime r=Runtime.getRuntime();
Process p=r.exec(str);
}
catch(IOException e)
{
System.out.println("Error"+e);
}
}}
OUTPUT
C:\Networking Programs>java serverRCE
C:\Networking Programs>java clientRCE
CLIENT WINDOW
Enter The Command:
Notepad

RESULT
Thus the implementation RCE is done & executed successfully.
EXP: 15
TCP MODULE IMPLEMENTATION
AIM
To write a socket program for implementation of TCP module.

ALGORITHM

CLIENT SIDE
1) Start the program.
2) Create a socket which binds the Ip address of server and the port address to acquire service.
3) After establishing connection send a data to server.
4) Close the socket.
5) End the program.

SERVER SIDE
1) Start the program.
2) Create a server socket to activate the port address.
3) Create a socket for the server socket which accepts the connection.
4) After establishing connection receive the data from client.
5) Print the data.
6) Close the socket.
7) End the program.

CLIENT PROGRAM
import java.io.*;
import java.net.*;

public class client2


{
static String a;
static String b;
public static void main(String args[])throws IOException
{
Socket s=new Socket("127.0.0.1",8080);
BufferedReader c=new BufferedReader(new InputStreamReader(System.in));
DataOutputStream d1=new DataOutputStream(s.getOutputStream());
DataInputStream d2=new DataInputStream(s.getInputStream());
do
{
String st=new String(d2.readUTF());
System.out.println("s::"+st);
System.out.println("c::");
a=c.readLine();
d1.writeUTF(a);
}while(!a.equals("exit"));
d2.close();
d1.close();
s.close();
}
SERVER PROGRAM
import java.io.*;
import java.net.*;
public class server1
{
public static void main(String args[])throws IOException
{
ServerSocket s=new ServerSocket(8080);
System.out.println("socket is created");
System.out.println("waiting for client");
Socket s1=s.accept();
DataOutputStream d1=new DataOutputStream(s1.getOutputStream());
BufferedReader c=new BufferedReader(new InputStreamReader(System.in));
String e=c.readLine();
d1.writeUTF(e);
d1.close();
s1.close();
}}
OUTPUT
CLIENT
Enter the IP address 127.0.0.1
CONNECTION ESTABLISHED
Enter the data SRM
SERVER
CONNECTION ACCEPTED
Server received SRM

RESULT
Thus the program for tcp module implementation was written & executed successfully.

You might also like