0% found this document useful (0 votes)
185 views

College of Engineering &technology: Mahatma Gandhi Mission's

The document lists practical experiments related to computer networks. It includes experiments on networking hardware configuration, using networking commands, network packet analysis, socket programming, routing algorithms, and more.

Uploaded by

Bhaiya G ff
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)
185 views

College of Engineering &technology: Mahatma Gandhi Mission's

The document lists practical experiments related to computer networks. It includes experiments on networking hardware configuration, using networking commands, network packet analysis, socket programming, routing algorithms, and more.

Uploaded by

Bhaiya G ff
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/ 67

Mahatma Gandhi Mission’s

College of Engineering &Technology


Computer Networks Lab
KCS-653
LIST OF PRACTICALS

S. No. TITLE

1. To learn handling and configuration of networking hardware like


RJ- 45 connector, CAT-6 cable, crimping tool, etc.

2. Configuration of router, hub, switch etc. (using real devices or


simulators)

3. Running and using services/commands like ping, trace route, ns


lookup, arp, telnet, ftp, etc.

4. Network packet analysis and simulation using tools like Wireshark,


tcpdump, Cisco Packet Tracer, NetSim, OMNeT++, NS2, NS3, etc.

5. Socket programming using UDP and TCP (e.g., simple DNS, data &
time client/server, echo client/server, iterative & concurrent servers.

6. Programming using raw sockets.

7. To implement the program using RPC/RMI


8. Write a code simulating Ping and Trace-route commands

9. Create a Socket for HTTP for webpage upload and download.

10. To perform case study for different routing algorithms to select the
network path using LINK STATE ROUTING b) FLOODING c)
DISTANCE VECTOR.

11. Implementation of Stop and Wait Protocol and Sliding Window Protocol

12. Implement Subnetting to generate Range of IP Addresses.

13. To implement socket programming date and time display from client to server
using TCP and UDP Sockets.

14. To Study of Network simulator and Simulation of Congestion


Control Algorithms using NS.

15. Applications using TCP Sockets like a. Echo client and echo server
b. Chat c. File Transfer.

16. Applications using TCP and UDP Sockets like DNS, SNMP, File Transfer
EXPERIMENT NO.-01
Aim: To learn handling and configuration of networking hardware like RJ-
45 connector, CAT-6 cable, crimping tool, etc.
Description:
RJ-45 (Registered Jack): The acronym for Registered Jack-45 is RJ-45. The RJ-45 connector
is an eight-wire connector that is commonly used to connect computers to a local area network
(LAN), particularly Ethernet LANs. Although they are slightly larger than the more commonly
used RJ-11 connectors, RJ-45s can be used to connect some types of telephone equipment.

RJ-45 can be easily crimped to a cable with or without a crimping tool. If you have a crimping
tool, strip away a portion of the sheath, untangle and arrange the wires in the correct order, fit
them into the connector, and use the crimping part of your tool to squeeze the small pins into
the wires and secure the connector. If you don’t have a crimping tool, no problem! Use a pair
of scissors or a utility knife to cut away a section of the sheathing at the end of the cable, untwist
and arrange the small cables in the right order, put them into the RJ-45 connector, and use a
small, flathead screwdriver to press down each of the pins.
Pre-Experiment:
(i) What is the use of RJ-45 connector and CAT cables in computer
networking?
(ii) How is crimping tool used to connect devices like RJ-45, CAT- cable-6 etc?

Method:
Using a crimping tool: Strip the cable back 1 inch (25 mm) from the end. Insert the cable
into the stripper section of the tool and squeeze it tight. Then, rotate the crimping tool around
the cable in a smooth and even motion to create a clean cut. Keep the tool clamped and pull
away towards the end of the wire to remove the sheathing.[1]
The stripping section is a round hole near the handle of the tool.
The sheathing should come off cleanly, leaving the wires exposed
2. Untwist and straighten the wires inside of the cable. Inside of the cable you’ll see a bunch
of smaller wires twisted together. Separate the twisted wires and straighten them out so they’re
easier to sort into the right order.[2]
Cut off the small plastic wire separator or core so it’s out of the way.
Don’t cut off or remove any of the wires or you won’t be able to crimp them into the connector.

3. Arrange the wires into the right order. Use your fingers to put the wires in the correct
order so they can be properly crimped. The proper sequence is as follows from left to right:
Orange/White, Orange, Green/White, Blue, Blue/White, Green, Brown/White, Brown.[3]
• There are 8 wires in total that need to be arranged in the right sequence.
• Note that the wires labeled Orange/White or Brown/White indicate the small wires that have 2
colors.
4. Cut the wires into an even line 1⁄2 inch (13 mm) from sheathing. Hold the wires with your
thumb and index finger to keep them in order. Then, use the cutting section of the crimping
tool to cut them into an even line.[4]
The cutting section of the tool will resemble wire cutters.
The wires must be in an even line to be crimped into the RJ-45 connector properly. If you cut
them in an uneven line, move further down the wires and cut them again.
5. Insert the wires into the RJ-45 connector. Hold the RJ-45 connector so the clip is on the
underside and the small metal pins are facing up. Insert the cable into the connector so that
each of the small wires fits into the small grooves in the connector.
• The sheathing of the cable should fit just inside of the connector so it’s past the base.
If any of the small wires bend or don’t fit into a groove correctly, take the cable out and
straighten the wires with your fingers before trying again.
The wires must be inserted in the correct order and each wire must fit into a groove before you
crimp the connector.

6. Stick the connector into the crimping part of the tool and squeeze twice. Insert the
connector in the crimping section of the tool until it can’t fit any further. Squeeze the handles
to crimp the connector and secure the wires. Release the handles, then squeeze the tool again
to make sure all of the pins are pushed down.
The crimping tool pushes small pins in the grooves down onto the wires to hold and connect
them to the RJ-45 connector.
7. Remove the cable from the tool and check that all of the pins are down. Take the
connector out of the tool and look at the pins to see that they’re all pushed down in an even
line. Lightly tug at the connector to make sure it’s attached to the cable.[7]
If any of the pins aren’t pushed down, put the wire back into the crimping tool and crimp it
again.
EXPERIMENT NO.-02
Aim: Configuration of router, hub, switch etc. (using real devices or
simulators)
Pre-Experiment Questions:
(i) What is the functionality of basic physical layer devices like
repeater, hub, switch etc.?
(ii) What are the pre-requisites for the connection of basic physical
layer devices?
Description:
1. 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
2. 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.

3. Switch: A network 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) ar often referred to as Layer 3 switches or multilayer
switches.
4. 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.
5. 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.

