0% found this document useful (0 votes)
39 views78 pages

CN LabManual

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)
39 views78 pages

CN LabManual

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/ 78

LABORATORY MANUAL

Computer Networks Laboratory (20A05501P)


THIRD YEAR B.TECH I SEMESTER

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

RAVINDRA COLLEGE OF ENGINEERING FOR WOMEN


Accredited by NBA(CSE&ECE), Accredited by NAAC ‘A+’
An ISO 9001:2008 Certified Institution, Approved by A.I.C.T.E.-New Delhi,
Permanently Affiliated to J.N.T. University- Anantapur, Ananthapuramu.
Nandikotkur Road, Venkayapally, Kurnool, Andhra Pradesh – 518452.
VISION AND MISION STATEMENTS OF THE CSE DEPARTMENT

Vision :

To be a center of excellence in the field of Computer Science and Engineering along with
imparting proficient and adaptable technological resources for the well being of mankind.

Mission:

To achieve professional excellence by promoting an academic environment conducive to


research and innovative ideas in order to meet the needs of ever changing IT industry and
society.

Course Outcomes:

1. Design scripts for Wired network simulation.


2. Design scripts of static and mobile wireless networks simulation.
3. Analyze the data traffic using tools.
4. Design JAVA programs for client-server communication.
5. Construct a wired and wireless networks using the real hardware.
6. Build a network topology and configure using Packet Tracer Software.
RAVINDRA COLLEGE OF ENGINEERING FOR WOMEN
Accredited by NBA(CSE&ECE), Accredited by NAAC ‘A+’
An ISO 9001:2008 Certified Institution, Approved by A.I.C.T.E.-New Delhi,
Permanently Affiliated to J.N.T. University- Anantapur, Ananthapuramu.
Nandikotkur Road, Venkayapally, Kurnool, Andhra Pradesh – 518452.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


INDEX

S No Title of the Experiment


Study different types of Network cables (Copper and Fiber) and prepare
cables (Straight and Cross) to connect Two or more systems. Use
crimping tool to connect jacks. Use LAN tester to connect the cables.

Install and configure Network Devices: HUB, Switch and Routers.


Consider both manageable and non-manageable switches. Do the logical
1 configuration of the system. Set the bandwidth of different ports.

Install and Configure Wired and Wireless NIC and transfer files between
systems in Wired LAN and Wireless LAN. Consider both adhoc and
infrastructure mode of operation.

Work with the commands Ping, Tracert, Ipconfig, pathping, telnet, ftp,
2 getmac, ARP, Hostname, Nbtstat, netdiag, and Nslookup

Find all the IP addresses on your network. Unicast, Multicast, and


3
Broadcast on your network.
Use Packet tracer software to build network topology and configure using
4
Distance vector routing protocol.
Use Packet tracer software to build network topology and configure using
5
Link State routing protocol.
6 Using JAVA RMI Write a program to implement Basic Calculator
7 Implement a Chatting application using JAVA TCP and UDP sockets.
Hello command is used to know whether the machine at the other end is
8 working or not. Echo command is used to measure the round trip time to
the neighbour. Implement Hello and Echo commands using JAVA.
Using Wireshark perform the following operations:
9 - Inspect HTTP Traffic
- Inspect HTTP Traffic from a Given IP Address
- Inspect HTTP Traffic to a Given IP Address
- Reject Packets to Given IP Address
- Monitor Apache and MySQL Network Traffic.
Install Network Simulator 2/3. Create a wired network using dumbbell
topology. Attach agents, generate both FTP and CBR traffic, and transmit
10
the traffic. Vary the data rates and evaluate the performance using metric
throughput, delay, jitter and packet loss.
Create a static wireless network. Attach agents, generate both FTP and
11 CBR traffic, and transmit the traffic. Vary the data rates and evaluate the
performance using metric throughput, delay, jitter and packet loss.
Create a mobile wireless network. Attach agents, generate both FTP and
12 CBR traffic, and transmit the traffic. Vary the data rates and evaluate the
performance using metric throughput, delay, jitter and packet loss.
Experiments beyond course curriculum

S No Title of the Experiment

Cisco Switch and Router Configuration basic commands in Packet Tracer


1

Setting up a Basic Home Network using Packet Tracer


2

T1: Shivendra S.Panwar, Shiwen Mao, Jeong-dong Ryoo, and Yihan Li, “TCP/IP Essentials A
Lab- Based Approach”, Cambridge University Press, 2004

T2: Cisco Networking Academy, “CCNA1 and CCNA2 Companion Guide”, Cisco Networking
Academy Program, 3rd edition, 2003

T3: Elloitte Rusty Harold, “Java Network Programming”, 3rd edition, O’REILLY, 2011
.
T4: Ns Manual, Available at: https://www.isi.edu/nsnam/ns/ns-documentation.html, 2011
Computer Networks Lab (20A05501P)

Experiment 1:

A) Study different types of Network cables (Copper and Fiber) and prepare cables (Straight and
Cross) to connect Two or more systems. Use crimping tool to connect jacks. Use LAN tester to
connect the cables.

B) Install and configure Network Devices: HUB, Switch and Routers. Consider both manageable
and non-manageable switches. Do the logical configuration of the system. Set the bandwidth of
different ports.

C) Install and Configure Wired and Wireless NIC and transfer files between systems in Wired
LAN and Wireless LAN. Consider both adhoc and infrastructure mode of operation.

A) Apparatus (Components): RJ-45 connector, Crimping Tool, Twisted pair Cable

Procedure: To do these practical following steps should be done:

