Sie sind auf Seite 1von 53

EX.NO.

1 NETWORK COMMANDS

Aim
To learn and use network commands .

COMMANDS

1.netstat

netstat stands for network statistics. This command displays incoming


and outgoing network connections as well as other network
information. It’s available on Windows, Mac, and Linux each version
has its own command-line options you can tweak to see different
types of information. The netstat utility can show you the open
connections on your computer, which programs are making which
connections, how much data is being transmitted, and other
information.

2. ipconfig

The ipconfig command is used on Windows, while the ifconfig


command is used on Linux, Mac OS X, and other Unix-like operating
systems. These commands allow you to configure your network
interfaces and view information about them. For example, you can
use the ipconfig /all command on Windowsto view all your
configured network interfaces, their IP addresses, DNS servers, and
other information. Or, you can use the ipconfig /flushdns command to
flush your DNS cache, forcing Windows to get new addresses from
its DNS servers every time you contact a new hostname. Other
commands can force your computer to release its IP address and get a
new one from its DHCP server. This utility can quickly display your
computer’s IP address or help you troubleshoot problems.

3.nslookup

The nslookup command will look up the IP addresses associated with


a domain name. For example, you can run nslookup
howtogeek.com to see the IP address of How-To Geek’s server.
Your computer is constantly querying its DNS servers to translate
domain names to IP addresses. This command just allows you to do it
manually. nslookup also allows you to perform a reverse lookup to
find the domain name associated with an IP address. For
example,nslookup 208.43.115.82 will show you that this IP address
is associated with howtogeek.com.

4.traceroute / tracert / tracepath

The traceroute, tracert, or tracepath command is similar to ping, but


provides information about the path a packet takes. traceroute sends
packets to a destination, asking each Internet router along the way to
reply when it passes on the packet. This will show you the path
packets take when you send them between your location and a
destination. This tool can help troubleshoot connection problems. For
example, if you can’t communicate with a server, running traceroute
may show you where the problem is occurring between your
computer and the remote host.
5.ping

The ping command sends ICMP echo request packets to a destination.


For example, you could run ping google.com orping
173.194.33.174 to ping a domain name or IP address. These packets
ask the remote destination to reply. If the remote destination is
configured to reply, it will respond with packets of its own. You’ll be
able to see how long the round-trip time is between your computer
and the destination. You’ll see a “request timed out” message if
packet loss is occurring, and you’ll see an error message if your
computer can’t communicate with the remote host at all. This tool can
help you troubleshoot Internet connection problems, but bear in mind
that many servers and devices are configured not to reply to pings.
6.Tcpdump

tcpdump 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. It is available under most of the Linux/Unix based
operating systems. tcpdump also gives us a option to save captured
packets in a file for future analysis. It saves the file in a pcap format,
that can be viewed by tcpdump command or a open source GUI based
tool called Wireshark (Network Protocol Analyzier) that reads
tcpdump pcap format files.
Capture packets from specific interface

Capture only n number of packets

Print captured packets in ASCII


Display available interfaces

Capture and save packets in file

RESULT
Thus the network commands was leaned and used successfully.
Ex.no.2 CREATE A SOCKET FOR HTTP FOR WEB PAGE
UPLOAD AND DOWNLOAD.
AIM:
To write a java program for socket for HTTP for web page upload and
download.
ALGORITHM
1. Start the program.
2. Get the frame size from the user
3. To create the frame based on the user request.
4. To send frames to server from the client side.
5. If your frames reach the server it will send ACK signal to client
otherwise it will send NACK signal to client.
6. Stop the program
PROGRAM
/*http Server*/
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);
}}