5. 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.
EXPERIMENT NO.-03
Aim: Running and using services/commands like ping, trace route, ns lookup, arp, telnet,
ftp, etc.
Description:
1. Scripting Language (Tcl - Tool Command Language and pronounced tickle)
2. System Programming Language (C/C++)
5) C++ defines the internal mechanism (a backend) of the Simulation objects also the
simulation kernel is implemented using C++.
6) OTcl sets up simulation by assembling and configuring the objects as well as scheduling
discrete events (i.e., a frontend). The Tcl scripting language is used to express the definition,
configuration and the control of the simulation.
7) The C++ and the OTcl are linked together using TclCL.
Simple Network Topology and Simulation Scenario

Algorithm/Syntax:

set ns [new Simulator] # Letter S is capital


set nf [open PA1.nam w] # open a nam trace file in write mode
$ns namtrace-all $nf # nf nam filename
set tf [open PA1.tr w] # tf trace filename
$ns trace-all $tf

proc finish { } {
global ns nf tf
$ns flush-trace # clears trace file contents
close $tf
exec nam PA1.nam &
exit 0
}
set n0 [$ns node] # creates 3 nodes
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n2 200Mb 10ms DropTail # establishing links
$ns duplex-link $n2 $n3 1Mb 1000ms DropTail
$ns queue-limit $n0 $n2 10

set udp0 [new Agent/UDP] # attaching transport layer protocols


$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR] # attaching application layer protocols
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

set null0 [new Agent/Null] # creating sink(destination) node


$ns attach-agent $n3 $null0
$ns connect $udp0 $null0

$ns at 0.1 "$cbr0 start" $ns


at 1.0 "finish"
$ns run

AWK file: (Open a new editor using “vi command” and write awk file and save with “.awk”
extension) #immediately after BEGIN should open braces „{„

BEGIN{ c=0;}
{
if($1= ="d")
{ c++;
printf(
"%s\t
%s\n",
$5,$11)
;
}
}
END{ printf("The number of packets dropped =%d\n",c); }
Steps for execution:

Open vi editor and type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# vi lab1.tcl

Save the program by pressing “ESC key” first, followed by “Shift and :” keys
simultaneously and type “wq” and press Enter key.
Open vi editor and type awk program. Program name should have the extension “.awk

[root@localhost ~]# vi lab1.awk

Save the program by pressing “ESC key” first, followed by “Shift and :” keys

simultaneously and type “wq” and press Enter key.


Run the simulation program

[root@localhost~]# ns lab1.tcl

Here “ns” indicates network simulator. We get the


topology shown in the snapshot. Now press the play button
in the simulation window and the simulation will begins.
After simulation is completed run awk file to see the output
,
[root@localhost~]# awk –f lab1.awk lab1.tr
To see the trace file contents open the file as ,
[root@localhost~]# vi lab1.tr

Trace file contains 12 columns:


Event type, Event time, From Node, To Node, Packet Type, Packet Size, Flags (indicated by
--------), Flow ID, Source address, Destination address, Sequence ID, Packet ID
SIMULATION STEPS :
The followings show the three key step guideline in defining a simulation scenario in a NS2:
1. Simulation Design The first step in simulating a network is to design the simulation. In
this step, the users should determine the simulation purposes, network configuration and
assumptions, the performance measures, and the type of expected results
2. Configuring and Running Simulation This step implements the design in the first step.
It consists of two phases: a) Network configuration phase: In this phase network components
(e.g., node, TCP and UDP) are created and configured according to the simulation design. Also,
the events such as data transfer are scheduled to start at a certain time. b) Simulation Phase:
This phase starts the simulation which was configured in the Network Configuration Phase. It
maintains the simulation clock and executes events chronologically. This phase usually runs
until the simulation clock reached a threshold value specified in the Network Configuration
Phase.
EXPERIMENT NO.-4
AIM: Network packet analysis and simulation using tools like Wireshark, tcpdump, Cisco
Packet Tracer, NetSim, OMNeT++, NS2, NS3, etc.
Description: Analysis of Simulation tools like Wireshark, tcpdump, Cisco Packet Tracer,
NetSim, OMNeT++, NS2, NS3, etc.
Pre-Experiment Questions:
(i) State the main aspects of simulation of network analysis tools?
CISCO PACKET TRANSFER
1. The robust simulation tool used to visualize networks.
Packet Tracer provides valuable tips and best practices for using Cisco Packet
Tracer.
Learn the basic operations of Packet Tracer: - File commands, visualization and
configuration of networking devices.
Simulate the interactions of data traveling through the network.
Learn to visualize the network in logical and physical modes.
Reinforce your understanding with extensive hands-on networking and IoT
activities.
7. Get immediate feedback on your work through built-in quizzes and tests.
8. Connect with the global Cisco Networking Academy community.

System requirement

The following configuration is recommended by Cisco to successfully install and run Packet
Tracer 7.0 :

Microsoft Windows (7 / 8.1 / 10) or Linux Ubuntu (14.04 64-bits)

At least Pentium 4 (2.5 GHz)

A minimum of 2GB RAM (4GB recommended)

700 MB of storage space

A minimum screen resolution of 1024 x 768


NS-2/NS-3
1. ns (from network simulator) is a name for a series of discrete event network simulators,
specifically ns-1, and ns-2.
2. All of them are discrete-event computer network simulators, primarily used in
research[2] and teaching.

System Requirements

Summary

Packet Tracer is a cross-platform visual simulation tool designed by Cisco Systems that
allows users to create network topologies and imitate modern computer networks. The
software allows users to simulate the configuration of Cisco routers and switches using
a simulated command line interface.
Packet Tracer is a cross-platform visual simulation tool designed by Cisco Systems that
allows users to create network topologies and imitate modern computer networks. The
software allows users to simulate the configuration of Cisco routers and switches using
a simulated command line interface. Packet Tracer makes use of a drag and drop user
interface, allowing users to add and remove simulated network devices as they see fit.
The software is mainly focused towards Certified Cisco Network Associate Academy
students as an educational tool for helping them learn fundamental CCNA concepts.

1. Linux (x86 and x86_64): gcc/g++ versions 4.9 and above

2. Note: If you are using RHEL or Centos, you will likely need to install a more up-

to- date compiler than the default; search for how to enable 'software collections' or

'devtoolset' on these distributions. Other Linux distributions typically have a suitable

default compiler (at least version 4.9).


3. MacOS Apple LLVM: version 8.0.0 and above (version 7.0.0 may work)

4. FreeBSD and Linux (x86_64): clang/LLVM version 3.9 and above (older versions

down to 3.3 may work)


5. The minimum Python version supported is 2.7 or greater (version 2), or version 3.4
or greater (version 3).

Summary

Ns3
ns-3 has been developed to provide an open, extensible network simulation platform, for
networking research and education. In brief, ns-3 provides models of how packet data
networks work and perform, and provides a simulation engine for users to conduct
simulation experiments. Some of the reasons to use ns-3 include to perform studies that are
more difficult or not possible to perform with real systems, to study system behavior in a
highly controlled, reproducible environment, and to learn about how networks work.