1. Start by stripping off about 2 inches of the plastic jacket off the end of the cable. Be very careful at this
point, as to not nick or cut into the wires, which are inside. Doing so could alter the characteristics of
your cable, or even worse render is useless. Check the wires, one more time for nicks or cuts. If there are
any, just whack the whole end off, and start over.
2. Spread the wires apart, but be sure to hold onto the base of the jacket with your other hand. You do not
want the wires to become untwisted down inside the jacket. Category 5 cable must only have 1/2 of an
inch of 'untwisted' wire at the end; otherwise it will be 'out of spec'. At this point, you obviously have
ALOT more than 1/2 of an inch of un-twisted wire.
3. You have 2 end jacks, which must be installed on your cable. If you are using a pre-made cable, with one
of the ends whacked off, you only have one end to install - the crossed over end Below are two diagrams,
which show how you need to arrange the cables for each type of cable end. Decide at this point which
end you are making and examine the associated picture below.

Department of CSE, Ravindra College of Engineering for Women 1


Computer Networks Lab (20A05501P)

Diagram shows you how to prepare Cross wired connection

Diagram shows you how to prepare straight through wired connection

Department of CSE, Ravindra College of Engineering for Women 2


Computer Networks Lab (20A05501P)

B) Procedure: Following should be done to understand this practical.

Hub: An Ethernet hub, active hub, network hub, repeater hub, hub or concentrator is a device for
connecting multiple twisted pair or fiber optic Ethernet devices together and making them act as a single
network segment. Hubs work at the physical layer (layer 1) of the OSI model. The device is a form of
multiport repeater. Repeater hubs also participate in collision detection, forwarding a jam signal to all
ports if it detects a collision.

Switch: Anetwork switch or switching hub is a computer networking device that connects network
segments. The term commonly refers to a network bridge that processes and routes data at the data link
layer (layer 2) of the OSI model. Switches that additionally process data at the network layer (layer 3 and
above) are often referred to as Layer 3 switches or multilayer switches.

Router: A router is an electronic device that interconnects two or more computer networks, and
selectively interchanges packets of data between them. Each data packet contains address information that
a router can use to determine if the source and destination are on the same network, or if the data packet
must be transferred from one network to another. Where multiple routers are used in a large collection of
interconnected networks, the routers exchange information about target system addresses, so that each
router can build up a table showing the preferred paths between any two systems on the interconnected
networks.

Repeater: Functioning at Physical Layer. A repeater is an electronic device that receives a signal and
retransmits it at a higher level and/or higher power, or onto the other side of an obstruction, so that the
signal can cover longer distances. Repeater have two ports ,so cannot be use to connect for more than two
devices.

Department of CSE, Ravindra College of Engineering for Women 3


Computer Networks Lab (20A05501P)

Bridge: A network bridge connects multiple network segments at the data link layer (Layer 2) of the
OSI model. In Ethernet networks, the term bridge formally means a device that behaves according to the
IEEE 802.1D standard. A bridge and switch are very much alike; a switch being a bridge with numerous
ports. Switch or Layer 2 switch is often used interchangeably with bridge .Bridges can analyze incoming
data packets to determine if the bridge is able to send the given packet to another segment of the network.

Gate Way: In a communications network, a network node equipped for interfacing with another network
that uses different protocols.
• A gateway may contain devices such as protocol translators, impedance matching devices, rate
converters, fault isolators, or signal translators as necessary to provide system interoperability. It also
requires the establishment of mutually acceptable administrative procedures between both networks.
• A protocol translation/mapping gateway interconnects networks with different network
protocol technologies by performing the required protocol conversions.

C) Install and Configure Wired and Wireless NIC and transfer files between systems in
Wired LAN and Wireless LAN. Consider both adhoc and infrastructure mode of
operation .

Wired and Wireless NIC:


Objectives
Part 1 : Identify and Work with PC NICs

Required Resources:
 1 PC (Windows with two NICs, wired and wireless, and a wireless connection)

Department of CSE, Ravindra College of Engineering for Women 4


Computer Networks Lab (20A05501P)

Instructions
Part 1: Identify and Work with PC NICs.

In Part 1, you will identify the NIC types in the PC that you are using. You will explore different
ways to extract information about these NICs and how to activate and deactivate them.
Step 1: Use the Network and Sharing Center.
1. Navigate to the Control Panel. Click View network status and tasks under Network and
Internet heading in the Category View.
2. In the left pane, click the Change adapter settings link.
3. In the Network Connections window, the results provide a list of NICs available on this PC. Look
for your Wi-Fi adapters.
Note: Virtual Private Network (VPN) adapters and other types of network connections may also
be displayed in this window.

Step 2: Work with your wireless NIC.

1. Locate the wireless network connection. If it is disabled, right-click and select Enable to activate
your wireless NIC.
2. If the wireless network connection is not currently connected, right-click and
select Connect/Disconnect to connect to an SSID that you are authorized to connect to.
3. Right-click a wireless network connection, and then click Status.
4. The wireless network connection Status window displays where you can view information about
your wireless connection.
5. Click Details to display the Network Connection Details window.
6. Open a Windows Command Prompt and type ipconfig /all.
7. Close the command window and the Network Connection Details window. This should return you
back to the Wi-Fi Status window. Click Wireless Properties.
8. In the Wireless Network Properties window, click the Security tab.
9. The type of security the connected wireless router has implemented displays. Click the Show
characters check box to display the actual Network security key, instead of the hidden characters,
and then click OK.
10. Close the Wireless Network Properties and the Wi-Fi Status windows. Select and right-click
the Wi-Fi option > Connect/Disconnect. A pop-up window should appear at the bottom right
corner of your desktop that displays your current connection, along with a list of SSIDs that are in
range of the wireless NIC of your PC. If a scrollbar appears on the right side of this window, you
can use it to display additional SSIDs.
11. To join one of the other wireless network SSIDs listed, click the SSID that you want to join, and
then click Connect.
12. If you have selected a secure SSID, you are prompted to enter the Security key for the SSID.
Type the security key for that SSID and click OK. You can click the Hide characters check box
to prevent people from seeing what you type in the Security key field.
Step 3: Work with your wired NIC.
1. On the Network Connections window, select and right-click Ethernet option to display the drop-
down list. If the NIC is disabled, enable it, and then click the Status option.
Department of CSE, Ravindra College of Engineering for Women 5
Computer Networks Lab (20A05501P)

