0% found this document useful (0 votes)
12 views33 pages

CS8581 - Networks Lab Manual

The document outlines the practical records for the CS8581 - Networks Laboratory course at Surya College of Engineering. It includes various programming exercises such as simulating ping commands, traceroute, HTTP web client-server communication, TCP sockets echo client-server, and DNS using UDP sockets. Each exercise is accompanied by code snippets and expected outputs, demonstrating practical applications of networking concepts.

Uploaded by

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

CS8581 - Networks Lab Manual

The document outlines the practical records for the CS8581 - Networks Laboratory course at Surya College of Engineering. It includes various programming exercises such as simulating ping commands, traceroute, HTTP web client-server communication, TCP sockets echo client-server, and DNS using UDP sockets. Each exercise is accompanied by code snippets and expected outputs, demonstrating practical applications of networking concepts.

Uploaded by

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

SURYA COLLEGE OF ENGINEERING

KONALAI, TRICHIRAPALLI - 621 132

DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING

REGISTER NO. :

NAME :

YEAR & DEPT. :

V SEMESTER

CS8581 – NETWORKS LABORATORY


SURYA COLLEGE OF ENGINEERING
KONALAI, TRICHIRAPALLI - 621 132

BONAFIDE CERTIFICATE

Certified that this is the bonafide record of Practical done in


CS8581-NETWORKS LABORATORY by____________________________________
SPR.NO. in V Semester during 2022 – 2023.

REGISTER NUMBER

Date:

STAFF IN-CHARGE HOD

INTERNAL EXAMINER EXTERNAL EXAMINER


INDEX