Ns2
It is not possible to run a simulation in ns-2 purely from C++ (i.e., as a main() program
without any OTcl). Moreover, some components of ns-2 are written in C++ and others in
OTcl. In ns-3, the simulator is written entirely in C++, with optional Python bindings.
Simulation scripts can therefore be written in C++ or in Python. New animators and
visualizers are available and under current development. Since ns-3 generates pcap packet
trace files, other utilities can be used to analyze traces as well.

WIRESHARK
1. Wireshark is a network packet analyzer. A network packet analyzer will try to capture
network packets and tries to display that packet data as detailed as possible.

2. You could think of a network packet analyzer as a measuring device used to examine
what’s going on inside a network cable, just like a voltmeter is used by an electrician
to examine what’s going on inside an electric cable (but at a higher level, of course).
3. Wireshark is perhaps one of the best open source packet analyzers available today.

System Requirements

The amount of resources Wireshark needs depends on your environment and on the size of the
capture file you are analyzing. The values below should be fine for small to medium-sized
capture files no more than a few hundred MB. Larger capture files will require more memory
and disk space.If Wireshark runs out of memory it will crash.
1. Microsoft Windows
2. Unix/Linux

OmNet++

1. OMNeT++ is an extensible, modular, component-based C++ simulation library


and framework, primarily for building network simulators.
2. "Network" is meant in a broader sense that includes wired and wireless communication
networks, on-chip networks, queueing networks, and so on.
3. Domain-specific functionality such as support for sensor networks, wireless ad-hoc
networks, Internet protocols, performance modeling, photonic networks, etc., is
provided by model frameworks, developed as independent projects. OMNeT++ offers
an Eclipse-based IDE, a graphical runtime environment, and a host of other tools.
4. There are extensions for real-time simulation, network emulation, database integration,
SystemC integration, and several other functions.
5. Although OMNeT++ is not a network simulator itself, it has gained widespread
popularity as a network simulation platform in the scientific community as well as in
industrial settings, and building up a large user community.

System Requirements

1. simulation kernel library


2. NED topology description language
3. GUI for simulation execution, links into simulation executable (Tkenv)
4. command-line user interface for simulation execution (Cmdenv)
5. utilities (makefile creation tool, etc.)
6. documentation, sample simulations, etc.
7. OMNeT++ IDE based on the Eclipse platform

Summary

OverSim is an OMNeT++-based open-source simulation framework for overlay and peer-to-


peer networks, developed at the Institute of Telematics, Karlsruhe Institute of Technology,
Germany.
The simulator contains several models for structured (e.g. Chord, Kademlia, Pastry) and
unstructured (e.g. GIA) peer-to-peer protocols. An example implementation of the framework
is an implementation of a peer-to-peer SIP communications network.

Research tool- OverSim provides a convenient platform for simulating large-scale complex
overlay protocols and applications. Though it can be overwhelming at first, you will realize its
power when you develop a better understanding of the tool.

Packet Sniffing with color coding scheme using Wireshark Simulator

Introduction
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.
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.
STEPS FOR CAPTURING THE PACKETS
1. Start up the Wireshark program (select an interface and press start to capture packets).
2. After the browser has been displayed click stop button through the capture link in the
Wireshark capture window.

3. Now , the Wireshark capture window disappears and the main Wireshark window displays
all packets captured since the time we began packet capture
Color Coding: After implementing the steps 1, 2, 3 mentioned above we’ll see packets
highlighted in green, blue, and black. Wireshark uses colors to help 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.
Simulation of LAN topologies using CISCO Packet Tracer
Steps for creating a topology

1. Open your Network Topology. Once you've opened your Network Topology on Cisco
Packet Tracer, access your network and identify the components of your network, for
example; Servers, Routers, End Devices, etc.
2. Complete the cabling. Access the cables section and connect completely and correctly
the cables between the network in order to ensure connectivity between the devices in
the network using the connections table given.
3. Using the address table still, correctly and completely configure the IP addresses on all
end devices. This can be done by accessing the desktop platform on each device and
locating the IP configuration section. The reason for doing this is to enable the devices
be on the right network.
4. After configuring the addresses, you will have to test connectivity by opening a
command prompt window on the end devices and try pinging the address which the
network operates on. If it gives you a reply, it means your network was configured
correctly.

Simulating network devices


Simulating generic switches
Establish the links between the network devices and generic switches

Connect the links


Enter the IP address to each network devices
EXPERIMENT NO.-05
AIM: Socket programming using UDP and TCP (e.g., simple DNS, data & time
client/server, echo client/server, iterative & concurrent servers.
Description: To compute date and time from local host using transmission control
protocol.
Pre-experiment Question
Q.1 What is socket address?
Q.2 How to establish a connection from client to server using TCP.
Algorithm/Syntax:
CLIENT
1. Start the program
2. Include necessary package in java
3. To create a socket in client to server.
4. The client connection accept to the server and replay to read the system date and
time.
5. Stop the program.

SERVER
INPUT: Insert a client request
1. Start the program
2. Include necessary package in java
3. To create a socket in server to client.
4. To display the current date and time to client
5. Stop the program
OUTPUT:
CLIENTSIDE:
C:\Program Files\Java\jdk1.5.0\bin>javac dateclient.java
Note: dateclient.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details. C:\Program
Files\Java\jdk1.5.0\bin>java dateclient
THE date in the server is:Sat Jul 19 13:01:16 GMT+05:30 2008
C:\Program Files\Java\jdk1.5.0\bin>
SERVERSIDE:
C:\Program Files\Java\jdk1.5.0\bin>javac dateserver.java
Note: dateserver.java uses or overrides a deprecated API. Note:
Recompile with -deprecation for details.
C:\Program Files\Java\jdk1.5.0\bin>java dateserver
THE CLIENT SYSTEM ADDRESS IS: com17/192.168.21.17
EXPERIMENT NO.-06

Aim: Programming using raw sockets.

Description: There are two types of Internet Protocol (IP) traffic. They are
TCP or Transmission Control Protocol and UDP or User Datagram Protocol. TCP is
connection oriented – once a connection is established, data can be sent bidirectional. UDP is
a simpler, connectionless Internet protocol. Multiple messages are sent as packets in chunks
using UDP.

Algorithm/Syntax:
set ns [new Simulator] set nf [open
lab2.nam w] $ns namtrace-all $nf

set tf [open lab2.tr w] $ns trace-all


$tf

proc finish { } { global ns nf tf $ns


flush-trace close $nf
close $tf
exec nam lab2.nam & exit 0

}
set n0 [$ns node] set n1 [$ns node]
set n2 [$ns node] set n3 [$ns node]
$ns duplex-link $n0 $n2
10Mb 1ms DropTail $ns
duplex-link $n1 $n2
10Mb 1ms DropTail $ns
duplex-link $n2 $n3
10Mb 1ms DropTail

set tcp0 [new Agent/TCP] # letters A,T,C,P are capital

$ns attach-agent $n0 $tcp0


set udp1 [new Agent/UDP] # letters A,U,D,P are capital

$ns attach-agent $n1 $udp1


set null0 [new Agent/Null] # letters A and N are capital

$ns attach-agent $n3 $null0


set sink0 [new Agent/TCPSink] # letters A,T,C,P,S are capital

$ns attach-agent $n3 $sink0


set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1


$ns connect $tcp0 $sink0
$ns connect $udp1 $null0
$ns at 0.1 "$cbr1 start"
$ns at 0.2 "$ftp0 start"
$ns at 0.5 "finish"
$ns run

AWK file: (Open a new editor using “vi command” and write awk file and save with “.awk”
extension)
BEGIN{
udp=0;
tcp=0;
}
{
if($1= = “r” && $5 = = “cbr”)

udp++;
}
else if($1 = = “r” && $5 = = “tcp”)

{ tcp++;
}

}
END{
printf(“Number of packets sent by
TCP = %d\n”, tcp);
printf(“Number of packets sent by
UDP=%d\n”,udp);

}
Steps for execution:
Open vi editor and type program. Program name should have the extension “ .tcl ”
[root@localhost ~]# vi lab2.tcl
Save the program by pressing “ESC key” first, followed by “Shift and :” keys simultaneously
and type “wq” and press Enter key.
Open vi editor and type awk program. Program name should have the extension “.awk ”
[root@localhost ~]# vi lab2.awk
Save the program by pressing “ESC key” first, followed by “Shift and :” keys
simultaneously and type “wq” and press Enter key.
Run the simulation program :
[root@localhost~]# ns lab2.tcl
o Here “ns” indicates network simulator. We get the topology shown in the
snapshot.
o Now press the play button in the simulation window and the simulation will
begins.
After simulation is completed run awk file to see the output ,
[root@localhost~]# awk –f lab2.awk lab2.tr
To see the trace file contents open the file as ,
[root@localhost~]# vi lab2.tr