/*httpClient*/
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("Desert.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(); } }
OUTPUT:

SERVER:

C:\Java\jdk1.8.0_77\bin>javac Server.java

C:\Java\jdk1.8.0_77\bin>java Server

Server Waiting for image

Client connected.

Image Size: 120KB

CLIENT:

C:\Java\jdk1.8.0_77\bin>javac Client.java

C:\Java\jdk1.8.0_77\bin>java Client
Client is running.

Reading image from disk.

Sending image to server.

Image sent to server.

RESULT
Thus the program was implementing to socket for HTTP for web page
upload and download.
Ex.no.3a APPLICATIONS USING TCP SOCKETS

ECHO CLIENT AND ECHO SERVER


AIM
To write a java program for application using TCP Sockets Links

ALGORITHM
1.Start the program.
2.Get the frame size from the user
3.To create the framebased on the user request.
4.To send frames to server from the client side.
5.If your frames reach the server it will send ACK signal to client otherwise it
will send NACK signal to client.
6.Stop the program
PROGRAM

/*EchoServer*/

import java.io.*;
import java.net.*;
public class EchoServer
{
public EchoServer(int portnum)
{
try
{
server = new ServerSocket(portnum);
}
catch (Exception err)
{
System.out.println(err);
}
}
public void serve()
{
try
{
while (true)
{
Socket client = server.accept();
BufferedReader r = new BufferedReader(new
InputStreamReader(client.getInputStream()));
PrintWriter w = new PrintWriter(client.getOutputStream(), true);
w.println("Welcome to the Java EchoServer. Type 'bye' to close.");
String line;
do
{
line = r.readLine();
if ( line != null )
w.println("Got: "+ line);
}
while ( !line.trim().equals("bye") );
client.close();
}
}
catch (Exception err)
{
System.err.println(err);
}
}
public static void main(String[] args)
{
EchoServer s = new EchoServer(9999);
s.serve();
}
private ServerSocket server;
}

/*EchoClient*/
import java.io.*;
import java.net.*;
public class EchoClient
{
public static void main(String[] args)
{
try
{
Socket s = new Socket("127.0.0.1", 9999);
BufferedReader r = new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintWriter w = new PrintWriter(s.getOutputStream(), true);
BufferedReader con = new BufferedReader(new
InputStreamReader(System.in));
String line;
do
{
line = r.readLine();
if ( line != null )
System.out.println(line);
line = con.readLine();
w.println(line);
}
while ( !line.trim().equals("bye") );
}
catch (Exception err)
{
System.err.println(err);
}}}

OUTPUT:

SERVER:

C:\Java\jdk1.8.0_77\bin>javac EchoServer.java

C:\Java\jdk1.8.0_77\bin>java EchoServer

CLIENT:
C:\Java\jdk1.8.0_77\bin>javac EchoClient.java

C:\Java\jdk1.8.0_77\bin>java EchoClient

Welcome to the Java EchoServer. Type 'bye' to close.

hai

Got: hai

how are you

Got: how are you

bye

RESULT:

Thus, the java program on ECHO CLIENT AND SERVER USING UDP
Sockets is well executed.
Ex.no.3b APPLICATIONS USING TCP SOCKETS

CHAT
AIM
To write a java program for application using TCP Sockets Links
ALGORITHM
1.Start the program.
2.Get the frame size from the user
3.To create the framebased on the user request.
4.To send frames to server from the client side.
5.If your frames reach the server it will send ACK signal to client otherwise it
will send NACK signal to client.
6.Stop the program.

PROGRAM

/*chatTCPserver*/
import java.io.*;
import java.net.*;
class TCPserver
{
public static DatagramSocket ds;
public static byte buffer[]=new byte[1024];
public static int clientport=789,serverport=790;
public static void main(String args[])throws Exception
{
ds=new DatagramSocket(clientport);
System.out.println("press ctrl+c to quit the program");
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
InetAddress ia=InetAddress.getLocalHost();
while(true)
{
DatagramPacket p=new DatagramPacket(buffer,buffer.length);
ds.receive(p);
String psx=new String(p.getData(),0,p.getLength());
System.out.println("Client:" + psx);
System.out.println("Server:");
String str=dis.readLine();
if(str.equals("end"))
break;
buffer=str.getBytes();
ds.send(new
DatagramPacket(buffer,str.length(),ia,serverport));
} }}

/*chat TCPClient*/
import java .io.*;
import java.net.*;
class TCPclient
{
public static DatagramSocket ds;
public static int clientport=789,serverport=790;
public static void main(String args[])throws Exception
{
byte buffer[]=new byte[1024];
ds=new DatagramSocket(serverport);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
System.out.println("server waiting");
InetAddress ia=InetAddress.getLocalHost();
while(true)
{
System.out.println("Client:");
String str=dis.readLine();
if(str.equals("end"))
break;
buffer=str.getBytes();
ds.send(new DatagramPacket(buffer,str.length(),ia,clientport));
DatagramPacket p=new DatagramPacket(buffer,buffer.length);
ds.receive(p);
String psx=new String(p.getData(),0,p.getLength());
System.out.println("Server:" + psx);
}}}

OUTPUT:
SERVER SIDE:
C:\Java\jdk1.8.0_77\bin>javac TCPserver.java
C:\Java\jdk1.8.0_77\bin>java TCPserver
press ctrl+c to quit the program
Client:hai
Server:
how are you
Client:how are u
Server:
fine thanks
Client:fine thanks
Server:
end
C:\Java\jdk1.8.0_77\bin>
CLIENT SIDE:
C:\Java\jdk1.8.0_77\bin>javac TCPclient.java
C:\Java\jdk1.8.0_77\bin>java TCPclient
server waiting
Client:
hai
Server:how
Client:
how are u
Server:fine than
Client:
fine thanks

RESULT:

Thus, the java program on CHAT CLIENT AND SERVER USING UDP
Sockets is well executed.
Ex.no.3c APPLICATIONS USING TCP SOCKETS

FILE TRANSFER
AIM
To write a java program for application using TCP Sockets Links
ALGORITHM
1.Start the program.
2.Get the frame size from the user
3.To create the framebased on the user request.
4.To send frames to server from the client side.
5.If your frames reach the server it will send ACK signal to client otherwise it
will send NACK signal to client.
6.Stop the program.

PROGRAM

/*ftpserver*/
import java.io.*;
import java.net.*;
class ftpserver
{
public static void main(String args[])throws IOException
{
char ch[] = new char[35];
String str;
int i=0,j;
ServerSocket ss = new ServerSocket(5600);
Socket s = ss.accept();
BufferedReader in = new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
String fname = in.readLine();
FileInputStream fin = new FileInputStream(fname);
while(true)
{
for(i=0;i<30;i++)
{
j=fin.read();
ch[i]=(char)j;
if(j==-1)
break;
}
str = new String(ch,0,i);
out.println(str);
if(i!=30)
break;
}
out.println("EOF");
in.close();
out.close();
s.close();
ss.close();
}
}
/*ftpclient*/
import java.io.*; import java.net.*;
class ftpclient
{
public static void main(String args[])throws Exception
{
BufferedReader in1 = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the hostname to connect:");
Socket s = new Socket(InetAddress.getByName(in1.readLine()),5600);
BufferedReader in2 = new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
System.out.println("Enter the source filename:");
out.println(in1.readLine());
System.out.println("Enter the destination filename:");
FileOutputStream fout = new FileOutputStream(in1.readLine());
String data; int i=0;
while(true)
{
data = in2.readLine();
if(data.equals("EOF"))
break; char ch[] = new char[35];
data.getChars(0,data.length(),ch,0);
for(i=0;i<data.length();i++)
fout.write((int)ch[i]);
}
in1.close(); in2.close(); out.close(); s.close();
fout.close();
}}
OUTPUT:

SERVER SIDE:
C:\Java\jdk1.8.0_77\bin>javac ftpserver.java
C:\Java\jdk1.8.0_77\bin>java ftpserver
CLIENT SIDE:
C:\Java\jdk1.8.0_77\bin>javac ftpclient.java
C:\Java\jdk1.8.0_77\bin>java ftpclient
Enter the hostname to connect:
localhost
Enter the source filename:
ex.txt
Enter the destination filename:
ex1.txt
C:\Java\jdk1.8.0_77\

RESULT:

Thus, the java program on FILE TRANSFER CLIENT AND SERVER


USING UDP Sockets is well executed.
Ex.no.4 SIMULATION OF DNS USING UDP SOCKETS.

AIM
To write a java program for DNS using UDP Sockets

ALGORITHM

1.Start the program.


2.Get the frame size from the user
3.To create the frame based on the user request.
4.To send frames to server from the client side.
5.If your frames reach the server it will send ACK signal to client otherwise it
will send NACK signal to client.
6.Stop the program

PROGRAM

Udpdnsserver
import.java import java.io.*;

import java.net.*;

public class udpdnsserver


{
private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str)) return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"};
String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140",
"69.63.189.16"}; System.out.println("Press Ctrl + C to Quit");
while (true)
{
DatagramSocket serversocket=new DatagramSocket(1362);
byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];
DatagramPacket recvpack = new DatagramPacket
(receivedata, receivedata.length);
serversocket.receive(recvpack);
String sen = new String(recvpack.getData());
InetAddress ipaddress = recvpack.getAddress();
int port = recvpack.getPort();
String capsent;
System.out.println("Request for host " + sen);
if(indexOf (hosts, sen) != -1)
capsent = ip[indexOf (hosts, sen)];
else capsent = "Host Not Found";
senddata = capsent.getBytes();
DatagramPacket pack = new DatagramPacket
(senddata, senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
}
}
}
//UDP DNS Client
Udpdnsclient
.java import java.io.*;
import java.net.*;
public class udpdnsclient
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientsocket = new DatagramSocket();
InetAddress ipaddress;
if (args.length == 0)
ipaddress = InetAddress.getLocalHost();
else
ipaddress = InetAddress.getByName(args[0]);
byte[] senddata = new byte[1024];
byte[] receivedata = new byte[1024];
int portaddr = 1362;
System.out.print("Enter the hostname : ");
String sentence = br.readLine();
Senddata = sentence.getBytes();
DatagramPacket pack = new DatagramPacket(senddata,senddata.length,
ipaddress,portaddr);
clientsocket.send(pack);
DatagramPacket recvpack =new
DatagramPacket(receivedata,receivedata.length);
clientsocket.receive(recvpack);
String modified = new String(recvpack.getData());
System.out.println("IP Address: " + modified);
clientsocket.close();
}
}
OUTPUT
Server
$ javac udpdnsserver.java
$ java udpdnsserver Press Ctrl + C to Quit Request for host yahoo.com Request
for host cricinfo.com Request for host youtube.com
Client
$ javac udpdnsclient.java
$ java udpdnsclient Enter the hostname : yahoo.com IP Address:
68.180.206.184 $ java udpdnsclient Enter the hostname : cricinfo.com IP
Address: 80.168.92.140 $ java udpdnsclient Enter the hostname : youtube.com
IP Address: Host Not Found