Note: You must have an Ethernet cable attaching your PC NIC to a switch or similar device to
see the status. Many wireless routers have a small 4-port Ethernet switch built-in. You can
connect to one of the ports using a straight-through Ethernet patch cable.
2. In the Status window, the results display information about your wired connection to the LAN.
3. Click Details… to view the address information for your LAN connection.
4. Open a command window prompt and type ipconfig /all. Find your Ethernet adapter information
and compare this with the information displayed in the Network Connection Details window.
C:\Users\ITE> ipconfig /all

Department of CSE, Ravindra College of Engineering for Women 6


Computer Networks Lab (20A05501P)

Experiment 2 : Work with the commands Ping, Tracert, Ipconfig, pathping, telnet, ftp,
getmac, ARP, Hostname, Nbtstat, netdiag, and Nslookup

Ping Command :

Verifies IP-level connectivity to another TCP/IP computer by sending Internet Control Message Protocol
(ICMP) Echo Request messages. The receipt of corresponding Echo Reply messages are displayed, along
with round-trip times. Ping is the primary TCP/IP command used to troubleshoot connectivity,
reachability, and name resolution.

Tracert Command :

Determines the path taken to a destination by sending Internet Control Message Protocol (ICMP) Echo
Request messages to the destination with incrementally increasing Time to Live (TTL) field values. The
path displayed is the list of near-side router interfaces of the routers in the path between a source host and
a destination. The near-side interface is the interface of the router that is closest to the sending host in the
path. Used without parameters, tracert displays help.

This diagnostic tool determines the path taken to a destination by sending ICMP Echo Request messages
with varying Time to Live (TTL) values to the destination. Each router along the path is required to
decrement the TTL in an IP packet by at least 1 before forwarding it.

Effectively, the TTL is a maximum link counter. When the TTL on a packet reaches 0, the router is
expected to return an ICMP Time Exceeded message to the source computer. Tracert determines the path
by sending the first Echo Request message with a TTL of 1 and incrementing the TTL by 1 on each
subsequent transmission until the target responds or the maximum number of hops is reached. The
maximum number of hops is 30 by default and can be specified using the -h parameter.

The path is determined by examining the ICMP Time Exceeded messages returned by intermediate
routers and the Echo Reply message returned by the destination. However, some routers do not return

Department of CSE, Ravindra College of Engineering for Women 7


Computer Networks Lab (20A05501P)

Time Exceeded messages for packets with expired TTL values and are invisible to the tracert command.
In this case, a row of asterisks (*) is displayed for that hop.

Examples:

To trace the path to the host named www.google.co.in use following command

Ipconfig Command :

Displays all current TCP/IP network configuration values and refreshes Dynamic Host Configuration
Protocol (DHCP) and Domain Name System (DNS) settings. This command is most useful on computers
that are configured to obtain an IP address automatically. This enables users to determine which TCP/IP
configuration values have been configured by DHCP, Automatic Private IP Addressing (APIPA), or an
alternate configuration.

