Computer Networks Manual
Computer Networks Manual
Computer Networks Manual
RAJAMADAM - 614701
PATTUKKOTTAI
RAJAMADAM - 614701
NAME :
REGISTER NUMBER :
SEMESTER :
BRANCH :
ACADEMIC YEAR :
BONAFIDE CERTIFICATE
REGISTER NO:
3.a Application using tcp socket for echo client and echo
server.
3.b Application using tcp socket for chat
10 Implementation of subnetting
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
C:\>netstat
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
Ping is the most basic TCP/IP command, and it’s main purpose is to place a phone call
or communicate to another computer on the network, and request an answer. Ping has 2
options it can use to place a phone call to another computer on the network. It can use
the computers name or IP address.
C:\>route
The route command displays the computers routing table. A typical computer,
with a single network interface, connected to a LAN, with a router is fairly
simple and generally doesn’t pose any network problems. But if you’re having
trouble accessing other computers on your network, you can use the route
command to make sure the entries in the routing table are correct.
C:\>tracert
The tracert command displays a list of all the routers that a packet has to go through
to get from the computer where tracert is run to any other computer on the internet.
C:\>tcpdump
The tcpdump is a common packet analyzer that runs under the command line. It allows
the user to display TCP/IP and other packets being transmitted or received over a
network to which the computer is attached.
OUTPUT:
RESULT:
Thus, the above list of primitives has been studied.
1.b) Capture ping and traceroute PDU’s using a network
AIM:
Writes the java program to download a webpage
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.
CLIENT 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 WebClient{
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("pic1.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
System.out.println("Sending image to server. ");
OutputStream out = soc.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(bytes.length);
dos.write(bytes, 0, bytes.length);
System.out.println("Image sent to server. ");
dos.close();
out.close();
}catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
soc.close();
}
soc.close();
}}
SERVER PROGRAM:
import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class WebServer {
public static void main(String args[]) throws Exception{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
System.out.println("Server Waiting for image");
socket=server.accept();
System.out.println("Client connected.");
InputStream in = socket.getInputStream();
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB");
byte[] data = new byte[len];
dis.readFully(data);
dis.close(); in.close();
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian);
JFrame f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
l.setIcon(icon);
f.add(l); f.pack();
f.setVisible(true); }}
OUTPUT:
RESULT:
The webpage is successfully downloaded and the contents are displayed and verified.
Ex. No:3.a
APPLICATION USING TCP SOCKET FOR ECHO CLIENT AND ECHO SERVER. Pg.no:
Date:
AIM:
write a java program application using TCP socket for echo client and echo server.
ALGORITHM:
1. Start the program.
2. Import all necessary packages.
3. Create two new application client and server.
4. Connect both applications.
5. Send the input data into client through server.
6. Get the input in client.
PROGRAM:
ECHO SERVER
import java.io.*;
import java.net.*;
try {
serverSocket = new ServerSocket(10007);
}
catch (IOException e)
{
System.err.println("Could not listen on port: 10007.");
System.exit(1);
}
Socket clientSocket = null;
System.out.println ("Waiting for connection.....");
try {
clientSocket = serverSocket.accept();
}
catch (IOException e)
{
System.err.println("Accept failed.");
System.exit(1);
}
System.out.println ("Connection successful");
System.out.println ("Waiting for input.....");
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),true);
BufferedReader in = new BufferedReader(new InputStreamReader( clientSocket.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
System.out.println ("Server: " + inputLine);
out.println(inputLine);
if (inputLine.equals("Bye."))
break;
}
out.close();
in.close();
clientSocket.close();
serverSocket.close();
}
}
OUTPUT:
ECHO SERVER:
ECHO CLIENT:
RESULT:
Thus, the application using TCP socket for echo client and echo server program
was written and the output was verified successfully.
Ex. No:3.b
APPLICATION USING TCP SOCKET FOR CHAT Pg.no:
Date:
AIM:
write a java program application using TCP socket for Chat between Server and Client.
Algorithm:
TCP Server
1. Create a socket
4. Accept connections.
TCP Client
1.Create a socket.
import java.io.*;
import java.net.*;
public class ChatClient
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1", 3000);
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new InputStreamReader(istream));
System.out.println("Start the chitchat, type and press Enter key");
String receiveMessage, sendMessage;
while(true)
{
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
pwrite.flush();
if((receiveMessage = receiveRead.readLine()) != null)
{
System.out.println(receiveMessage);
}
}
}
}
OUTPUT:
Server:
Client:
Result:
Thus, the application using TCP socket for Chat client and server program was
written and the output was verified successfully.
Ex. No:3.c
APPLICATION USING TCP SOCKET FOR FILE TRANSFER Pg.no:
Date:
AIM:
Create a Java program application using TCP socket for File Transfer client and server.
ALGORITHM:
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
public class FileTransferClient {
public static void main(String[] args) throws Exception{
Socket socket = new Socket(InetAddress.getByName("localhost"), 5000);
byte[] contents = new byte[10000];
FileOutputStream fos = new FileOutputStream("e:\\data2.bin");
BufferedOutputStream bos = new BufferedOutputStream(fos);
InputStream is = socket.getInputStream();
int bytesRead = 0;
while((bytesRead=is.read(contents))!=-1)
bos.write(contents, 0, bytesRead);
bos.flush();
socket.close();
System.out.println("File saved successfully!");
}
}
Output:
File transfer server:
Aim:
Create a java program for DNS application by 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:
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);
}
}
Output:
Dns server:
dns client:
Result:
Thus, the program for simulation of udp socket was written and the output
was verified successfully.
Ex. No:5
Write a code simulating ARP /RARP protocols Pg.no:
Date:
Thus, the implementation of ARP and RARP is done & executed successfully.
Ex. No:6
Study of Network simulator (NS) and Simulation of Pg.no:
Congestion Control Algorithms using NS
Date:
Aim:
NETWORK SIMULATOR
overview
Ns overview
➢ Ns Status
➢ Periodical release ( )
➢ Platform support
Ns functionalities
Wireless
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.
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)
4. Packet Tracer (open source)
Network simulators serve a variety of needs. Compared to the cost and time involved in setting
up an entire test bed containing multiple networked computers, routers and data links, network
simulators are relatively fast and inexpensive. They allow engineers, researchers to test
scenarios that might be particularly difficult or expensive to emulate using real hardware - for
instance, simulating a scenario with several nodes or experimenting with a new protocol in the
network. Network simulators are particularly useful in allowing researchers to test new
networking protocols or changes to existing protocols in a controlled and reproducible
environment. A typical network simulator encompasses a wide range of networking
technologies and can help the users to build complex networks from basic building blocks such
as a variety of nodes and links. With the help of simulators, one can design hierarchical
networks using various types of nodes like computers, hubs, bridges, routers, switches, links,
mobile units etc.
Various types of Wide Area Network (WAN) technologies like TCP, ATM, IP etc. and Local
Area Network (LAN) technologies like Ethernet, token rings etc., can all be simulated with a
typical simulator and the user can test, analyze various standard results apart from devising
some novel protocol or strategy for routing etc. Network simulators are also widely used to
simulate battlefield networks in Network-centric warfare
There are a wide variety of network simulators, ranging from the very simple to the very
complex. Minimally, a network simulator must enable a user to represent a network topology,
specifying the nodes on the network, the links between those nodes and the traffic between the
nodes. More complicated systems may allow the user to specify everything about the protocols
used to handle traffic in a network. Graphical applications allow users to easily visualize the
workings of their simulated environment. Text-based applications may provide a less intuitive
interface, but may permit more advanced forms of customization.
Packet loss
occurs when one or 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
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:
Network simulator (NS).and Simulation of Congestion Control Algorithms using NS
has been studied successfully.
Ex. No:7
TCP/UDP performance using Simulation tool Pg.no:
Date:
AIM:
Simulate the TCP and UDP performance using Simulation tool.
Procedure:
1.devolop a topology shown in below.
2.configure all end devices.
3. Generate the Network Traffic.
Topology:
Step1:
Generate traffic to populate Address Resolution Protocol(ARP) tables.
➢ Click Multi-Server and click the Desktop tab>Command Prompt.
➢ Enter the ping 192.168.1.255 command.
➢ This will take a few seconds as every device on the network responds to MultiServer.
➢ Close the MultiServer window.
Step2:
Generate web(HTTP) traffic.
➢ Switch to Simulation mode.
➢ Click HTTP Client and click the Desktop tab>Web Browser.
➢ In the URL field, enter 192.168.1.254 and click Go.
➢ Envelopes(PDUs) will appear in the simulation window.
➢ Minimize, but do not close, the HTTP Client configuration window.
Step3:
Generate FTP traffic.
➢ Click FTP Client and click the Desktop tab>Command Prompt.
➢ Enter the ftp 192.168.1.254 command.
➢ PDUs will appear in the simulation window.
➢ Minimize, but do not close, the FTP Client configuration window.
Step4:
Generate DNS traffic.
➢ Click DNS Client and click the Desktop tab>Command Prompt.
➢ Enter the nslookup multiserver.pt.ptu command.
➢ A PDU will appear in the simulation window.
➢ Minimize, but do not close, the DNS Client configuration window.
Step5:
Generate Email traffic.
➢ Click E-Mail Client and click the Desktop tab>Email tool.
➢ Click Compose and enter the following information:
➢ To: [email protected]
➢ Subject: Personalize the subject line
➢ E-Mail Body: Personalize the Email
➢ Click Send.
➢ Minimize, but do not close, the E-Mail Client configuration window.
Step6:
Verify that the traffic is generated and ready for simulation.
Every client computer should have PDUs listed in the Simulation Panel.
OUTPUT:
TCp:
UDP:
Result:
TCP/UDP performance has been studied successfully by using simulation tool.
Ex. No:8.a
Simulation of Distance Vector Routing Algorithm Pg.no:
Date:
Aim:
Configure a Network using Distance vector routing protocol.
Procedure:
➢ Develop a topology shown in below.
➢ Configure all routers.
➢ Implement RIP protocols in all router to configure network.
TOPOLOGY:
RouteR 1 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 10.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 13.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#
Router(config-if)#exit
Router(config)#router rip
Router(config-router)#network 10.0.0.0
Router(config-router)#network 13.0.0.0
Router(config-router)#
RouteR 2 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 11.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 10.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up
Router(config-if)#sh ip route
^
% Invalid input detected at '^' marker.
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet1/0
Router(config-if)#
Router(config-if)#exit
Router(config)#router rip
Router(config-router)#network 10.0.0.0
Router(config-router)#network 11.0.0.0
Router(config-router)#
RouteR 3 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 11.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet1/0
Router(config-if)#
Router(config-if)#exit
Router(config)#router rip
Router(config-router)#network 11.0.0.0
Router(config-router)#network 12.0.0.0
Router(config-router)#
Router 4 configuration…
Router>
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#no ip address
Router(config-if)#ip address 13.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 12.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route
Router#
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet1/0
Router(config-if)#
Router(config-if)#exit
Router(config)#router rip
Router(config-router)#network 12.0.0.0
Router(config-router)#network 13.0.0.0
Router(config-router)#
Rip protocols in routers:
Router 1:
Router>enable
Router#sh ip route rip
R 11.0.0.0/8 [120/1] via 10.1.1.2, 00:00:16, FastEthernet1/0
R 12.0.0.0/8 [120/1] via 13.1.1.2, 00:00:28, FastEthernet0/0
Router#
Router 2:
Router>enable
Router#sh ip route rip
R 12.0.0.0/8 [120/1] via 11.1.1.2, 00:00:08, FastEthernet0/0
R 13.0.0.0/8 [120/1] via 10.1.1.1, 00:00:15, FastEthernet1/0
Router#
Router 3:
Router>enable
Router#sh ip route rip
R 10.0.0.0/8 [120/1] via 11.1.1.1, 00:00:14, FastEthernet0/0
R 13.0.0.0/8 [120/1] via 12.1.1.2, 00:00:19, FastEthernet1/0
Router#
Router 4:
Router>enable
Router#sh ip route rip
R 10.0.0.0/8 [120/1] via 13.1.1.1, 00:00:22, FastEthernet0/0
R 11.0.0.0/8 [120/1] via 12.1.1.1, 00:00:16, FastEthernet1/0
Router#
Simulation of rip protocol:
Aim:
configure network using Link State routing protocol.
Procedure:
➢ Develop a Topology shown in figure given below.
➢ Configure all the workstation.
➢ Configure all switches.
➢ Configure all routers
➢ Implement OSPF protocols in router to configure network.
RouteR 1 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 14.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet1/0
Router(config-if)#ip address 15.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 40
Router(config-router)#network 14.0.0.0 255.0.0.0 area 0
Router(config-router)#network 15.0.0.0 255.0.0.0 area 0
Router(config-router)#end
Router#
RouteR 2 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface Serial2/0
Router(config-if)#ip address 11.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet5/0, changed state to down
Router(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#shutdown
%LINK-5-CHANGED: Interface FastEthernet5/0, changed state to administratively down
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#no ip address
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial3/0, changed state to down
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 20
Router(config-router)#network 11.0.0.0 255.0.0.0 area 0
Router(config-router)#network 12.0.0.0 255.0.0.0 area 0
RouteR 3 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface Serial2/0
Router(config-if)#ip address 11.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet5/0, changed state to down
Router(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#shutdown
%LINK-5-CHANGED: Interface FastEthernet5/0, changed state to administratively down
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#
Router(config-if)#exit
Router(config)#interface FastEthernet5/0
Router(config-if)#no ip address
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#ip address 12.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial3/0, changed state to down
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 20
Router(config-router)#network 11.0.0.0 255.0.0.0 area 0
Router(config-router)#network 12.0.0.0 255.0.0.0 area 0
RouteR 4 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface Serial2/0
Router(config-if)#ip address 12.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial2/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial3/0
Router(config-if)#ip address 13.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial3/0, changed state to down
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#c
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial2/0, changed state to up
% Ambiguous command: "c"
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 30
Router(config-router)#network 12.0.0.0 255.0.0.0 area 0
Router(config-router)#network 13.0.0.0 255.0.0.0 area 0
RouteR 5 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 15.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial0/0/0
Router(config-if)#ip address 13.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial0/0/0, changed state to up
Router(config-if)#exit
Router(config)#interface Serial0/0/1
Router(config-if)#ip address 17.1.1.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface Serial0/0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet0/1
Router(config-if)#ip address 18.1.1.1 255.0.0.0
Router(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0/1, changed state to up
no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 60
Router(config-router)#network 13.0.0.0 255.0.0.0 area 0
Router(config-router)#network 15.0.0.0 255.0.0.0 area 0
Router(config-router)#network 17.0.0.0 255.0.0.0 area 0
Router(config-router)#network 18.0.0.0 255.0.0.0 area 0
RouteR 6 configuRation…
Router>enable
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface FastEthernet0/0
Router(config-if)#ip address 10.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#interface FastEthernet0/1
Router(config-if)#ip address 14.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
Router(config-if)#exit
Router(config)#interface Serial0/0/0
Router(config-if)#ip address 11.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial0/0/0, changed state to down
Router(config-if)#
Router(config-if)#exit
Router(config)#interface Serial0/0/1
Router(config-if)#ip address 16.1.1.1 255.0.0.0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface Serial0/0/1, changed state to down
Router(config-if)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#router ospf 10
Router(config-router)#network 10.0.0.0 255.0.0.0 area 0
Router(config-router)#network 11.0.0.0 255.0.network 10.0.0.0 255.0.0.0 area 0network 14.0.0.0
255.0.0.0 area 0
Router(config-router)#network 16.0.0.0 255.0.0.0 area 0
Router(config-router)#end
Link state protocol- connected networks
Simulation of ospf:
Result:
Aim:
Algorithm:
receiver:
Result:
The stop and wait protocol program has been executed and output verified successfully.
Ex. No:10
Implementation of subnetting Pg.no:
Date:
Aim:
find Subnet Mask and Network ID for given IP Address.
Algorithm:
Step1: Get the input from the user by using scanner method.
Step 2: Read the input by using nextLine() and store it.
Step 3: Split the string based on string by using split(“\\”)
Step4 : Convert it into binary.
Step 5: calculating the network mask by using math and logarithmic
Step 6: get the first address by ANDing the last n bits with 0.
Step7 : get the last address by ORing the last n bits with 1.
Program:
import java.util.Scanner;
class subnet{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("Ip address: ");
String ip = sc.nextLine();
String split_ip[] = ip.split("\\."); //SPlit the string after every .
String split_bip[] = new String[4]; //split binary ip
String bip = "";
for(int i=0;i<4;i++){
split_bip[i] = appendZeros(Integer.toBinaryString(Integer.parseInt(split_ip[i])));
bip += split_bip[i];
}
System.out.println("Binary Format "+bip);
System.out.print("Enter the number of addresses in each subnet: ");
int n = sc.nextInt();
int bits = (int)Math.ceil(Math.log(n)/Math.log(2));
int mask = 32-bits;
System.out.println("Subnet mask = "+mask);
int fbip[] = new int[32];
for(int i=0; i<32;i++) fbip[i] = (int)bip.charAt(i)-48; //convert cahracter 0,1 to integer 0,1
for(int i=31;i>31-bits;i--)//Get first address by ANDing last n bits with 0
fbip[i] &= 0;
String fip[] = {"","","",""};
for(int i=0;i<32;i++)
fip[i/8] = new String(fip[i/8]+fbip[i]);
System.out.print("Network address is = ");
for(int i=0;i<4;i++){
System.out.print(Integer.parseInt(fip[i],2));
if(i!=3) System.out.print(".");
}
System.out.println();
int lbip[] = new int[32];
for(int i=0; i<32;i++) lbip[i] = (int)bip.charAt(i)-48; //convert cahracter 0,1 to integer 0,1
for(int i=31;i>31-bits;i--)//Get last address by ORing last n bits with 1
lbip[i] |= 1;
String lip[] = {"","","",""};
for(int i=0;i<32;i++)
lip[i/8] = new String(lip[i/8]+lbip[i]);
System.out.print("Broadcast address is = ");
for(int i=0;i<4;i++){
System.out.print(Integer.parseInt(lip[i],2));
if(i!=3) System.out.print(".");
}
System.out.println();
}
static String appendZeros(String s){
String temp = new String("00000000");
return temp.substring(s.length())+ s;
}
}
OUTPUT:
Result:
The program for subnetting has been executed successfully.
Ex. No:11
Simulation of error correction code Pg.no:
Date:
AIM:
Implement the hamming code using java programming language for error correction.
Algorithm:
1. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc).
2. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc).
3. All the other bit positions are marked as data bits.
4. Each data bit is included in a unique set of parity bits, as determined its bit position in
binary form.
a. Parity bit 1 covers all the bits positions whose binary representation includes a 1 in
the least significant position (1, 3, 5, 7, 9, 11, etc).
b. Parity bit 2 covers all the bits positions whose binary representation includes a 1 in
the second position from the least significant bit (2, 3, 6, 7, 10, 11, etc).
c. Parity bit 4 covers all the bits positions whose binary representation includes a 1 in
the third position from the least significant bit (4–7, 12–15, 20–23, etc).
d. Parity bit 8 covers all the bits positions whose binary representation includes a 1 in
the fourth position from the least significant bit bits (8–15, 24–31, 40–47, etc).
e. In general each parity bit covers all bits where the bitwise AND of the parity
position and the bit position is non-zero.
5. Since we check for even parity set a parity bit to 1 if the total number of ones in the
positions it checks is odd.
6. Set a parity bit to 0 if the total number of ones in the positions it checks is even.
Program:
import java.util.*;
public class HammingCode {
static void print(int ar[])
{
for (int i = 1; i < ar.length; i++) {
System.out.print(ar[i]);
}
System.out.println();
}
static int[] calculation(int[] ar, int r)
{
for (int i = 0; i < r; i++) {
int x = (int)Math.pow(2, i);
for (int j = 1; j < ar.length; j++) {
if (((j >> i) & 1) == 1) {
if (x != j)
ar[x] = ar[x] ^ ar[j];
}
}
System.out.println("r" + x + " = "+ ar[x]);
}
return ar;
}
static int[] generateCode(String str, int M, int r)
{
int[] ar = new int[r + M + 1];
int j = 0;
for (int i = 1; i < ar.length; i++) {
if ((Math.ceil(Math.log(i) / Math.log(2)) - Math.floor(Math.log(i) / Math.log(2)))== 0)
{
ar[i] = 0;
}
else {
ar[i] = (int)(str.charAt(j) - '0');
j++;
}
}
return ar;
}
public static void main(String[] args)
{
System.out.println("Enter the data ");
Scanner sc=newF Scanner(System.in);
String str = sc.nextLine();
int M = str.length();
int r = 1;
while (Math.pow(2, r) < (M + r + 1))
{
r++;
}
int[] ar = generateCode(str, M, r);
System.out.println("Generated hamming code ");
ar = calculation(ar, r);
print(ar);
}
}
OUTPUT:
Result:
Thus, the program for error correction has executed and output was verified.
Ex. No:12
Study of performance evaluation in routing protocols Pg.no:
Date:
Aim:
To study about the various routing protocols and evaluates their performance.
Dynamic routing protocols:
An aggregate of networks linked by routers is known as an internet. When a packet is sent
from source to destination there can be such a lot of passes through many routers until it reaches the
router attached to the destination network. Autonomous system (AS) that's a group of routers under
a common place management is also referred to as routing domains. Depending on the independent
device,
there are two sorts of routing protocols:
characteristic that specifies the route of the subsequent-hop router or exit interface to reach
the destination. Characteristics of Distance Vector Protocols:
➢ Collects statistics of the records of the routing desk of its neighbors.
➢ Determines the better direction, adding the metric cost that is acquired as the routing facts
happens from router to some other one.
➢ The updates for the alternate of topology consist of periodic updates of the tables.
➢ Slower convergence. RIP and EIGRP are a number of the examples of distance vector routing
protocols.
The Routing Information Protocol (RIP) is one of the interarea (interior) routing protocols
used in an autonomous system. It is one of the distance vector routing protocols that is quite
simple protocol. RIP implements distance vector routing immediately with some concerns.
RIP traits:
➢ Distance Vector routing protocol.
➢ It metric is the wide variety of hops
➢ The maximum number of hops is 15
➢ One updates each 30 second.
➢ Now not always it selects the fastest path with
➢ a minimum quantity of hope
➢ It generates traffic of community with updates.
There are variations of RIP, particularly RIPv1 and RIPv2.
OSPF characteristics:
Update Type Full table Full table Only changes Only changes