PAGE STAFF
S.NO DATE NAME OF THE PROGRAM
NO. SIGN
EX.NO.1(A) CODE SIMULATING PING COMMAND
DATE:
PROGRAM:
import java.io.*;
import java.net.*;
class pingserver
{
public static void main(String args[])
{
try
{
String str;
System.out.print(" Enter the IP Address to be Ping : ");
BufferedReader buf1=new BufferedReader(new
InputStreamReader(System.in));
String ip=buf1.readLine();
Runtime H=Runtime.getRuntime();
Process p=H.exec("ping " + ip);
I`nputStream in=p.getInputStream();
BufferedReader buf2=new BufferedReader(new
InputStreamReader(in));
while((str=buf2.readLine())!=null)
{
System.out.println(" " + str);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
Output:
Enter the IP address to the ping:192.168.0.1
Pinging 192.168.0.1: with bytes of data =32
Reply from 192.168.0.11:bytes=32 time<1ms TTL =128
Reply from 192.168.0.11:bytes=32 time<1ms TTL =128
Reply from 192.168.0.11:bytes=32 time<1ms TTL =128
Reply from 192.168.0.11:bytes=32 time<1ms TTL =128
Ping statistics for 192.168.0.1
Packets: sent=4,received=4,lost=0(0% loss),approximate round trip time in milli seconds:
Minimum=1ms,maximum=4ms,average=2ms.
EX.NO.1(B) TRACE ROUTE

DATE:

PROGRAM:
import java.io.*;
import java.net.*;
import java.lang.*;
class Traceroute
{
public static void main(String args[]){
BufferedReader in;
try{
Runtime r = Runtime.getRuntime();
Process p = r.exec("tracert www.google.com");
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
if(p==null)
System.out.println("could not connect");
while((line=in.readLine())!=null){
System.out.println(line);
//in.close();
}
}
catch(IOException e)
{
System.out.println(e.toString());
}
}
}

Output :

Tracing route to www.google.com [74.125.28.106]


over a maximum of 30 hops:
1 70 ms 55 ms 70 ms 10.228.129.13
2 87 ms 84 ms 10.228.149.14
3 82 ms 85 ms 116.202.226.145
4 95 ms 94 ms 136 ms 10.228.158.82
5 Request timed out.
6 53 ms 55 ms 59 ms 116.202.226.21
7 85 ms 74 ms 82 ms 72.14.205.145
8 76 ms 75 ms 71 ms 72.14.235.69
9 124 ms 114 ms 113 ms 216.239.63.213
10 181 ms 194 ms 159 ms 66.249.95.132
11 285 ms 247 ms 246 ms 209.85.142.51
12 288 ms 282 ms 283 ms 72.14.233.138
13 271 ms 283 ms 274 ms 64.233.174.97
14 Request timed out.
15 269 ms 273 ms 283 ms pc-in-f106.1e100.net [74.125.28.106]
Trace complete.
EX.NO 2: A HTTP WEB CLIENT PROGRAM TO DOWNLOAD A WEB PAGE USING TCP SOCKETS
DATE:
PROGRAM :
CLIENT
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
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
When you run the client code, following output screen would appear on client side
EX.NO: 3(A) TCP SOCKETS ECHO CLIENT AND ECHO SERVER
DATE:
PROGRAM:
ECHOSERVER.JAVA
import java.net.*;
import java.io.*;
public class EServer
{
public static void main(String args[])
{
ServerSocket s=null;
String line;
DataInputStream is;
PrintStream ps;
Socket c=null;
try
{
s=new ServerSocket(9000);
}
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();
ps.println(line);
}
}
catch(IOException e)
{
System.out.println(e);
}
}
}
EClient.java
import java.net.*;
import java.io.*;
public class EClient
{
public static void main(String arg[])
{
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os;
try
{
InetAddress ia = InetAddress.getLocalHost();
c=new Socket(ia,9000);
}
catch(IOException e)
{
System.out.println(e);
}
try
{
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in);
is1=new DataInputStream(c.getInputStream());
while(true)
{
System.out.println("Client:");
line=is.readLine();
os.println(line);
System.out.println("Server:" + is1.readLine());
}}
catch(IOException e)
{
System.out.println("Socket Closed!");
}
}
}
Output
Server
C:\Program Files\Java\jdk1.5.0\bin>javac EServer.java
Note: EServer.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin>java EServer
C:\Program Files\Java\jdk1.5.0\bin>
Client
C:\Program Files\Java\jdk1.5.0\bin>javac EClient.java
Note: EClient.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin>java EClient
Client:
Hai Server
Server:Hai Server
Client:
Hello
Server:Hello
Client:
end
Server:end
Client:
ds
Socket Closed!
EX.NO:3(B) CLIENT - SERVER CHAT USING TCP SOCKET
DATE:
PROGRAM:
TCPserver.java
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.geyLocalHost();
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));
}
}
}
TCPclient.java
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
C:\Program Files\Java\jdk1.5.0\bin>javac TCPserver.java
C:\Program Files\Java\jdk1.5.0\bin>java TCPserver
press ctrl+c to quit the program
Client:Hai Server
Server:
Hello Client
Client:How are You
Server:
I am Fine
Client
C:\Program Files\Java\jdk1.5.0\bin>javac TCPclient.java
C:\Program Files\Java\jdk1.5.0\bin>java TCPclient
server waiting
Client:
Hai Server
Server:Hello Clie
Client:
How are You
Server:I am Fine
Client:
end
EX.NO:3(C) CLIENT - SERVER FILE TRANSFER USING SOCKET
DATE:
PROGRAM:
File Client
import java.io.*;
import java.net.*;
import java.util.*;
class Clientfile
{ 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 file name:");
String str=in.readLine();
dout.writeBytes(str+'\n');
System.out.println("Enter the new file name:");
String str2=in.readLine();
String str1,ss;
FileWriter f=new
FileWriter(str2); char buffer[];
while(true)
{ str1=din.readLine();
if(str1.equals("-1")) break;
System.out.println(str1);
buffer=new char[str1.length()];
str1.getChars(0,str1.length(),buffer,0);
f.write(buffer);
}
f.close();
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}

Server
import java.io.*;
import java.net.*;
import java.util.*;
class Serverfile
{
public static void main(String args[])
{
Try
{
ServerSocket obj=new ServerSocket(139);
while(true)
{
Socket obj1=obj.accept();
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
FileReader f=new FileReader(str);
BufferedReader b=new BufferedReader(f);
String s;
while((s=b.readLine())!=null)
{
System.out.println(s);
dout.writeBytes(s+'\n');
}f.close();
dout.writeBytes("-1\n");
}}
catch(Exception e)
{
System.out.println(e);
}}}
Output
File content
Computer networks
jhfcgsauf
jbsdava
jbvuesagv
client
Enter the file name:
sample.txt
server
Computer networks
jhfcgsauf
jbsdava
jbvuesagv
client
Enter the new file name:
net.txt
Computer networks
jhfcgsauf
jbsdava
jbvuesagv
Destination file
Computer networks
Jhfcgsauf
Jbsdava
EX.NO: 4 DNS USING UDP SOCKETS
DATE:
PROGRAM:
UDP DNS Server
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
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
EX.NO:5(A) CODE SIMULATING ARP PROTOCOLS.
DATE:
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
EX.NO:5(B) REVERSE ADDRESS RESOLUTION PROTOCOL(RARP)
DATE:
PROGRAM:
Client:
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);
}
}
}
Server:
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);
}
}
}
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
EX.NO: 6 STUDY OF NETWORK SIMULATOR (NS).AND SIMULATION OF CONGESTION
CONTROL ALGORITHMS USING NS
DATE:

AIM:

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

NET WORK SIMULATOR (NS2)

Wireless
Ad hoc routing, mobile IP, sensor-MACTracing, visualization and various utilitieNS(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 thatpacket 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 ofnotable 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 nodeslike computers, hubs,
bridges, routers, switches, links, mobile units etc.Various types of Wide Area Network (WAN) technologies like TCP, ATM,
IP etc. 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 thenodes.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

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. In communicationnetworks, such
asEthernetorpacket radio, throughputor network throughputs. 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.
EX. NO:7 STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL
DATE:

AIM:
To study TCP/IP model using simulation tools.

PROCEDURE:
TCP/IP means Transmission Control Protocol and Internet Protocol. It is the network model used in
the current Internet architecture as well. Protocols are set of rules which govern every possible communication
over a network. These protocols describe the movement of data between the source and destination or the
internet. These protocols offer simple naming and addressing schemes.

TCP/IP that is Transmission Control Protocol and Internet Protocol was developed by Department of
Defense’s Project Research Agency (ARPA, later DARPA) as a part of a research project of network
interconnection to connect remote machines. There are four layers in TCP/IP model Hostto-
Network layer
Internet layer
Transporlayer
Application layer
Network interface layer

Internet layer:
The Internet Layer exists for routing and providing a single network interface to the upper layers. IP
provides the single network interface for the upper layers.

Protocols at the Internet Layer are:

The Internet Protocol (IP) is a protocol that contains addressing information and some control
information that enables packets to be routed. IP has two primary responsibilities: providing connectionless,
best-effort delivery of datagrams through an internetwork; and providing fragmentation and reassembly of
datagrams to support data links.All machines on a TCP/IP network have a unique logical address, an IP
address. The Internet Layer (IP) has a complete picture of the entire network and is responsible for path
determination and packet switching.

ICMP(Internet control message protocol)

ICMPs generate several kinds of useful messages, including Destination Unreachable, Echo Request
and Reply, Redirect, Time Exceeded, and Router Advertisement and Router Solicitation. If an ICMP message
cannot be delivered, no second one is generated. This is to avoid an endless flood of ICMP messages.
When an ICMP destination-unreachable message is sent by a router, it means that the router is unable
to send the package to its final destination. The router then discards the original packet. Destination-
unreachable messages include four basic types: network unreachable, host unreachable, protocol unreachable,
and port unreachable.

ARP (Address Resolution Protocol)


Used to find the MAC address from the known IP address. ARP sends a broadcast asking for the
machine with the specified IP address to respond with its MAC address. If two devices want to communicate,
the first device can send a broadcast ARP message requesting the physical address for a specified IP address.
The receiving device responds with its IP address and the first device maintains the entry in its ARP
cache. If a device doesn't exist on the same subnet, the sending device addresses the the default gateway's
physical address and sends the packet to the default gateway.

RARP (Reverse Address Resolution Protocol)


This protocol is used to find an IP address when the MAC address is known. A machine sends a
broadcast with its MAC address and requests its IP address. An example of a device that uses RARP is a
diskless workstation. Since it can't store its logical network address, it sends its MAC address to a RARP server
to requests its IP address. A RARP server responds to the RARP request with the device's IP address.

Transport layer:
It is designed to allow peer entities on the source and destination hosts to carry on a conversation. Two
protocols are defined here TCP and UDP.

Transmission Control Protocol (TCP)


Transmission Control Protocol (TCP) is a required TCP/IP standard defined in RFC 793,
"Transmission Control Protocol (TCP)," that provides a reliable, connection-oriented packet delivery service.
The Transmission Control Protocol:
Guarantees delivery of IP datagrams.
 Performs segmentation and reassembly of large blocks of data sent by programs.
 Ensures proper sequencing and ordered delivery of segmented data.
 Performs checks on the integrity of transmitted data by using checksum calculations.
 Sends positive messages depending on whether data was received successfully.
 By using selective acknowledgments, negative acknowledgments for data not received are also sent.
 Offers a preferred method of transport for programs that must use reliable session-based data transmission,
such as client/server database and e-mail programs.

User Datagram Protocol (UDP)


UDP is a TCP/IP standard defined in RFC 768, "User Datagram Protocol (UDP)." UDP is used by
some programs instead of TCP for fast, lightweight, unreliable transportation of data between TCP/IP hosts.
UDP provides a connectionless datagram service that offers best-effort delivery, which means that UDP does
not guarantee delivery or verify sequencing for any datagrams. A source host that needs reliable
communication must use either TCP or a program that provides its own sequencing and acknowledgment
services.

Application Layer

Application layer is the top most layer of four layer TCP/IP model. Application layer defines TCP/IP application
protocols and how host programs interface with Transport layer services to use the network.
Application layer includes all the higher-level protocols like DNS (Domain Naming System), HTTP (Hypertext
Transfer Protocol), Telnet, SSH, FTP (File Transfer Protocol), TFTP (Trivial File Transfer Protocol), SNMP
(Simple Network Management Protocol), SMTP (Simple Mail Transfer Protocol) , DHCP (Dynamic Host
Configuration Protocol).
Layer Description Protocols

Application Defines TCP/IP application protocols and how host HTTP, Telnet, FTP,
programs interface with transport layer services to use the TFTP, SNMP, DNS,
network. SMTP,
X Windows,
other application
protocols

Transport Provides communication session management between host TCP, UDP, RTP
computers. Defines the level of service and status of the
connection used when transporting data.

Internet Packages data into IP datagrams, which contain source and IP, ICMP, ARP, RARP
destination address information that is used to forward the
datagrams between hosts and across networks. Performs
routing of IP datagrams.

Network Specifies details of how data is physically sent through the Ethernet, Token Ring,
interface network, including how bits are electrically signaled by FDDI, X.25, Frame Relay,
hardware
devices that interface directly with a network medium, RS-232, v.35
such as coaxial cable, optical fiber, or twisted-pair
copper wire.
EX.NO:8 DISTANCE VECTOR ROUTING
DATE:
PROGRAM:
#include<stdio.h>
#define MAX 10
struct dist_vect
{
int dist[MAX];
int from[MAX];
};
int main()
{
int adj[MAX][MAX],n,i,j,hop[10][10]={{0}},k,count;
struct dist_vect arr[10];
printf("enter the number of nodes\n");
scanf("%d",&n);
printf("enter adjacency matrix\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++);
scanf("%d",&adj[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
arr[i].dist[j]=adj[i][j];
arr[i].from[j]=j;
}
}
count=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
if(arr[i].dist[j]>adj[i][k]+arr[k].dist[j])
{
arr[i].dist[j]=adj[i][k]+arr[k].dist[j];
arr[i].from[j]=k;
count++;
if(count==0)
hop[i][j]=1;
else
hop[i][j]=count+hop[k][j];
}
}
count=0;
}
}
for(i=0;i<n;i++)
{
printf("state value of router under %d",i+1);
printf("\n node\tvia node\tdiatance\tnumber of hopes\n");
for(j=0;j<n;j++)
{
if(i==j)
printf("\n%d\t%d\t%d\n",j+1,arr[i].from[j]+1,arr[i].dist[j]);
else
printf("\n%d\t%d\t\t%d\t\t%d\n",j+1,arr[i].from[j]+1,arr[i].dist[j],hop[i][j]+1);
}
}
}
EX.NO.9 ROUTING PROTOCOL SIMULATION TOOLS
DATE:
PROGRAM:
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the Trace file
set file1 [open out.tr w]
$ns trace-all $file1
#Open the NAM trace file
set file2 [open out.nam w]
$ns namtrace-all $file2
#Define a 'finish' procedure
proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam out.nam &
exit 3
}
# Next line should be commented out to have the static routing
$ns rtproto DV
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n4 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n1 0.3Mb 10ms DropTail
$ns duplex-link $n1 $n2 0.3Mb 10ms DropTail
$ns duplex-link $n2 $n3 0.3Mb 10ms DropTail
$ns duplex-link $n1 $n4 0.3Mb 10ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 10ms DropTail
$ns duplex-link $n4 $n5 0.5Mb 10ms DropTail
#Give node position (for NAM)
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right
$ns duplex-link-op $n2 $n3 orient up
$ns duplex-link-op $n1 $n4 orient up-left
$ns duplex-link-op $n3 $n5 orient left-up
$ns duplex-link-op $n4 $n5 orient right-up
#Setup a TCP connection
set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n5 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
$ns rtmodel-at 1.0 down $n1 $n4
$ns rtmodel-at 4.5 up $n1 $n4
$ns at 0.1 "$ftp start"
$ns at 6.0 "finish"
$ns run
EX.NO: 10 ERROR CORRECTION CODE USING CRC
DATE:
PROGRAM
import java.io.*;
class CRC
{
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...

You might also like