RESULT:

Thus, the java program for DNS using UDP Socket is well executed.
Ex.no.5a Write a code simulating ARP /RARP protocols
Aim:
To write a java program for simulating arp/rarp protocols
ALGORITHM:
server
1. Create a server socket and bind it to port.
2. Listen for new connection and when a connection arrives, accept it.
3. Send server‟s date and time to the client.
4. Read client‟s IP address sent by the client.
5. Display the client details.
6. Repeat steps 2-5 until the server is terminated.
7. Close all streams.
8. Close the server socket.

Client
1. Create a client socket and connect it to the server‟s port number.
2. Retrieve its own IP address using built-in function.
3. Send its address to the server.
4. Display the date & time sent by the server.
5. Close the input and output streams.
6. Close the client socket.
7. Stop.
PROGRAM

/*ServerARP*/

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);
}
}}
/* ClientARP*/
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);
}}}
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

5b. RARP protocols


/*ServeRARP*/
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket server=new DatagramSocket(1309);
while(true)
{
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new String(receiver.getData());
String s=str.trim();
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
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(s.equals(mac[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket
sender=newDatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}}}

/*ClientRARP*/

import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Physical address (MAC):")
String str=in.readLine(); sendbyte=str.getBytes();
DatagramPacket
sender=newDatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Logical Address is(IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
I:\ex>java Serverrarp12
I:\ex>java Clientrarp12
Enter the Physical address
(MAC): 6A:08:AA:C2
The Logical Address is(IP): 165.165.80.80

RESULT:
Thus the program for implementing to display simulating ARP /RARP
protocols.
Ex.no.6 STUDY OF NETWORK SIMULATOR
(NS).AND SIMULATION OF
CONGESTION CONTROL ALGORITHMS
USING NS
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 overview
 Ns Status
 Periodical release (ns-2.26, Feb 2003)
 Platform support
 FreeBSD, Linux, Solaris, Windows and Mac
Ns unctionalities
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 beextremely 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 LocalArea 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 more packets of data travelling across a computer network
fail to reach their 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 transport layer 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. In
communication networks, such as Ethernet or packet radio, throughput or
network throughput is the average rate of successful message delivery over a
communication channel. The throughput is usually measured in bits per second
(bit/s or bps), and sometimes in data packets per second or data packets per time
slot This 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 value of delay, the more difficult it is for transport layer protocols to
maintain high bandwidths. 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 the
system 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 study of Network simulator (NS2) was studied.
Ex.no.7 STUDY OF TCP/UDP PERFORMANCE USING
SIMULATION TOOL.
AIM:
To Study of tcp/udp performance using simulation tool.

Transmission Control Protocol


A basic strategy for communication among dissimilar networks called as TCP.
The evolution that followed provides a reliable and ordered delivery of a data
among the communicating nodes. Internet protocol suite comprises two core
protocols viz. TCP and IP and commonly referred to as TCP/IP. In the event of
data transmission between two computers, TCP, staying between an application
program and the Internet protocol, provides reliable and ordered delivery of a
stream of bytes from a program on one computer to another program on another
computer .That is, when an application program desires to send a large chunk of
data across the internet using IP, instead of breaking the data into IP-sized
pieces and issuing a series of IP requests, the software can issue a single request
to TCP and let TCP to handle the IP details. TCP is a byte-stream protocol as its
flow control and acknowledgement are based on byte number rather than packet
number. However, the smallest unit of data transmitted over the internet is a
data segment or packet and each packet is identified by a data octet number.
When a destination receives a data segment, it acknowledges the receipt of the
segment by issuing an ACK with the next expected data octet number. The time
elapsed between moment a data segment is sent and the moment an ACK for
that segment is received is known as the RTT of the communication between
the source and the destination, which is the sum of the propagation,
transmission, queuing, and processing delays at each hop of the communication,
along with the time taken to process a received segment and generate an ACK
for the segment at the destination. The flow control mechanism used by TCP is
a credit allocation scheme. To avoid overwhelming its buffer space, a
destination advertises to the associated source the size of a window, called as
advertised window,61 which indicates the number of data bytes, beyond the
acknowledged data, the source can send to the destination. This information is
included in the header of each TCP (data or control) segment sent to the source.
Suppose that based on the ACKs received, a source knows that ‘Byte ’ is the
last data byte received by the destination. The source can send data up to Byte
+ , where W is the size of the advertised window. The scenario of the source’s
sequence number space is exhibited in

Congestion Control Operations of TCP


To achieve good performance, it is necessary to control network congestion so
that the number of packets lost within the internet is well below the level at
which the network performance drops significantly. Various congestion control
measures have been implemented in TCP to limit the sending rate of data
entering the internet by regulating the size of the congestion window cwnd, and
the number of unacknowledged segments permitted over the link. These
measures include slow start, congestion avoidance, fast retransmit, and fast
recovery. When a new connection is established, TCP initializes the cwnd size
to 1. In slow start, the value of cwnd is incremented by one each time an ACK
is received
until it reaches the slow start threshold, ssthresh.
TCP uses segment loss as an indicator of network congestion. To characterize a
segment as being lost in transit, a source has to wait long enough without
receiving an ACK for the segment. Therefore, a retransmission timer is
associated with each transmitted segment and a timer timeout signals a segment
loss. The Retransmission Timeout Period (RTO) is determined by the sum of
the smoothed exponentially weighted moving average and a multiple of the
mean deviation of RTT When a timeout occurs, ssthresh is set to half of the
amount of outstanding data sent to the network. The slow start process is
performed starting with cwnd set to one and changes the size of it using AIMD
technique, until it reaches ssthresh. The congestion avoidance phase is then
carried out where cwnd is increased by one for each RTT. When the data octet
number of an arriving segment is greater than the expected one, the destination
finds it as a sequence hole, i.e. a gap in the sequence number space. Then the
receiver immediately sends out a duplicate ACK, i.e., an ACK with the next
expected data octet number in the cumulative acknowledgement field, to the
source, instead of the ACK for the segment received with sequence hole. If the
communication channel is an in-order channel, the reception of a duplicate
ACK implies the loss of a segment. When the source receives three duplicate
ACKs, fast retransmit is triggered such that the inferred loss segment is
retransmitted before the expiration of the retransmission timeout. Fast recovery
works as a companion of fast retransmit. A fast retransmission suggests the
presence of mild network congestion. To handle this, ssthresh is set to half of
the amount of outstanding data sent to the network. Since the reception of a
duplicate ACK indicates the departure of a segment from the network, cwnd is
set to the sum of ssthresh and the number 63 of duplicate ACKs received. When
an ACK for a new segment arrives, cwnd is reset to ssthresh and then
congestion avoidance takes place. Packet reordering refers to the network
behavior where the relative order of some packets in the same flow is altered
when these packets are transported in the network. In other words, the receiving
order of a flow of packets or segments differs from its sending order. The
presence of persistent and substantial packet reordering violates the in-order or
near in-order channel assumption made in the design principles of some traffic
control mechanisms in TCP. This can result in a substantial degradation in
application throughput and network performance .
Modern TCP implementations also include congestion control mechanisms that
adapt the source transmission behaviour to network conditions by dynamically
computing the congestion window size. The goal of TCP congestion control is
to increase the congestion window size, if there is additional bandwidth
available on the network, and decrease the congestion window size upon
congestion. It is widely agreed that the congestion control
schemes in TCP provide stability for the “best effort” internet. These
mechanisms increase network utilization, prevent starvation of flows, and
ensure inter-protocol fairness .With TCP as the benchmark, a transport
mechanism in WSN should have basic functionalities such as reliable transport
of data, better congestion control means, reasonable rate-control and acceptable
fairness
User Datagram Protocol
The UDP is another protocol with TCP/IP suit which can send messages, or
datagrams in this protocol, to other nodes on IP network without 64 requiring
prior communications to set up special transmission channels or data paths.
UDP does not guarantee reliability or ordering in the way that TCP does.
Datagrams may arrive out of order, appear duplicated, or go missing
without notice. Avoiding the overhead of checking whether every packet
actually arrived makes UDP faster and more efficient, at least for applications
that do not need guaranteed delivery. Time-sensitive applications often use
UDP because dropped packets are preferable to delayed packets. UDP's
stateless nature is also useful for servers that answer small queries from huge
numbers of clients. Unlike TCP, UDP supports packet broadcast i.e. sending
to all on local network and multicasting i.e. send to all subscribers. UDP
assumes that error checking and correction is either not necessary or performed
in the application, thus avoiding the overhead of such processing at the network
interface level. Due to this, the arrival of datagrams may not be in the same
order in which they were transmitted and some of the
transmitted datagrams may not reach the receiver and hence, lost during
transmission. The QoS is further deteriorated by data duplication and data loss.
UDP is more appropriate for applications where time is precious than data loss
and hence, seldom suitable for real-time applications

RESULT
Thus the study of tcp/udp performance using simulation tool was studied.
Ex.no.8a DISTANCE VECTOR

Aim

To write a distance vector routing algorithm using ns2 simulator.

PROGRAM

set ns [new Simulator]

set nf [open out.nam w]


$ns namtrace-all $nf

set tr [open out.tr w]


$ns trace-all $tr

proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n1 10Mb 10ms DropTail


$ns duplex-link $n1 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n1 10Mb 10ms DropTail

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


$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n2 $n1 orient right-up

set tcp [new Agent/TCP]


$ns attach-agent $n0 $tcp

set ftp [new Application/FTP]


$ftp attach-agent $tcp

set sink [new Agent/TCPSink]


$ns attach-agent $n3 $sink

set udp [new Agent/UDP]


$ns attach-agent $n2 $udp
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp

set null [new Agent/Null]


$ns attach-agent $n3 $null

$ns connect $tcp $sink


$ns connect $udp $null

$ns rtmodel-at 1.0 down $n1 $n3


$ns rtmodel-at 2.0 up $n1 $n3

$ns rtproto DV

$ns at 0.0 "$ftp start"


$ns at 0.0 "$cbr start"

$ns at 5.0 "finish"

$ns run

RESULT
Thus the distance vector rounting algorithm was executed
successfully.
Ex.no.8b LINK STATE ROUTING ALGORITHM.

Aim

To write a link state routing algorithm using ns2 simulator.

PROGRAM

ns [new Simulator]

set nf [open out.nam w]


$ns namtrace-all $nf

set tr [open out.tr w]


$ns trace-all $tr

proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n1 10Mb 10ms DropTail


$ns duplex-link $n1 $n3 10Mb 10ms DropTail
$ns duplex-link $n2 $n1 10Mb 10ms DropTail

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


$ns duplex-link-op $n1 $n3 orient right
$ns duplex-link-op $n2 $n1 orient right-up

set tcp [new Agent/TCP]


$ns attach-agent $n0 $tcp

set ftp [new Application/FTP]


$ftp attach-agent $tcp

set sink [new Agent/TCPSink]


$ns attach-agent $n3 $sink

set udp [new Agent/UDP]


$ns attach-agent $n2 $udp

set cbr [new Application/Traffic/CBR]


$cbr attach-agent $udp

set null [new Agent/Null]


$ns attach-agent $n3 $null

$ns connect $tcp $sink


$ns connect $udp $null

$ns rtmodel-at 1.0 down $n1 $n3


$ns rtmodel-at 2.0 up $n1 $n3

$ns rtproto LS

$ns at 0.0 "$ftp start"


$ns at 0.0 "$cbr start"

$ns at 5.0 "finish"

$ns run

RESULT
Thus the link state rounting algorithm was executed successfully.
Ex.no.9 PERFORMANCE EVALUATION OF ROUTING PROTOCOLS
USING SIMULATION TOOL
AIM:
To Study of performance evaluation of routing protocols using simulation tool
VANET ROUTING PROTOCOLS
There are many routing protocols available for VANET. Among them all we are
working with AODV and DSR for performance analysis.
A.Ad-hoc On demand Distance Vector (AODV)
It is purely On-Demand route acquisition routing protocol. It is better
protocol than DSDV network as the size of network may increase depending
on the number of vehicle nodes.
1) Path Discovery Process: In order to discover the path between source
and destination, a route request message (RREQ) is broadcasted to all the
neighbours in radio range who again continue to send the same to their
neighbours in there radio range, until the destination is reached. Every node
maintains two counters: sequence number and broadcast-id in order to maintain
loop-free and most recent route information. The broadcast-id is incremented
for every RREQ the source node initiates. If an intermediate node receives the
same copy of request, it discards it without routing it further. When a node
forwards the RREQ message, it records the address of the neighbour from
which it received the first copy of the broadcast packet, in order to maintain a
reverse path to the source node. The RREQ packet contains: the source
sequence number and the last destination sequence number know to the source.
The source sequence number is used to maintain information about reverse
route and destination sequence number tells about the actual distance to the final
node.
2) Route Maintenance: A source node sends a new moving request packet
RREQ to find a new route to the destination. But, if an intermediate node moves
from its place, its upstream neighbor noticed the move and sends a message
notification failure of the link to each of its active upstream neighbors to inform
them about the move to source nodes is achieved. After the detection process is
again initiated.
B. Dynamic Source Routing (DSR)
It is an On-Demand routing protocol in which the sequence of nodes
through which a packet needs to travel is calculated and maintained as an
information in packet header. Every mobile node in the network needs to
maintain a route cache where it caches source routes that it has learned. When a
packet is sent, the route-cache inside the node is compared with the actual route
needs to be covered.
1) Route Discovery: The source node broadcasts request-packets to all the
neighbours in the network containing the address of the destination node, and a
reply is sent back to the source node with the list of network-nodes through
which it should propagate in the process. Sender initiates the route record as a
list with a single element containing itself followed by the linking of its
neighbour in that route. A request packet also contains an identification number
called request-id, which is counter increased only when a new route request
packet is being sent by the source node. To make sure that no loops occur
during broadcast, the request is processed in the given order. A route reply is
obtained in DSR by two ways: Symmetric-links (bidirectional), in which the
backward route is followed again to catch the source node. Asymmetric-links
(unidirectional) needs to discover the route up to the source node in the same
manner as the forward route is discovered.
2) Route Maintenance: In the hop by hop acknowledgement at data link
layer allows the early detection and retransmission of lost or corrupt packets in
the data-link layer. If a transmission error occurs, a route error packet
containing the address of node detecting the error and the host address is sent
back to the sender. Whenever a node receives a route error packet, the hop in
error is removed from the route cache and all routes containing this hop are
truncated at that point. When the wireless transmission between two nodes
does not work equally well in both directions, and then end-to-end replies on
the application or transport layer may be used to indicate the status of the route
from one host to the other