If the Adapter name contains any spaces, use quotation marks around the adapter name (that is, "Adapter
Name").

For adapter names, ipconfig supports the use of the asterisk (*) wildcard character to specify either
adapters with names that begin with a specified string or adapters with names that contain a specified
string.

ARP Command :

Displays and modifies entries in the Address Resolution Protocol (ARP) cache, which contains one or
more tables that are used to store IP addresses and their resolved Ethernet or Token Ring physical

Department of CSE, Ravindra College of Engineering for Women 8


Computer Networks Lab (20A05501P)

addresses. There is a separate table for each Ethernet or Token Ring network adapter installed on your
computer.

Examples:

To display the ARP cache tables for all interfaces use following command

Netstat Command :

Displays active TCP connections, ports on which the computer is listening, Ethernet statistics, the IP
routing table, IPv4 statistics (for the IP, ICMP, TCP, and UDP protocols), and IPv6 statistics (for the IPv6,
ICMPv6, TCP over IPv6, and UDP over IPv6 protocols).

Department of CSE, Ravindra College of Engineering for Women 9


Computer Networks Lab (20A05501P)

Nbtstat Command :

Displays NetBIOS over TCP/IP (NetBT) protocol statistics

NetBIOS name tables for both the local computer and remote computers, and the NetBIOS name cache.
Nbtstat allows a refresh of the NetBIOS name cache and the names registered with Windows Internet
Name Service (WINS).

Nbtstat command-line parameters are case-sensitive.

Department of CSE, Ravindra College of Engineering for Women 10


Computer Networks Lab (20A05501P)

Nslookup Command :

Nslookup (Name Server lookup) is a UNIX shell command to query Internet domain name servers

Department of CSE, Ravindra College of Engineering for Women 11


Computer Networks Lab (20A05501P)

Pathping Command :

The PathPing command is a command-line network utility supplied in Windows 2000 and beyond that
combines the functionality of ping with that of tracert. It is used to locate spots that have network
latency and network loss.The command provides details of the path between two hosts and ping-like
statistics for each node in the path based on samples taken over a time period, depending on how many
nodes are between the start and end host.

The advantages of PathPing over ping and traceroute are that each node is pinged as
the result of a single command, and that the behavior of nodes is studied over an extended time period,
rather than the default ping sample of four messages or default traceroute single route trace. The
disadvantage is that it takes a total of 25 seconds per hop to show the ping statistics

Department of CSE, Ravindra College of Engineering for Women 12


Computer Networks Lab (20A05501P)

Telnet Command :

The Telnet protocol creates a communication path through a virtual terminal connection. The data
distributes in-band with Telnet control information over the transmission control protocol (TCP). Unlike
other TCP/IP protocols, Telnet provides a log-in screen and allows logging in as the remote device’s
actual user when establishing a connection on port 23. This type of access grants direct control with all
the same privileges as the owner of the credentials. Telnet comes with a command accessible from the
command line in Windows. The telnet command also exists for macOS and Linux operating systems.

Ftp Command :

FTP is the simplest file transfer protocol to exchange files to and from a remote computer or network.
Similar to Windows, Linux and UNIX operating systems also have built-in command-line prompts that
can be used as FTP clients to make an FTP connection. Here’s a list of commonly used FTP Linux and
UNIX platforms commands.

Department of CSE, Ravindra College of Engineering for Women 13


Computer Networks Lab (20A05501P)

Getmac Command :

Returns the media access control (MAC) address and list of network protocols associated with each
address for all network cards in each computer, either locally or across a network. This command is
particularly useful either when you want to enter the MAC address into a network analyzer, or when you
need to know what protocols are currently in use on each network adapter on a computer.

Department of CSE, Ravindra College of Engineering for Women 14


Computer Networks Lab (20A05501P)

Hostname Command :

hostname command in Linux is used to obtain the DNS(Domain Name System) name and set the
system’s hostname or NIS(Network Information System) domain name. A hostname is a name which
is given to a computer and it attached to the network. Its main purpose is to uniquely identify over a
network.

Netdiag Command:

The Netdiag command-line diagnostic tool helps to isolate networking and connectivity problems by
performing a series of tests to determine the state of your network client. These tests and the key network
status information that they expose give network administrators and support personnel a more direct
means of identifying and isolating network problems.

Department of CSE, Ravindra College of Engineering for Women 15


Computer Networks Lab (20A05501P)

Experiment 3 : Find all the IP addresses on your network. Unicast, Multicast, and Broadcast on
your network.

There are three types of Ethernet addresses:

1. Unicast addresses

Unicast addresses represent a single LAN interface. A unicast frame will be sent to a specific
device, not to a group of devices on the LAN:

The unicast address will have the value of the MAC address of the destination device.

Unicast IP addresses – an address of a single interface. The IP addresses of this type are used
for one-to-one communication. Unicast IP addresses are used to direct packets to a specific host.
Here is an example:

Department of CSE, Ravindra College of Engineering for Women 16


Computer Networks Lab (20A05501P)

In the picture above you can see that the host wants to communicate with the server. It uses the (unicast)
IP address of the server (192.168.0.150) to do so

2. Multicast addresses

Multicast addresses represent a group of devices in a LAN. A frame sent to a multicast address
will be forwarded to a group of devices on the LAN:

Multicast frames have a value of 1 in the least-significant bit of the first octet of the destination
address. This helps a network switch to distinguish between unicast and multicast addresses.

Multicast IP addresses – used for one-to-many communication. Multicast messages are sent to IP multicast
group addresses. Routers forward copies of the packet out to every interface that has hosts subscribed to that
group address. Only the hosts that need to receive the message will process the packets. All other hosts on the
LAN will discard them. Here is an example:

Department of CSE, Ravindra College of Engineering for Women 17


Computer Networks Lab (20A05501P)

R1 has sent a multicast packet destined for 224.0.0.9. This is an RIPv2 packet, and only routers on the
network should read it. R2 will receive the packet and read it. All other hosts on the LAN will discard the
packet.

3. Broadcast addresses

Broadcast addresses represent all device on the LAN. Frames sent to a broadcast address will be
delivered to all devices on the LAN:

broadcast IP addresses – used to send data to all possible destinations in the broadcast domain (the one-to-
everybody communication). The broadcast address for a network has all host bits on. For example, for the
network 192.168.30.0 255.255.255.0 the broadcast address would be 192.168.30.255*. Also, the IP address of
all 1’s (255.255.255.255) can be used for local broadcast. Here’s an example:

R1 wants to communicate with all hosts on the network and has sent a broadcast packet to the
broadcast IP address of 192.168.30.255. All hosts in the same broadcast domain will receive and
process the packet.

Department of CSE, Ravindra College of Engineering for Women 18


Computer Networks Lab (20A05501P)

Experiment - 4 : Use Packet tracer software to build network topology and configure using
Distance vector routing protocol.

Apparatus (software) : Packet Tracer Software

Procedure :

1. Develop a Topology shown in figure given below

2. Configure all Routers

3. Implement RIP protocols in Router to configure network.

RIP Configuration

Department of CSE, Ravindra College of Engineering for Women 19


Computer Networks Lab (20A05501P)

Configure PC0: Configure IP Address for PC0 and same repeat for all the PC’s.

Configure PC1:

Router 0 : By selecting GigabitEthernet0/0/0 provide the below IP Address


Department of CSE, Ravindra College of Engineering for Women 20
Computer Networks Lab (20A05501P)

Router 0 : By selecting Serial0/1/0 provide the below IP Address

Select the RIP and add all the network address as shown below and apply same for Router1 and
Router 2.
Department of CSE, Ravindra College of Engineering for Women 21
Computer Networks Lab (20A05501P)

Router 1:

Router 2 :

Department of CSE, Ravindra College of Engineering for Women 22


Computer Networks Lab (20A05501P)

SIMULATION: Sending data from PC1 to PC4 via Router 0 to Router 1, Router 1 to Router 2.

TOPOLOGY: Adding serial link from Router 0 to Router 2

Department of CSE, Ravindra College of Engineering for Women 23


Computer Networks Lab (20A05501P)

Router 0: Add Network Address in Router 0

Router 1:Add Network Address in Router 1

Department of CSE, Ravindra College of Engineering for Women 24


Computer Networks Lab (20A05501P)

Router 2: Add Network Address in Router 2

Department of CSE, Ravindra College of Engineering for Women 25


Computer Networks Lab (20A05501P)

SIMULATION: Sending data from PC1 to PC4 via Router 0 to Router 2.

Department of CSE, Ravindra College of Engineering for Women 26


Computer Networks Lab (20A05501P)

Experiment 5 : Use Packet tracer software to build network topology and configure using Link
State routing protocol.

Apparatus (Software): Packet Tracer Software

Procedure :

1. Develop a Topology shown in figure given below.

2. Configure all the Workstations.

3. Configure all Switches.

4. Configure all Routers.

5. Implement OSPF protocols in Router to configure network.

Department of CSE, Ravindra College of Engineering for Women 27


Computer Networks Lab (20A05501P)

Configure PC0: Configure IP Addresses for each PCs.

Configure PC1:

Department of CSE, Ravindra College of Engineering for Women 28


Computer Networks Lab (20A05501P)

Configure PC2:

Configure PC3:

Configuring IP Addresses for Router0: Configure all the IP Address for 4 ports as given
below

Department of CSE, Ravindra College of Engineering for Women 29


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 30


Computer Networks Lab (20A05501P)

Note: Configure IP Addreses for remaining routers router1, router2 and router3 also.

Configure Shortest Path by assigning Network Addresses for router0, router1, router2 and
router3 as shown below:

Department of CSE, Ravindra College of Engineering for Women 31


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 32


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 33


Computer Networks Lab (20A05501P)

Simulation: Sending data from PC0 to PC2 via Router0 and Router2 which takes open shortest
path.

Department of CSE, Ravindra College of Engineering for Women 34


Computer Networks Lab (20A05501P)

Experiment 6: Using JAVA RMI Write a program to implement Basic Calculator

Program:

RMI (Remote Method Invocation) is an API used to access objects running on another
JVM(Server-side). It is mainly used for the creation of distributed systems and is provided in Java
Rome. Stub and Skeleton are the two objects used for handling communication between client and
server. The following figure shows an overview of RMI.

 Stub Object: The stub object on the client machine builds an information block and
sends this information to the server.
 Skeleton Object: The skeleton object passes the request from the stub object to the
remote object. RMI contains a rmiregistry that holds all the server objects. The server
binds all the objects to the registry and then the client fetches the object from the
respective registry after which the client invokes the methods using the fetched objects.

Steps to create Calculator using RMI

Step 1: Create the Remote interface


First, we will create 4 interfaces(addition, subtraction, multiplication, division). These
interfaces are helpful for the operation. To create remote interfaces we need to extend
the remote interface and the method prototype within the interface should throw
the RemoteException.

Department of CSE, Ravindra College of Engineering for Women 35


Computer Networks Lab (20A05501P)

// Creating a AddInterface interface

import java.rmi.*;

public interface AddInterface extends Remote

// Declaring the method prototype

public int add(int x, int y) throws RemoteException;

// Creating a SubInterface interface

import java.rmi.*;

public interface SubInterface extends Remote

// Declaring the method prototype

public int sub(int x, int y) throws RemoteException;

// Creating a MulInterface interface

import java.rmi.*;

public interface MulInterface extends Remote

// Declaring the method prototype

public int mul(int x, int y) throws RemoteException;

// Creating a DivInterface interface

import java.rmi.*;

Department of CSE, Ravindra College of Engineering for Women 36


Computer Networks Lab (20A05501P)

public interface DivInterface extends Remote

// Declaring the method prototype

public int div(int x, int y) throws RemoteException;

Step 2: Implementation of the remote interface


Now it is time to provide implementation to all the interfaces. To implement the remote
interface, the class should extend to the UnicastRemoteObject class of the java.rmi package.
Also, a default constructor needs to be created to throw the java.rmi.RemoteException from
its parent constructor in the class.

// Java program to implement the AddInterface,


// subInterface, MulInterface, and DivInterface
import java.rmi.*;
import java.rmi.server.*;
public class Impl extends UnicastRemoteObject implements AddInterface, SubInterface,
MulInterface,DivInterface
{
// Default constructor to throw RemoteException
// from its parent constructor
Impl() throws Exception { super(); }

// Implementation of the AddInterface,


// subInterface, MulInterface, and DivInterface
public int add(int x, int y) { return x + y; }
public int sub(int x, int y) { return x - y; }
public int mul(int x, int y) { return x * y; }
public int div(int x, int y) { return x / y; }
}
Step 3: Create and execute the server application program.
The next step is to create the server application program and execute it on a separate command
prompt. The rebind method of the Naming class is used to bind the remote object to the new name.

// Program for server application


import java.rmi.*;
import java.rmi.registry.*;
public class Server
{
public static void main(String[] args) throws Exception
{

// Create an object of the interface


Department of CSE, Ravindra College of Engineering for Women 37
Computer Networks Lab (20A05501P)

// implementation class
Impl obj = new Impl();

// Binds the remote object by the name obj


Naming.rebind("rmi://localhost:6000/sonoo",obj);
System.out.println("Server Started");
}
}

Step 4: Create and execute the client application program.


The next step is to create the client application program and execute it on a separate command
prompt. The lookup method of Naming class is used to get the reference of the Stub object.
// Program for client application
import java.rmi.*;
import java.util.*;
public class Client
{
public static void main(String[] args) throws Exception
{
Scanner sc = new Scanner(System.in);
while (true) {
// User Menu
System.out.println(

"\n1.Addition\n2.Subtraction\n3.multiplication\n4.division\n5.Exit");
System.out.println("Enter the option:");
int opt = sc.nextInt();
if (opt == 5) {
break;
}
System.out.println("Enter the the first number:");
int a = sc.nextInt();
System.out.println("Enter the second number:");
int b = sc.nextInt();
int n;
switch (opt) {
case 1:
// lookup method to find reference of remote
// object
AddInterface obj=
(AddInterface)Naming.lookup("rmi://localhost:6000/s
onoo");
n = obj.add(a, b);
System.out.println("Addition= " + n);
break;
case 2:
SubInterface obj1=
Department of CSE, Ravindra College of Engineering for Women 38
Computer Networks Lab (20A05501P)

(SubInterface)Naming.lookup("rmi://localhost:6000/sonoo");
n = obj1.sub(a, b);
System.out.println("Subtraction= " + n);
break;
case 3:
MulInterface obj2=

(MulInterface)Naming.lookup("rmi://localhost:6000/sonoo");
n = obj2.mul(a, b);
System.out.println("Multiplication = " + n);
break;
case 4:
DivInterface obj3=

(DivInterface)Naming.lookup("rmi://localhost:6000/sonoo");
n = obj3.div(a, b);
System.out.println("Division = " + n);
break;
}
}
}
}

Step 5: Compile all the java program


Now we need to compile all the java program. To compile all the java program we need to
open the command prompt and enter into the respective folder. Now enter into the folder
where all the files are stored. We can compile all file at a time by using the following
command;

javac *.java

Step 6: Create a stub and skeleton


The rmic tool is used to invoke the rmi compiler that creates the Stub and Skeleton objects. Its
prototype is:

rmic Impl

Step: 7 Start the registry service by the rmiregistry tool


Now start the rmi registry service by using rmiregistry tool. We need to specify port number.
If we don’t specify the port number, it uses a default port number for example we are using
port number 6000.
rmiregistry 6000

Department of CSE, Ravindra College of Engineering for Women 39


Computer Networks Lab (20A05501P)

OUTPUT:

Department of CSE, Ravindra College of Engineering for Women 40


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 41


Computer Networks Lab (20A05501P)

Experiment 7 : Implement a Chatting application using JAVA TCP and UDP sockets..

Program:

Concept:

1. It uses TCP socket communication .We have a server as well as a client.

2. Both can be run in the same machine or different machines. If both are running in the machine, the
address to be given at the client side is local host address.

3. If both are running in different machines, then in the client side we need to specify the ip address
of machine in which server application is running.

Program:

import java.net.*;

import java.io.*;

public class chatserver { public static void main(String args[]) throws Exception

ServerSocket ss=new ServerSocket(2000);

Socket sk=ss.accept();

BufferedReader cin=new BufferedReader(new InputStreamReader(sk.getInputStream()));

PrintStream cout=new PrintStream(sk.getOutputStream());

BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));

String s;

while ( true )

s=cin.readLine();

if (s.equalsIgnoreCase("END")) { cout.println("BYE"); break;

System. out.print("Client : "+s+"\n");

Department of CSE, Ravindra College of Engineering for Women 42


Computer Networks Lab (20A05501P)

System.out.print("Server : ");

s=stdin.readLine();

cout.println(s);

ss.close();

sk.close();

cin.close();

cout.close();

stdin.close();

This is chatclient.java program

import java.net.*;

import java.io.*;

public class chatclient

public static void main(String args[]) throws Exception

Socket sk=new Socket("127.0.0.1",2000);

BufferedReader sin=new BufferedReader(new InputStreamReader(sk.getInputStream()));

PrintStream sout=new PrintStream(sk.getOutputStream());

BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));