Topology Output
EXPERIMENT NO.-07
AIM: To implement the program using RPC/RMI

Description: RPC (Remote Procedure Call) and RMI (Remote Method Invocation)
are two mechanisms that allow the user to invoke or call processes that will run on a
different computer from the one the user is using. The main difference between the two
is the approach or paradigm used. RMI uses an object-oriented paradigm where the user
needs to know the object and the method of the object he needs to invoke.

Pre-experiment Question:
Q.1W hat is the method that is used by the RMI client to connect to remote RMI servers?

Q.2 What is the relationship between the RMI and CORBA?

Algorithm/Syntax:
1. Start the program and to include necessary packages
2. Using Add client to get the two values
3. Using Add server() to implement and Call the Add server impl
4.Usingpublic interface to call the program in remotely
5.Finally to call and compile all the sub program
6.To Execute Start RMI registry
7.Stop the program
INPUT :
Insert the client request for RPC.

OUTPUT :
EXPERIMENT NO.-08
Aim: Write a code simulating Ping and Trace-route commands

Description:

The ping command is a very common method for troubleshooting the


accessibility of devices.It uses a series of Internet Control Message Protocol
(ICMP) Echo messages to determine:
• Whether a remote host is active or inactive.
• The round-trip delay in communicating with the host.
• Packet loss.
The ping command first sends an echo request packet to an address, and then
waits for a reply.The ping is successful only if:
• the echo request gets to the destination, and
• The destination is able to get an echo reply back to the source within a
predetermined time calleda timeout. The default value of this timeout is two
seconds on Cisco routers.

TRACEROUTE Command
1. The trace route command is used to discover the routes that packets actually take when
traveling to their destination. The device (for example, a router or a PC) sends out a
sequence of User Datagram Protocol (UDP) data grams to an invalid port address at the
remote host.

2. Three data grams are sent, each with a Time-To-Live (TTL) field value set to one. The
TTL value of1 causes the datagram to "timeout" as soon as it hits the first router in the
path; this router then responds with an ICMP Time Exceeded Message (TEM)
indicating that the datagram has expired.

3. Another three UDP messages are now sent, each with the TTL value set to 2, which
causes the second router to return ICMP TEMs. This process continues until the packets
actually reach the other destination.

4. Since these data grams are trying to access an invalid port at the destination host, ICMP
Port Unreachable Messages are returned, indicating an unreachable port; this event
signals the Trace route program that it is finished.
Pre-experiment Questions:
1. Dose ping can measure round trip time?

2. What is ping sweep to trace the path from source to destination?

4. Difference between traceroute and ping.

5.What utility is used to find the number of routers between a source and destination?

Algorithm:

Server
Step1: Start the program.
Step2: Import necessary packages.
Step3: Initialize the ping server with both sockets as null value.
Step4: Start the server socket.
Step5: At the client give the IP address of the server(by using ifconfig command in
command prompt).
Step6: The client program is then started by
starting socket.Step7: At the receiver end, the
client is pinged and traced. Step8: Stop the
program.

Client
Step1: Start the program.
Step2: Import necessary packages.
Step3: Initialize the ping client with both sockets as null value.
Step4: Start the socket.
Step5: Get the IP address of the server.
Step6: Ping the server.
Step7: At the receiver end, the server is pinged and traced.
Step8: Stop the program.
Sample code:
pingclient.java

/*…localhostport name and 5555-port number…*/


Socket s=new Socket("127.0.0.1",5555);