RESULT
Thus Study of performance evaluation of routing protocols using
simulation tool was studied.
Ex.no.10 ERROR CORRECTION CODE (LIKE CRC).

AIM
To write a java program for CRC using java.

ALGORITHM

1.Start the program.


2.Get the frame size from the user
3.To create the frame based on the user request.
4.To send frames to server from the client side.
5.If your frames reach the server it will send ACK signal to client otherwise it
will send NACK signal to client.
6.Stop the program
PROGRAM

import java.util.Scanner;
class CRC
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int m,g[],n,d[],z[],r[],msb,i,j,k;
System.out.print(“Enter no. of data bits : “);
n=sc.nextInt();
System.out.print(“Enter no. of generator bits : “);
m=sc.nextInt();
d=new int[n+m];
g=new int[m];
System.out.print(“Enter data bits : “);
for(i=0;i<n;i++)
d[i]=sc.nextInt();
System.out.print(“Enter generator bits : “);
for(j=0;j<m;j++)
g[j]=sc.nextInt();
for(i=0;i<m-1;i++)
d[n+i]=0;
r=new int[m+n];
for(i=0;i<m;i++)
r[i]=d[i];
z=new int[m];
for(i=0;i<m;i++)
z[i]=0;
for(i=0;i<n;i++)
{
k=0;
msb=r[i];
for(j=i;j<m+i;j++)
{
if(msb==0)
r[j]=xor(r[j],z[k]);
else
r[j]=xor(r[j],g[k]);
k++;
}
r[m+i]=d[m+i];
}
System.out.print(“The code bits added are : “);
for(i=n;i<n+m-1;i++)
{
d[i]=r[i];
System.out.print(d[i]);
}
System.out.print(“\nThe code data is : “);
for(i=0;i<n+m-1;i++)
{
System.out.print(d[i]);
}
}
public static int xor(int x,int y)
{
if(x==y)
return(0);
else
return(1);
}
}

OUTPUT
Enter no. of data bits : 14
Enter no. of generator bits : 4
Enter data bits : 1
1
0
1
0
0
1
1
1
0
1
1
0
0

Enter generator bits :


1
0
1
1

The code bits added are : 100


The code data is : 11010011101100100

RESULT
Thus the cyclic redundancy check (error correction) algorithm was
executed successfully.

Das könnte Ihnen auch gefallen