String s; while ( true ) { System.out.print("Client : ");

s=stdin.readLine();

sout.println(s);

Department of CSE, Ravindra College of Engineering for Women 43


Computer Networks Lab (20A05501P)

s=sin.readLine();

System.out.print("Server : "+s+"\n");

if ( s.equalsIgnoreCase("BYE") )

break;

sk.close();

sin.close();

sout.close();

stdin.close();

OUTPUT: Sending chat Message from Client to Server.

Department of CSE, Ravindra College of Engineering for Women 44


Computer Networks Lab (20A05501P)

Sending chat message from Server to Client.

Department of CSE, Ravindra College of Engineering for Women 45


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 46


Computer Networks Lab (20A05501P)

Chat app is created using Java UDP Sockets


// Java program to illustrate Client side

// Implementation using DatagramSocket


import java.io.IOException;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import java.net.InetAddress;

import java.util.Scanner;

public class udpBaseClient_2

public static void main(String args[]) throws IOException

Scanner sc = new Scanner(System.in);

// Step 1:Create the socket object for

// carrying the data.

DatagramSocket ds = new DatagramSocket();

InetAddress ip = InetAddress.getLocalHost();

byte buf[] = null;

// loop while user not enters "bye"

while (true)
Department of CSE, Ravindra College of Engineering for Women 47
Computer Networks Lab (20A05501P)

String inp = sc.nextLine();

// convert the String input into the byte array.

buf = inp.getBytes();

// Step 2 : Create the datagramPacket for sending

// the data.

DatagramPacket DpSend =

new DatagramPacket(buf, buf.length, ip, 1234);

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

// the data.

ds.send(DpSend);

// break the loop if user enters "bye"

if (inp.equals("bye"))

break;

// Java program to illustrate Server side

// Implementation using DatagramSocket

import java.io.IOException;

Department of CSE, Ravindra College of Engineering for Women 48


Computer Networks Lab (20A05501P)

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import java.net.InetAddress;

import java.net.SocketException;

public class udpBaseServer_2

public static void main(String[] args) throws IOException

// Step 1 : Create a socket to listen at port 1234

DatagramSocket ds = new DatagramSocket(1234);

byte[] receive = new byte[65535];

DatagramPacket DpReceive = null;

while (true)

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

DpReceive = new DatagramPacket(receive,


receive.length);

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

ds.receive(DpReceive);

Department of CSE, Ravindra College of Engineering for Women 49


Computer Networks Lab (20A05501P)

System.out.println("Client:-" + data(receive));

// Exit the server if the client sends "bye"

if (data(receive).toString().equals("bye"))

System.out.println("Client sent bye.....EXITING");

break;

// Clear the buffer after every message.

receive = new byte[65535];

// A utility method to convert the byte array

// data into a string representation.

public static StringBuilder data(byte[] a)

if (a == null)

return null;

StringBuilder ret = new StringBuilder();

int i = 0;
Department of CSE, Ravindra College of Engineering for Women 50
Computer Networks Lab (20A05501P)

while (a[i] != 0)

ret.append((char) a[i]);

i++;

return ret;

OUTPUT:

Department of CSE, Ravindra College of Engineering for Women 51


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 52


Computer Networks Lab (20A05501P)

Experiment 8 : Hello command is used to know whether the machine at the other end is
working or not. Echo command is used to measure the round trip time to the neighbor.
Implement Hello and Echo commands using JAVA.

PROGRAM: /* Program for Hello Command using Java */

import java.io.*;
import java.net.*;
import java.util.*;
public class hello
{
public static void main(String[] args)
{
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String ipaddr;
System.out.print("Enter the IP address : ");
ipaddr = br.readLine();
boolean reachable = (java.lang.Runtime.getRuntime().exec("ping -n 1
"+ipaddr).waitFor()==0);
if(reachable)
{
System.out.println("IP is reachable:: "+ipaddr);
try
{
Process p = Runtime.getRuntime().exec("Tracert "+ipaddr);
Scanner scan = new Scanner(p.getInputStream());
while(scan.hasNextLine())
{
System.out.println(scan.nextLine());
}
}
catch(Exception ex)
{
System.out.println("Error "+ex);
}
}
else
{
System.out.println("IP is not reachable: "+ipaddr);
}
}
catch(Exception e)
{
e.printStackTrace();
}
Department of CSE, Ravindra College of Engineering for Women 53
Computer Networks Lab (20A05501P)

}
}

OUTPUT:

PROGRAM: /* Program for Echo Command using Java */

Department of CSE, Ravindra College of Engineering for Women 54


Computer Networks Lab (20A05501P)

import java.util.Scanner;

class Echo
{
public static void main (String[] args)
{
String inData;
Scanner scan = new Scanner( System.in );

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


inData = scan.nextLine();

System.out.println("You entered:" + inData );


}
}

OUTPUT:

Department of CSE, Ravindra College of Engineering for Women 55


Computer Networks Lab (20A05501P)

Experiment 9 : Using Wireshark perform the following operations:


 Inspect HTTP Traffic
 Inspect HTTP Traffic from a Given IP Address
 Inspect HTTP Traffic to a Given IP Address
 Reject Packets to Given IP Address
 Monitor Apache and MySQL Network Traffic.

Packet Sniffer :
Packet sniffer is a basic tool for observing network packet exchanges in a computer. As the name suggests,
a packet sniffer captures (“sniffs”) packets being sent/received from/by your computer; it will also
typically store and/or display the contents of the various protocol fields in these captured packets. A
packet sniffer itself is passive. It observes messages being sent and received by applications and protocols
running on your computer, but never sends packets itself.

Ethereal Packet Sniffer:


Wireshark is a free opensource network protocol analyzer. It is used for network troubleshooting and
communication protocol analysis. Wireshark captures network packets in real time and display them in
human-readable format. It provides many advanced features including live capture and offline analysis,
three-pane packet browser, coloring rules for analysis. This document uses Wireshark for the experiments,
and it covers Wireshark installation, packet capturing, and protocol analysis.
Getting Wireshark
The Kai Linux has Wireshark installed. You can just launch the Kali Linux VM and open Wireshark there.
Wireshark can also be downloaded from here:
https://www.wireshark.org/download.html

Department of CSE, Ravindra College of Engineering for Women 56


Computer Networks Lab (20A05501P)

Capturing Packets
After downloading and installing Wireshark, you can launch it and click the name of an interface under
Interface List to start capturing packets on that interface. For example, if you want to capture traffic on
the wireless network, click your wireless interface.
Test Run
Do the following steps:
1. Start up the Wireshark program (select an interface and press start to capture packets).
2. Start up your favorite browser (ceweasel in Kali Linux).
3. In your browser, go to Wayne State homepage by typing www.wayne.edu.
4. After your browser has displayed the http://www.wayne.edu page, stop Wireshark packet capture by
selecting stop in the Wireshark capture window. This will cause the Wireshark capture window to
disappear and the main Wireshark window to display all packets captured since you began packet Capture
5. Color Coding: You’ll probably see packets highlighted in green, blue, and black. Wireshark uses colors
to help you identify the types of traffic at a glance. By default, green is TCP traffic, dark blue is DNS
traffic, light blue is UDP traffic, and black identifies TCP packets with problems — for example, they
could have been delivered out-of-order.
6. You now have live packet data that contains all protocol messages exchanged between your computer
and other network entities! However, as you will notice the HTTP messages are not clearly shown
because there are many other packets included in the packet capture.
7. To further filter packets in Wireshark, we need to use a more precise filter. By setting the
http.host==www.wayne.edu, we are restricting the view to packets that have as an http host the
www.wayne.edu website.
Output:

Department of CSE, Ravindra College of Engineering for Women 57


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 58


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 59


Computer Networks Lab (20A05501P)

Experiment 10 : Install Network Simulator 2/3. Create a wired network using dumbbell topology.
Attach agents, generate both FTP and CBR traffic, and transmit the traffic. Vary the data rates
and evaluate the performance using metric throughput, delay, jitter and packet loss.

Figure : A Simple Network Topology

Explanation:

This network consists of 4 nodes (n0, n1, n2, n3) as shown in above figure. The duplex links between n0 and n2,
and n1 and n2 have 2 Mbps of bandwidth and 10 ms of delay. The duplex link between n2 and n3 has 1.7 Mbps
of bandwidth and 20 ms of delay. Each node uses a DropTail queue, of which the maximum size is 10. A "tcp"
agent is attached to n0, and a connection is established to a tcp "sink" agent attached to n3. As default, the
maximum size of a packet that a "tcp" agent can generate is 1KByte. A tcp "sink" agent generates and sends
ACK packets to the sender (tcp agent) and frees the received packets. A "udp" agent that is attached to n1 is
connected to a "null" agent attached to n3. A "null" agent just frees the packets received. A "ftp" and a "cbr"
traffic generator are attached to "tcp" and "udp" agents respectively, and the "cbr" is configured to generate 1

Department of CSE, Ravindra College of Engineering for Women 60


Computer Networks Lab (20A05501P)

KByte packets at the rate of 1 Mbps. The "cbr" is set to start at 0.1 sec and stop at 4.5 sec, and "ftp" is set to
start at 1.0 sec and stop at 4.0 sec.

Department of CSE, Ravindra College of Engineering for Women 61


Computer Networks Lab (20A05501P)

Creating the Agent

Department of CSE, Ravindra College of Engineering for Women 62


Computer Networks Lab (20A05501P)

Experiment 11 : Create a static wireless network. Attach agents, generate both FTP and CBR
traffic, and transmit the traffic. Vary the data rates and evaluate the performance using metric
throughput, delay, jitter and packet loss.

Department of CSE, Ravindra College of Engineering for Women 63


Computer Networks Lab (20A05501P)

Creating the Agent

Department of CSE, Ravindra College of Engineering for Women 64


Computer Networks Lab (20A05501P)

Experiment 12: Create a mobile wireless network. Attach agents, generate both FTP and CBR
traffic, and transmit the traffic. Vary the data rates and evaluate the performance using metric
throughput, delay, jitter and packet loss.

Department of CSE, Ravindra College of Engineering for Women 65


Computer Networks Lab (20A05501P)

Creating the Agent

Department of CSE, Ravindra College of Engineering for Women 66


Computer Networks Lab (20A05501P)

Additional Program 1: Cisco Switch and Router Configuration basic commands in Packet
Tracer.

Cisco Switch Configuration basic commands


A switch is a layer 2 device used to forward packet from one device to another within the
network. It forwards the packet through one of its ports on the basis of destination MAC
address and the entry in the MAC table.
Following basic commands are used to configure a new switch :
1. Changing the hostname of a switch to GfgSwitch :
It is used to set the name of the device.
switch(config)#hostname GfgSwitch
GfgSwitch(config)#
2. To add a banner message :
It provides a short message to the user who wants to access the switch.
GfgSwitch(config)#banner motd &
Enter Text message. End with character '&'
$ This is GeeksforGeeks floor Switch &
. To set IP address in Switch :
IP address is the address of device in network.
GfgSwitch(config)#interface vlan1
GfgSwitch(config-if)#ip address 172.16.10.1 255.255.255.0
GfgSwitch(config-if)#exit
GfgSwitch(config)#ip default-gateway 172.16.10.0
4. To set the current clock time :
This is set the current time stored in the switch.
GfgSwitch#clock set 3:03:14 June 25 2020
5. Apply password protection (enable password, secret password, console password and
vty password) :
 Enable password :
The enable password is used for securing privilege mode.
GfgSwitch(config)#enable password GFGGFG
 Enable secret password :
This is also used for securing privilege mode but the difference is that it will be
displayed as ciphertext(***) on the configuration file.
GfgSwitch(config)#enable secret GFGGFG

Department of CSE, Ravindra College of Engineering for Women 67


Computer Networks Lab (20A05501P)

 Line console password :


When a person will take access through console port then this password will be
asked.
GfgSwitch(config)#line console 0
GfgSwitch(config-line)#password GFG
GfgSwitch(config-line)#login
 Line VTY password :
When a person want to access a router through VTY lines (telnet or ssh) then this
password will be asked.
GfgSwitch(config)#line VTY 0 2
GfgSwitch(config-line)#password GFGGFG
GfgSwitch(config-line)#exit
6. Copy to startup-configuration file from running-configuration file :
GfgSwitch#copy running-config startup-config
7. To watch startup-configuration file and running-configuration file :
GfgSwitch#show startup-config
GfgSwitch#show running-config
8. Clear mac address table :
Switch stores MAC addresses in MAC address table
GfgSwitch#clear mac address-table

Basic Router Configuration


Purpose
Command
Step 1 configure terminal Enters global configuration mode, when using
Example: the console port.
Router> enable
Router# configure terminal
Step 2 hostname name Specifies the name for the router.
Example:
Router(config)# hostname
Router
Step 3 enable secret password Specifies an encrypted password to prevent
Example: unauthorized access to the router.
Router(config)# enable
secret cr1ny5ho

Department of CSE, Ravindra College of Engineering for Women 68


Computer Networks Lab (20A05501P)

Step 4 no ip domain-lookup Disables the router from translating unfamiliar


Example: words (typos) into IP addresses.
Router(config)# no ip
domain-lookup

Department of CSE, Ravindra College of Engineering for Women 69


Computer Networks Lab (20A05501P)

Additional Program 2: Setting up a Basic Home Network using Packet Tracer.

Setting up a Basic Home Network using Packet Tracer

Packet Tracer is a network simulation tool that allows us to create network topologies by
building virtual networking devices. Packet Tracer is highly encouraged for network
enthusiasts as it allows them to have keen in-depth knowledge of networking. Let us see how
to easily create a simple home network using Packet Tracer.
Step-1:
Open Packet Tracer and pick Home Router from Wireless Devices and place it on the
workspace.

Step-2:
Place Smartphone, PC, Laptop from End Devices on Workspace.

Department of CSE, Ravindra College of Engineering for Women 70


Computer Networks Lab (20A05501P)

Notice that Smartphone automatically connects to the home router after placing it on the
workspace

Step-3:
Connect the pc to the home router by using Copper Cross-Over wire available from
Connections by configuring pc to FastEthernet0 and Home Router to GigabitEthernet 1.

Department of CSE, Ravindra College of Engineering for Women 71


Computer Networks Lab (20A05501P)

Step-4:
To connect Laptop to Home Router we need to update a pin in the laptop’s configuration, to do
this click on the laptop and turn of the laptop and find the pin WPC300N and place it in the
laptop.
Note : To update the pin with WPC300N, the laptop must be turned off.

Department of CSE, Ravindra College of Engineering for Women 72


Computer Networks Lab (20A05501P)

Department of CSE, Ravindra College of Engineering for Women 73

You might also like