/*… Get an input file handle from the socket and read
the input…*/DataInputStream dis=new
DataInputStream(s.getInputStream()); PrintStream out=new
PrintStream(s.getOutputStream()); while(c<4)
{

/*…returns the current time in milliseconds…*/


t1=System.currentTimeMillis();
str="Welcome to network
programming world";out.println(str);

/*…readline() method read a line


of text…*/
System.out.println(dis.readLine());
t2=System.currentTimeMillis();
System.out.println(";TTL="+(t2-
t1)+"ms"); c++;

pingserver.java

/*…ServerSocket object is used to establish the communication with clients…*/


ServerSocketss=new ServerSocket(5555);

/*…accept(): Used to accept the client request…*/


Socket
s=ss.accept
();int c=0;
while(c<4)
{

/*… Get an input file handle from the socket and read
the input…*/DataInputStream dis=new

DataInputStream(s.getInputStream()); PrintStream out=new


PrintStream(s.getOutputStream());

/*…readline() method read a line of text…*/


String str=dis.readLine();
out.println("Reply from"+InetAddress.getLocalHost()+";Length"+str.length()); c++;

Sample Output:

Output:

Thus program for implementing ping and trace route command was executed
successfully.
EXPERIMENT NO.-09

Aim: Create a Socket for HTTP for webpage upload and download.

Objective:
To write a java program for creating socket for HTTP web page upload and
download.

Description:

HTTP

1. The Hypertext Transfer Protocol (HTTP) is a protocol used mainly to access data on
the www.
2. HTTP functions as a combination of FTP and SMTP.
3. SMTP messages are stored and forwarded, but HTTP messages are delivered
immediately.
4. The commands from the client to the server are embedded in a request message.
The contents of therequested file or other information are embedded in a response
message.

Pre-Experiment questions:

1. What is HTTP and WWW?


2. To which OSI layer does IP belong?
3. What HTTP response headers do?
4. What is HTTP session state?
5. What is Secure HTTP?

Algorithm:

Step1: Set a server port as 80.


Step2: Using HTTP services create a Socket for server by specifying the server port
Step3: Use HTTP socket for connecting the client to the URL.
Step4: Use BufferedReader to output stream to place the response from the server by the
client.
Step5: Close the Connection as soon the request is been serviced. Use Malformed
URL exceptionIf any errors in grabbing the server

Sample
Program:
Client.java

/* …create file
object…*/
importjava.io.File;
importjava.io.IOExc
eption;

/*…used to perform read and write operation…*/


importjavax.imageio.ImageIO;

public class Client{


public static void main(String args[]) throws
Exception{Socket soc;
BufferedImageimg =
null; soc=new
Socket("localhost",4000
);
System.out.println("Client is
running. ");try {
System.out.println("Reading image from disk. ");

/*…read image file…*/


img = ImageIO.read(new File("kalpanasonika.jpg"));
ByteArrayOutputStreambaos = new
ByteArrayOutputStream();

/*…write image
file…*/
ImageIO.write(img,
"jpg", baos);
baos.flush();

/*…we use toByteArray() method of ByteArrayOutputStream class…*/


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. ");

Server.java
//…Create Server
Socket…//
ServerSocket
server=null; Socket
socket;
//…Register Service port to
4000…// 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);intlen =
dis.readInt();
System.out.println("Image Size: " + len/1024
+ "KB");byte[] data = new byte[len];
dis.readFully(data);
//…method is used to request for closing or terminating an object…//
dis.close();
in.close();
InputStreamian = new
ByteArrayInputStream(data);
BufferedImagebImage =
ImageIO.read(ian);
//…create a frame window entitled “server”…//
JFrame f = new
JFrame("Server"); ImageIcon
icon = new
ImageIcon(bImage);

Sample Output:
Output:
Thus program for creating sockets for HTTP web page upload and
download was implemented.
EXPERIMENT NO.-10
Aim: To perform case study for different routing algorithms to select the network path using
LINK STATE ROUTING b) FLOODING c) DISTANCE VECTOR.
Description:

Link State routing

Routing is the process of selecting best paths in a network. In the past, the term
routing was also used to mean forwarding network traffic among networks. However, this
latter function is muchbetter described as simply forwarding. Routing is performed for
many kinds of networks, including the telephone network (circuit switching), electronic
data networks (such as the Internet), and transportation networks. This article is concerned
primarily with routing in electronic data networks using packet switching technology. In
packet switching networks, routing directs packet forwarding (the transit of logically
addressed network packets from their source toward their ultimate destination) through
intermediate nodes. Intermediate nodes are typically network hardware devices such as
routers, bridges, gateways, firewalls, or switches. General-purpose computers can also
forward packets and perform routing, though they are not specialized hardware and may
suffer from limited performance. The routing process usually directs forwarding on the
basis of routing tables which maintain a record of the routes to various network
destinations. Thus, constructing routing tables, which are held in the router's memory, is
very important for efficient routing. Most routing algorithms use only one network path at
a time. Multipath routing techniques enable the use of multiple alternative paths. In case of
overlapping/equal routes, the following elements are considered in order to decide which
routes get installed into the routing table (sorted by priority):
1. Prefix-Length: where longer subnet masks are preferred (independent of whether it is
within a routing protocol or over different routing protocol)
2. Metric: where a lower metric/cost is preferred (only valid within one and the same routing
protocol)
3. Administrative distance: where a lower distance is preferred (only valid between
different routing protocols) Routing, in a narrower sense of the term, is often contrasted
with bridging in its assumption that network addresses are structured and that similar
addresses imply proximity within the network. Structured addresses allow a single routing
table entry to represent the route to a group of devices. In large networks, structured
addressing (routing, in the narrow sense) outperforms unstructured addressing (bridging).
Routing has become the dominant form of addressing on the Internet. Bridging is still
widely used within localized environments.

a) FLOODING
Flooding is a simple routing algorithm in which every incoming packet is sent
through every outgoing link except the one it arrived on Flooding is used in bridging and
in systems such as Usenet and peer-to-peer file sharing and as part of some routing
protocols, including OSPF, DVMRP, and those used in ad-hoc wireless networks. There
are generally two types of flooding available, Uncontrolled Flooding and Controlled
Flooding. Uncontrolled Flooding is the fatal law of flooding. All nodes have neighbours
and route packets indefinitely. More than two neighbours create a broadcast storm.
Controlled Flooding has its own two algorithms to make it reliable, SNCF (Sequence
Number Controlled Flooding) and RPF (Reverse Path Flooding). In SNCF, the node
attaches its own address and sequence number to the packet, since every node has a
memory of addresses and sequence numbers. If it receives a packet in memory, it drops it
immediately while in RPF, the node will only send the packet forward. If it is received
from the next node, it sends it back to the sender.

Algorithm
There are several variants of flooding algorithm. Most work roughly as follows:
1. Each node acts as both a transmitter and a receiver.
2. Each node tries to forward every message to every one of its neighbours except the
source node. This results in every message eventually being delivered to all reachable parts
of the network. Algorithms may need to be more complex than this, since, in some case,
precautions have to be taken to avoid wasted duplicate deliveries and infinite loops, and to
allow messages to eventually expire from the system. A variant of flooding called selective
flooding partially addresses these issues by only sending packets to routers in the same
direction. In selective flooding the routers don't send every incoming packet on every line
but only on those lines which are going approximately in the right direction.

Advantages
packet can be delivered, it will (probably multiple times).
Department of Computer Science & Engineering

Since flooding naturally utilizes every path through the network, it will also use the
shortest path. Thisalgorithm is very simple to implement.
Disadvantages
Flooding can be costly in terms of wasted bandwidth. While a message may only have one
destination it has to be sent to every host. In the case of a ping flood or denial of service
attack, it can be harmful tothe reliability of a computer network. Messages can become
duplicated in the network further increasing the load on the networks bandwidth as well as
requiring an increase in processing complexity to disregard duplicate messages. Duplicate
packets may circulate forever, unless certain precautions are taken: Use a hop count or a
time to live count and include it with each packet. This value should take into account the
number of nodes that a packet may have to pass through on the way to its destination. Have
each node keep track of every packet seen and only forward each packet once enforce a
network topology without loops.

b) DISTANCE VECTOR ROUTING PROTOCOL USING NS2


In computer communication theory relating to packet-switched networks, a distance
vector routing protocol is one of the two major classes of routing protocols, the other
major class being the link-state protocol. Distance-vector routing protocols use the
Bellman–Ford algorithm, Ford–Fulkerson algorithm, or DUAL FSM (in the case of Cisco
Systems protocols) to calculate paths.
A distance-vector routing protocol requires that a router informs its neighbours of topology
changes periodically. Compared to link-state protocols, which require a router to inform
all the nodes in a network of topology changes, distance-vector routing protocols have less
computational complexity and message overhead. The term distance vector refers to the
fact that the protocol manipulates vectors (arrays) of distances to other nodes in the
network. The vector distance algorithm was the original ARPANET routing algorithm and
was also used in the internet under the name of RIP (Routing Information Protocol).
Examples of distance-vector routing protocols include RIPv1 and RIPv2 and IGRP.

Method
Routers using distance-vector protocol do not have knowledge of the entire path to a
destination. Instead they use two methods:
1. Direction in which router or exit interface a packet should be forwarded.
2. Distance from its destination
Distance-vector protocols are based on calculating the direction and distance to any link in
a network. "Direction" usually means the next hop address and the exit interface.
"Distance" is a measure of the cost to reach a certain node. The least cost route between
any two nodes is the route with minimum distance. Each node maintains a vector (table) of
minimum distance to every node. The cost of reaching a destination is calculated using
various route metrics. RIP uses the hop count of the destination whereas IGRP takes into
account other information such as node delay and available bandwidth. Updates are
performed periodically in a distance-vector protocol where all or part of a router's routing
table is sent to all its neighbors that are configured to use the same distance-vector routing
protocol. RIP supports cross-platform distance vector routing whereas IGRP is a Cisco
Systems proprietary distance vector routing protocol. Once a router has this information it
is able to amend its own routing table to reflect the changes and then inform its neighbors
of the changes. There are a number of features which can be used to help with instability
and inaccurate routing information. EGP and BGP are not pure distance-vector routing
protocols because a distance-vector protocol calculates routes based only on link costs
whereas in BGP, for example, the local route preference value takes priority over the link
cost.

Count-to-infinity problem
The Bellman–Ford algorithm does not prevent routing loops from happening and suffers
from the countto infinity problem. The core of the count-to-infinity problem is that if A
tells B that it has a path somewhere, there is no way for B to know if the path has B as a
part of it. To see the problem clearly, imagine a subnet connected like A–B–C–D–E–F, and
let the metric between the routers be "number of jumps". Now suppose that A is taken
offline. In the vector-update-process B notices that the route to A, which was distance 1, is
down – B does not receive the vector update from A. The problem is, B also gets an update
from C, and C is still not aware of the fact that A is down – so it tells B that A is only two
jumps from C (C to B to A), which is false. This slowly propagates through the network
until it reaches infinity (in which case the algorithm corrects itself, due to the relaxation
property of Bellman–Ford).
Sample program:
set ns [new
Simulator]
set nr [open
thro.tr w]
$ns trace-all $nr
setnf [open thro.nam w]
$ns
namtrace-
all $nf
proc
finish { }
{global ns nr nf
$ns
flush
-
trace
close
$nf
close
$nr
execnamth
ro.nam&
exit 0}
for { set i 0 }
{ $i < 12}
{ incr i 1 }
{set n($i)
[$ns node]}
for {set i 0}
{$i < 8}
{incr i}
{$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb
10ms DropTailset udp0 [new
Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent
$udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect
$udp0 $null0 set
udp1 [new
Agent/UDP]
$ns attach-agent $n(1)
$udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-
agent $udp1 set
null0 [new
Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto DV
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run

Sample Output:
EXPERIMENT NO.-11
AIM: . Implementation of Stop and Wait Protocol and Sliding Window Protocol
Description:
A sliding window protocol is a feature of packet-based data transmission protocols. Sliding
window protocols are used where reliable in-order delivery of packets is required, such as in
the Data Link Layer (OSI model) as well as in the Transmission Control Protocol (TCP).

Pre-Experiment Questions:
Q.1 What is Sliding Window?
Q.2 What is usage of Sequence Number in Reliable Transmission?
Algorithm/Syntax:
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

Input:
Data frame based on sender window
Output:
ENTER THE WINDOWS SIZE : 10
SENDER WINDOW IS EXPANDED TO STORE MESSAGE OR WINDOW
ENTER THE DATA TO BE SENT:
MESSAGE SEND BY THE SENDER:
WINDOW SIZE OF RECEIVER IS EXPANDED
ACKNOWLEDGEMENT FROM RECEIVER
ACK:5
MESSAGE RECEIVED BY RECEIVER IS :
WINDOW SIZE OF RECEIVER IS SHRINKED
EXPERIMENT NO.-12
Aim: Implement Subnetting to generate Range of IP Addresses.
Description: IP (Internet Protocol) addresses are used to identify hosts on the campus Internet,
a network that ties into the Internet, a global network. If the computer is attached to the network,
it needs an IP address to be recognized as part of the campus Internet. IP addresses are
constructed according to a set of specific rules so that hosts on any part of the Internet can
communicate with each other. An IP address consists of a 32-bit binary number, which is
typically presented as four decimal numbers (one for each 8-bit byte) separated by decimal
points. For example, 128.253.21.58.

HostAddress
The host address is the address given to the workstation, other computer, or device that is
connected to the LAN.

Subnetting
Subnetting is the process of dividing an IP network in to sub divisions called subnets.
Computers belonging to a sub network have a common group of most-significant bits in their
IP addresses. So, this would break the IP address in to two parts (logically), as the network
prefix and the rest field. Dividing an IP network in to sub divisions is subnetting. It divides an
IP address in to two parts as the network (or routing prefix) and the rest field (which is used to
identify a specific host). CIDR notation is used for writing a routing prefix. This notation uses
a slash (/) to separate the network starting address and the length of the network prefix (in bits).
For example, in IPv4, 192.60.128.0/22 indicates that 22 bits are allocated for the network prefix
and the remaining 10 bits are reserved for the host address. In addition, routing prefix can also
be represented using the subnet mask. 255.255.252.0
(11111111.11111111.11111100.00000000) is the subnet mask for 192.60.128.0/22. Separating
the network portion and the subnet portion of an IP address is done by performing a bitwise
AND operation between the IP address and the subnet mask. This would result in identifying
the network prefix and the host identifier.

Supernetting

Supernetting combines several sub networks, having a Classless Inter-Domain Routing (CIDR)
routing prefix. Supernetting is also called route aggregation or route summarization.
Supernetting is the practice of combining several IP networks with a common network prefix.
Supernetting was introduced to tackle the problem of increasing size in routing tables.
Supernetting also simplifies the routing process. For example, the subnetworks 192.60.2.0/24
and 192.60.3.0/24 can be merged with the supernetwork denoted by 192.60.2.0/23. In the
supernet, the first 23 bits are the network part of the address and the other 9 bits are used as the
host identifier. So, one address will represent several small networks and this would reduce the
number of entries that should be integrated in the routing table.

A Supernetted Network

A network with three levels of hierarchy (subnetted)

Pre-Experiment Questions:
Q.1Input should be binary form or in the form of an IP address?
Q.2 IP-v 4 or IP-V-6 version? Does it affects the subnetting process??
Pseudo-code: Subnetting process itself described above
Input:
In order to define the range of IP addresses we need the following:
In subnetting:
The first address of the subnet + subnet mask
In supernetting:
The first address of the supernet + supernet mask
Output: Subnets for a given network.
EXPERIMENT NO.-13

Aim: To implement socket programming date and time display from client to server using
TCP and UDPSockets.

Description:

➢ A server program to establish the socket connection with the client.


➢ A client program which on establishing a connection retrieves the time and date
of the system anddisplays it.

Socket Programming

➢ Sockets provide the communication mechanism between two computers. A


client program creates asocket on its end of the communication and attempts to
connect that socket to a server.
➢ When the connection is made, the server creates a socket object on its end of the
communication.The client and server can now communicate by writing to and
reading from the socket.

Client–server model
➢ The client–server model of computing is a distributed application structure that
partitions tasks or workloads between the providers of a resource or service, called
servers, and service requesters, called clients.
➢ Often clients and servers communicate over a computer network on separate
hardware, but both client and server may reside in the same system.
➢ A server host runs one or more server programs which share their resources with
clients. A client does not share any of its resources, but requests a server's content or
service function.
➢ Clients therefore initiate communication sessions with servers which await incoming
requests. Examples of computer applications that use the client–server model are
Email, network printing, and the World Wide Web.
Pre-Experiment Questions:

1. Define Socket.
2. What is Socket address?
3. What is port number?
4. Give the differences between connection oriented and connectionless service
5. What is UDP?

Algorithm:
Server:
Step1:Create a server socket and bind it to port.
Step 2:Listen for new connection and when a connection arrives, accept it.
Step 3:Send server’s date and time to
the client. Step 4:Read client’s IP
address sent by the client.Step 5:Display
the client details.
Step 6:Repeat steps 2-5 until the server is terminated.
Step 7:Close the server socket.

Client
Step1:Create a client socket and connect it to the server’s port number.
Step2:Retrieve its own IP address using built-in function.
Step3:Send its address to the server.
Step4:Display the date & time sent by
the server.Step5:Close the client socket

System and Software tools required:


Package Required : Java
CompilerOperating System:
UBUNTU
Minimum Requirement : Pentium III or Pentium IV with 2GB RAM 40 GB hard
disk

TCP Program:
dateserver.java
//import java packages
import java.net.*; import java.io.*; importjava.util.*;
Department of Computer Science & Engineering

/*… Register service on port 8020…*/


ss=new ServerSocket(8020);

/*… Wait and accept a connection…*/


s=ss.accept();

/*… Get a communication stream associated with the socket…*/


ps=new PrintStream(s.getOutputStream());

/* …To get system


time…*/Date
d=new Date();
ps.println(d);
dis=new DataInputStream(s.getInputStream());
inet=dis.readLine();System.out.println("THE CLIENT SYSTEM ADDRESS IS
:"+inet);

/* …This method is used to request for closing or terminating an object…*/


ps.close();}}

dateclient.java

/* …Socket class is having a constructor through this Client program can request to
server to getconnection…*/
Socket soc;
DataInputSt
ream dis;
String
sdate;
PrintStream
ps;

/*…getLocalHost() method: Returns the name of the local computer…*/


InetAddressia=InetAddress.getLocalHost();
/*… Open your connection to a server, at port 8020…*/
soc=new Socket(ia,8020);

/*… Get an input file handle from the socket and read the input…*/

/*…getInputStream()-This method take the permission to write the data from


client program toserver program and server program to client program…*/
dis=new
DataInputStream(soc.getInputStream());
sdate=dis.readLine();
System.out.println("THE date in the server is:"+sdate);

/* …getOutputStream()-This method is used to take the permission to


read data from clientsystem by the server or from the server system by the
client…*/
ps=new
PrintStream(soc.getOutputStream());
ps.println(ia);}

Output:
UDP Program:
Server.java
/*…import java packages…*/
import java.net.*; import java.io.*; importjava.util.*;

/*..receiving the packet from client…*/


DatagramPacketrp=new DatagramPacket(rd,rd.length);
ss.receive(rp);InetAddress ip= rp.getAddress(); int
port=rp.getPort();

/*… getting system time…*/


Date d=new Date();

/*… converting it to String…*/


String time= d + "";

/*… converting that String to byte…*/


sd=time.getBytes();

/*…sending the data to the client…*/


DatagramPacketsp=new
DatagramPacket(sd,sd.length,ip,port);ss.send(sp);

Clientnew.java

/*…send the data to the server(data,length,ip address and port


number)…*/DatagramPacketsp=new
DatagramPacket(sd,sd.length,ip,1234); DatagramPacketrp=new
DatagramPacket(rd,rd.length);
/*…To Send the data…*/
cs.send(sp); cs.receive(rp);
String time=new String(rp.getData()); System.out.println(time);

/*…This method is used to request for closing or terminating an object…*/


cs.close(); } }

