Ilovepdf Merged Removed
Ilovepdf Merged Removed
LIST OF EXPERIMENTS :
1. Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute. Capture ping
and traceroute PDUs using a network protocol analyzer and examine.
2. Write a HTTP web client program to download a web page using TCP sockets
3. Applications using TCP sockets like:
a) Echo client and echo server
b) Chat
4. Simulation of DNS using UDP sockets.
5. Use a tool like Wireshark to capture packets and examine the packets.
6. Write a code simulating ARP /RARP protocols.
7. Study of Network simulator (NS) and Simulation of Congestion Control Algorithms using NS.
8. Study of TCP/UDP performance using Simulation tool.
9. Simulation of Distance Vector/ Link State Routing algorithm.
10. Simulation of an error correction code (like CRC).
EX.No:1 NETWORKING COMMANDS
DATE:
AIM:
To Learn to use commands like tcpdump, netstat, ifconfig, nslookup and traceroute ping.
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.
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.
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: tcpdump is a command-line tool that allows you to capture, filter, and analyze network
traffic. It's invaluable for network administrators and security professionals to troubleshoot network issues,
monitor network activity, and identify potential security threats.
AIM:
To Write a HTTP web client program to download a web page using TCP sockets.
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"));
bByteArrayOutputStream 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 {
OUTPUT
2. Define HTTP.
HTTP means HyperText Transfer Protocol. HTTP is the underlying protocol used by the World
Wide Web and this protocol defines how messages are formatted and transmitted, and what actions Web
servers and browsers should take in response to various commands.
4. Define webpage.
A web page or webpage is a document commonly written in HTML (Hypertext Markup Language)
that is accessible through the Internet or other networks using an Internet browser.
5. Define URL.
URL stands for Uniform Resource Locator, and is used to specify addresses on the World Wide
Web. A URL is the fundamental network identification for any resource connected to the web (e.g.,
hypertext pages, images, and sound files). The protocol specifies how information from the link is
transferred.
RESULT :
The webpage is successfully downloaded and the contents are displayed and verified.
EX. No: 3a TCP SOCKETS APPLICATION – ECHO CLIENT & SERVER
DATE:
AIM
To write a socket program for implementation of echo Client and Server.
ALGORITHM
CLIENT
1. Start
2. Create the TCP socket
3. Establish connection with the server
4. Get the message to be echoed from the user
5. Send the message to the server
6. Receive the message echoed by the server
7. Display the message received from the server
8. Terminate the connection
9. Stop
SERVER
1. Start
2. Create TCP socket, make it a listening socket
3. Accept the connection request sent by the client for connection establishment
4. Receive the message sent by the client
5. Display the received message
6. Send the received message to the client from which it receives
7. Close the connection when client initiates termination and server becomes a listening server,
waiting for clients.
8. Stop.
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)
}
try
{
System.out.println(e);
}
c=s.accept();
is=newDataInputStream(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 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 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!
Viva Questions and Answers:
Socket programs are used to communicate between various processes usually running on
different systems. It is mostly used to create a client-server environment.
3. Define echo.
Echo describes when data is sent to a computer or other networkdevices, and that
information is sent back to verify the information was received. Echo can be a command used
with operating systems, network devices, or a function of a device.
RESULT:
Thus the above program a client-server application for echo using TCP / IP was
executed and successfully.
EX.No: 3b TCP SOCKETS APPLICATION - CHAT
DATE:
AIM
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.*;
TCPclient1.java
import java.net.*;
import java.io.*;
}
}
OUTPUT
SERVER
CLIENT
Client:Hai Server
Server: Hai Client
Client:How are you
Server: Fine
Client:quit
Server: quit
Viva Questions and Answers:
1. Define chat.
A real-time communication via keyboard between two or more users on a local network (LAN) or
over the Internet
2. Define TCP.
TCP/IP stands for Transmission Control Protocol/Internet Protocol, which is a set of
networking protocols that allows two or more computers to communicate. The Defense Data Network,
part of the Department of Defense, developed TCP/IP, and it has been widely adopted as a networking
standard.
RESULT:
Thus the above program a client-server application for chat using TCP / IP was executed
and successfully.
Ex.No:3c FILE TRANSFER IN CLIENT & SERVER
DATE:
AIM :
ALGORITHM:
CLIENT SIDE
1. Start.
5. After getting approval from the server ,the client either get file from the server
or send
SERVER SIDE
1. Start.
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.
6. Stop.
PROGRAM:
CLIENT SIDE
import java.net.*;
import java.io.*;
System.currentTimeMillis();
int bytesRead;
System.out.println("Connecting...");
// receive file
InputStream is = sock.getInputStream();
bytesRead = is.read(mybytearray,0,mybytearray.length);
current = bytesRead;
if(bytesRead >= 0)
current += bytesRead;
while(bytesRead > -1);
bos.write(mybytearray, 0 , current);
bos.flush();
System.out.println(end-start);
bos.close();
sock.close();
SERVER SIDE
import java.net.*;
import java.io.*;
while (true)
System.out.println("Waiting...");
OutputStream os = sock.getOutputStream();
System.out.println("Sending...");
os.write(mybytearray,0,mybytearray.length);
os.flush();
sock.close();
}
OUTPUT:
SERVER OUTPUT
Connection Established
CLIENT OUTPUT
File transfer is the process of copying or moving a file from one computer to
another over a network or Internet connection. It enables sharing, transferring or
transmitting a file or a logical data object between different users and/or computers
both locally and remotely.
RESULT:
DATE:
AIM
To write a program to Simulation of DNS using UDP sockets.
ALGORITHM
PROGRAM
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
Viva Questions and Answers:
1. Define DNS.
DNS. (Domain Name System) The Internet's system for converting alphabetic names into
numeric IP addresses. For example, when a Web address (URL) is typed into a browser, DNSservers
return the IP address of the Web server associated with that name.
2. Define UDP.
User Datagram Protocol (UDP) is part of the Internet Protocol suite used by programs running on
different computers on a network. UDP is used to send short messages called datagrams but overall, it is
an unreliable, connectionless protocol.
An Internet Protocol address (IP address) is a numerical label assigned to each device connected to
a computer network that uses the Internet Protocol for communication. An IP address serves two
principal functions: host or network interface identification and location addressing.
D
RESULT :
Thus the above program a client-server application for chat using UDP was executed and
successfully
Ex.No: 5 TOOL – WIRESHARK TO CAPTURE &EXAMINE PACKETS
DATE:
Wireshark is a free and open-source packet analyzer. It is used for network troubleshooting, analysis,
software and communications protocol development, and education. It works similar to tcpdump in
linux but the problem is that there is no GUI for tcpdump. Wireshark is having a nice interface through
which we can differentiate the data as per the different parameters and then we can analyze the packet
transfer process.
Whenever we want to do an analysis of any data packet the first step is to capture the packet which is
coming and outgoing then we use packet analyzer tool named Wireshark.
Step 1:
First we need to download and install Wireshark on our machine as per our operating system.
Wireshark is available to download and install on all the most used platforms
Step 2:
We need to start the Wireshark with administrative permission it will show the below window. Here we
need to select the appropriate interface through which we want to capture the packets.
Step 3:
Once we select the interface then Wireshark starts capturing packets and showing the list of packets and
live to capture packet window. Wireshark will keep capturing live packets until we stop capturing.
Step 4:
If We want to continue the live capturing then we can keep capturing the packet and if we want to stop
capturing then we can click on stop capturing packet menu in the toolbar.
Step 5:
The various column in the Wireshark window i.e. no. Time, Source, Destination, and protocol, etc.
Now we can select the appropriate packet which we want to analyze.
Step 6:
As per the various packet format we can select and analyze that how the packets are being transferred
over the internet.
Analyze the packet then we can see which protocol is used at various layer. What is the size of actual
message and and size of various header. Identify the various segments of the original message because a
large message reach to destination from source in the form of segments.
Wireshark is a useful tool for capturing network traffic data. Network pros can make the most of the
tool by analyzing captured packets to see what that data means for troubleshooting.
Capturing network traffic with tools such as Wireshark and tcpdump is fairly straightforward. Where
many administrators run into trouble is understanding what they've captured.
This article explains the primary components of captured data and relates this information to the
TCP/IP model. The article's purpose is not covering how to use Wireshark or its features and
options.
The basic steps to capture packets -- enough for you to grab a packet and apply the interpretive
information provided throughout.
Take the following steps to initiate a capture in Wireshark:
1. Open Wireshark.
Start a capture with the shark fin button in the upper left of the Wireshark tool.
Wireshark captures an immense amount of data quickly if filter not used. While this might be what you
want, be sure to set an effective filter if you know the protocols for the service you're troubleshooting.
And don't run the capture any longer than you must. Wireshark has various search and filter options, but
a targeted capture is much easier to work with.
I use Wireshark in this article because it is common, has a relatively simple GUI and is flexible. But many
other powerful protocol analyzers are available, such as tcpdump. You can analyze the content you
capture with those tools using the information below.
Wireshark is powerful and has many options beyond this article's scope, including network analysis and
performance information. Also, note that Wireshark v3 organizes the output into three vertically stacked
window panes. Wireshark v4 uses the same three panes, but the Packet Details pane is in the lower-left
corner -- it was the middle pane in v3 -- and the Packet Bytes pane is in the lower-right corner.
Three panes in the main Wireshark window
In the new Wireshark interface, the top pane summarizes the capture. It displays one or more frames,
along with the packet number, time, source, destination, protocol, length and info fields.
Use the protocols, source and destination addresses, and ports columns to help you decide which frame
to examine. Click on a frame to select it, and then look at the two lower panes for details.
The sample capture for these screenshots is a simple. This example generates DNS and other traffic that
is handy for the explanations below.
RESULT :
Thus the Wireshark tool is used to Captured and examined Packets successfully
Ex.No:6a CODE FOR SIMULATING ARP PROTOCOLS DATE:
AIM
ALGORITHM
CLIENT
SERVER
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);
t.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();
}
}
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
1. Define ARP.
The address resolution protocol (arp) is a protocol used by the Internet Protocol (IP)
[RFC826], specifically IPv4, to map IP network addresses to the hardware addresses used by a
data link protocol.
2. Define IPv4.
IPv4 (Internet Protocol Version 4) is the fourth revision of the Internet Protocol (IP) used to to
identify devices on a network through an addressing system.
RESULT :
Thus the implementation of ARP is done & executed successfully.
EX.No: 6b CODE FOR SIMULATING RARP PROTOCOLS
DATE:
AIM
To write a java program for simulating RARP protocols.
ALGORITHM
CLIENT
SERVER
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(newInputStreamReader(Sysem.in))
System.out.println("Enter the Physical address (MAC):");
String str=in.readLine();
sendbyte=str.getBytes();
DatagramPacket sender=new DatagramPacket(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=new Datagram Packet (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
1. Define RARP.
RARP (Reverse Address Resolution Protocol) is a protocol by which a physical machine in a local
area network can request to learn its IP address from a gateway server's Address Resolution Protocol
(ARP) table .
RESULT:
Thus the implementation of RARP is done & executed successfully.
EX.No: 7 STUDY OF NETWORK SIMULATOR (NS) AND
DATE: SIMULATION OF CONGESTION CONTROL
ALGORITHMS USING NS
AIM:
To Study Network simulator (NS).and Simulation of Congestion Control Algorithms using
NS
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.
Packet loss
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 error and 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
Throughput 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. Throughput is usually measured inbitsper
second (bit/s orbps), and sometimes in data packets per second or data packets per time slot. This
measures 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 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 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.
5. Define OPNET.
OPNET Network Simulator. OPNET Network simulator is a tool to simulate the behavior and
performance of any type of network. The main difference Opnet Network Simulator comparing to other
simulators lies in its power and versatility. IT Guru provides pre-built models of protocols and devices.
RESULT :
Thus we have Studied Network simulator (NS) and Simulation of Congestion Control
Algorithms using NS.
EX.No:8 STUDY OF TCP/UDP PERFORMANCE USING SIMULATION TOOL
DATE:
AIM
To Study of TCP/UDP performance using Simulation tool.
TCP Performance
Algorithm
1. Create a Simulator object.
2. Set routing as dynamic.
3. Open the trace and nam trace files.
4. Define the finish procedure.
5. Create nodes and the links between them.
6. Create the agents and attach them to the nodes.
7. Create the applications and attach them to the tcp agent.
8. Connect tcp and tcp sink.
9. Run the simulation.
PROGRAM
OUTPUT
UDP Performance
ALGORITHM
PROGRAM
OUTPUT
RESULT :
AIM:
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 priority over 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-
updateprocess 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).
ALGORITHM
PROGRAM
$ ns distvect.tcl
Viva questions and answers:
In distance vector routing the least cost route between any two nodes is the route with minimum
distance. In this each node maintains a vector table of minimum distances to every node. The table at
each node also guides the packets to the desired node by showing the next stop in the route.
In this each node shares its routing table with its immediate neighbors periodically and when there is a
change.
5. What is RIP?
RESULT:
Thus the simulation for Distance vector routing protocols was done using NS2 Ex.No: 9b
Ex.No: 9b SIMULATION OF LINK STATE ROUTING ALGORITHM
DATE:
AIM:
To implement the Link State Routing Algorithm
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.
b. Flooding
Flooding is a simple routing algorithm in which every incoming packet is sent through every outgoing
link except the one it arrived on. Flooding is used in bridging and in systems such as Usenet and peer-
to-peer file sharing and as part of some routing protocols, including OSPF, DVMRP, and those used
in ad-hoc wireless networks.There are generally two types of flooding available, Uncontrolled
Flooding and Controlled Flooding. Uncontrolled Flooding is the fatal law of flooding. All nodes have
neighbours and route packets indefinitely. More than two neighbours creates a broadcast storm.
Controlled Flooding has its own two algorithms to make it reliable, SNCF (Sequence Number
Controlled Flooding) and RPF (Reverse Path Flooding).
In SNCF, the node attaches its own address and sequence number to the packet, since every node has
a memory of addresses and sequence numbers.
If it receives a packet in memory, it drops it immediately while in RPF, the node will only send the
packet forward. If it is received from the next node, it sends it back to the sender.
ALGORITHM
PROGRAM
OUTPUT
Viva questions and answers:
1. What is link state routing protocol?
It has a different concept from that of distance vector routing. In this each node in the
domain has the entire topology of the domain-the list of nodes and links, how they are connected
including the type, cost and condition of the links.
Dijkstra’s algorithm.
By formation of a shortest path tree for each node. Calculation of a routing table based on
the shortest path tree. Creation of the states of the links by each node.
A node sends its routing table, normally every 30’s in a periodic update. The period depends
on the protocol that is using distance vector routing.
RESULT :
Thus the simulation for Link State routing protocols was done using NS2.
EX.No:10 SIMULATION OF ERROR CORRECTION CODE (LIKE CRC)
DATE:
AIM
To implement error checking code using java.
ALGORITHM
1. Start the Program
2. Given a bit string, append 0S to the end of it (the number of 0s is the same as the degree of the
generator polynomial) let B(x) be the polynomial corresponding to B.
3.Divide B(x) by some agreed on polynomial G(x) (generator polynomial) and determine the remainder
R(x). This division is to be done using Modulo 2 Division.
4. Define T(x) = B(x) –R(x)
5. (T(x)/G(x) => remainder 0)
6. Transmit T, the bit string corresponding to T(x).
7. Let T’ represent the bit stream the receiver gets and T’(x) the associated polynomial
8. The receiver divides T1(x) by G(x). If there is a 0 remainder, the receiver concludes T = T’ and no
error occurred otherwise, the receiver concludes an error occurred and requires a retransmission
9. Stop the Program
PROGRAM
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 remainder 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]);
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
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. )
BUILD SUCCESSFUL
RESULT :