Output:

Test cases:
1. Check for the successful connection establishment
2. Retrieve the time and date of the system
3. Change the port number in both server and client programs. Recompile
4. Run client and server on separate computers and try to retrieve the date
and time usingTCP and UDP.

Output:
Thus, the program for implementing to display date and time from client to server
using TCPSockets was executed successfully and output verified using various samples.
EXPERIMENT NO.-14
Aim:To Study of Network simulator and Simulation of Congestion Control Algorithms
using NS.

Description:
Ns overview
•Ns programming: A Quick start
•Case study I: A simple Wireless network
•Case study II: Create a new agent in Ns
•Ns Status
•Periodical release (ns-2.26, Feb 2003)
•Platform support
• FreeBSD, Linux, Solaris, Windows and Mac

Ns Functionalities
Routing, Transportation, Traffic sources, queuing disciplines, QoS

Wireless
Ad hoc routing, mobile IP, sensor-MAC Tracing, visualization and various
utilitiesNS(Network Simulators) Most of the commercial simulators are GUI driven, while
some network simulators are CLI driven. The network model / configuration describe the
state of the network (nodes, routers, switchesand links) and the events (data transmissions,
packet error etc.). The important outputs 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 variants" and "importance sampling" have
been developed to speed simulation.
Examples of network simulators

There are many both free/open-source and proprietary network simulators. Examples of notable
network simulation software are, ordered after how often they are mentioned in research papers:
•ns (open source)
•OPNET (proprietary software)
• NetSim (proprietary software)
Uses of network simulators

Network simulators serve a variety of needs. Compared to the cost and time involved in setting up
an entire test bed containing multiple networked computers, routers and data links, network
simulators are relatively fast and inexpensive. They allow engineers, researchers to test scenarios
that might be particularly difficult or expensive to emulate using real hardware - for
instance,simulating a scenario with several nodes or experimenting with a new protocol in the
network. Network simulators are particularly useful in allowing researchers to test new networking
protocols or changes to existing protocols in a controlled and reproducible environment. A typical
network simulator encompasses a wide range of networking technologies and can help the users to
build complex networks from basic building blocks such as a variety of nodes and links. With the
help of simulators, one can design hierarchical networks using various types of nodes like
computers, hubs, bridges, routers, switches, links, mobile units etc. Various types of Wide Area
Network (WAN) technologies like TCP, ATM, IPetc. and Local Area Network (LAN) technologies
like Ethernet, token rings etc., can all be simulated with a typical simulator and the user can test,
analyse 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 andpatterns 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 thetotal 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.
EXPERIMENT NO: -15
Aim: Applications using TCP Sockets like a. Echo client and echo server b. Chat c. File
Transfer.

Description

Our aim is to send a file from the client machine to the server machine using TCP
Communication.

Algorithm

Server

Step1: Import java packages and create class file


server. Step2: Create a new server socket and
bind it to the port. Step3: Accept the client
connection
Step4: Get the file name and stored into the BufferedReader.
Step5: Create a new object class file and realine.
Step6: If file is exists then FileReader read the content until EOF is reached.
Step7: Stop the program.

Client

Step1: Import java packages and create class file


server. Step2: Create a new server socket and bind
it to the port.Step3: Now connection is established.
Step4: The object of a BufferReader class is used for storing data content which has been
retrievedfrom socket object.
Step5: The content of file is displayed in the client window and the connection is closed.
Step6: Stop the program.

Sample
code:
Se.java
{/*… Register service on port 15123…*/
ServerSocketserverSocket = new ServerSocket(15123);

/*… Wait and accept a connection…*/


Socket socket = serverSocket.accept();
System.out.println("Accepted connection : " +
socket);

/*… enter the source file name which is to be transferred to client…*/


File transferFile = new File
("sunithanandhinifiletransfer.doc");byte [] bytearray
= new byte [(int)transferFile.length()];

/*…FileInputStream is meant for reading streams of raw bytes such as image


data…*/
FileInputStream fin = new FileInputStream(transferFile);
BufferedInputStream bin = new BufferedInputStream(fin);bin.read(bytearray,0,bytearray.length);

/*… Get a communication stream associated with


the socket…*/OutputStreamos =
socket.getOutputStream(); System.out.println("Sending
Files..."); os.write(bytearray,0,bytearray.length);
os.flush();socket.close();

Cl.java

/*… Open your connection to a server, at port 15123…*/


Socket socket = new
Socket("127.0.0.1",15123);byte []
bytearray = new byte [filesize];
InputStream is =
socket.getInputStream();

/*… enter the destinationfile name which is to be transferred


…*/ FileOutputStream fos = new
FileOutputStream("kalpanasonikafiletransfer.doc");
BufferedOutputStream bos = new BufferedOutputStream(fos);
bytesRead =
is.read(bytearray,0,bytearray.length);
currentTot = bytesRead;
do { bytesRead = is.read(bytearray, currentTot, (bytearray.length-currentTot));
if(bytesRead>= 0) currentTot += bytesRead;}
while(bytesRead> -1);
bos.write(bytearray, 0 ,
currentTot);
bos.flush(); bos.close(); socket.close(); }}

Sample Output:

Testcase:

1. Send and receive files from or to server/client


2. Change the port number in both server and client programs. Recompile
3. Run Client and Server on separate computers and try to transfer the files.
EXPERIMENT NO: -16
Aim: Applications using TCP and UDP Sockets like DNS, SNMP, File Transfer

Description:

1. The DNS client program sends a request to a DNS server to map the e-mail
address to thecorresponding IP address.
2. When the Internet was small, mapping was done by using a host file. The host
file had only twocolumns: name and address.
3. The host that needs mapping can contact the closest computer holding the needed
information.This method is used by the Domain Name System (DNS).

Algorithm:
Server
Step1: Start the program.
Step2: Create the socket for the server.
Step3: Bind the socket to the port.
Step4: Listen for the incoming client connection.
Step5: Receive the IP address from the client to be resolved.
Step6: Get the domain name for the client.
Step7: Check the existence of the domain in the server.
Step8: If domain matches then send the corresponding address to the client.
Step9: Stop the program execution

Client
Step1: Start the Program.
Step2: Create the socket for the client.
Step3: Connect the socket to the Server.
Step4: Send the host name to the server to be resolved.
Step5: If the server corresponds then print the address and terminate the process
Sample Program:
Clientdns12.java

/*... datagram socket is the sending or receiving point for a packet delivery
service.
DatagramSocket client=new DatagramSocket();

/*...InetAddress class provides methods to get the IP of any host name...*/


InetAddress
addr=InetAddress.getByName("127.0.0.1"); byte[]
sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the DOMAIN NAME or IP adress:");
String
str=in.readLine();
sendbyte=str.getBytes(
);

/*…send the data to the server(data,length,ip address and port


number)…*/ DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,1309); client.send(sender);
DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("IP address or DOMAIN NAME: "+s.trim());

Serverdns12.java
DatagramSocket server=new
DatagramSocket(1309);while(true)
{byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];

/*..receiving the packet from client…*/


DatagramPacket receiver=new DatagramPacket(receivebyte,receivebyte.length);
server.receive(receiver);
String str=new
String(receiver.getData());String
s=str.trim();
//System.out.println(s);
InetAddressaddr=receiver.getA
ddress(); int
port=receiver.getPort();

/*... specify the IP address to map with its domain name...*/


String ip[]={"165.165.80.80","165.165.79.1"};

/*domain name...*/
{if(s.equals(ip[i]))
{sendbyte=name[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port); server.send(sender);
break;}
else if(s.equals(name[i])){
sendbyte=ip[i].getBytes();
DatagramPacket sender=new
DatagramPacket(sendbyte,sendbyte.length,addr,port); server.send(sender);

Sample Output:

Test cases:
1 Give the domain name as google.com

2 Give the domain name as computernetworks.in


Analysis of Result:
From this experiment, student will be able to
1 Deduce the need for the DNS server.
2 Relate the purpose of the DNS in real time when they type URL’s in the browser.
3 Analyze how the DNS server resolves the IP address from the domain name
given by the end user

Output:

Thus, the DNS application program was executed.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy