Computer Networks File
Computer Networks File
LABORATORY FILE
COMPUTER NETWORKS
(BCS-653)
Name
Roll No.
Section-Batch
Mission 1: To provide quality education in the theoretical and applied foundations of Computer
Science & Engineering.
Mission 2: To Conduct research in Computer Science & Engineering resulting in innovations,
thereby nurturing entrepreneurial thinking.
Mission 3: To inculcate team building skills and promote life-long learning with high societal and
ethical values.
2
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
B. Tech Computer Science & Engineering Department has the following Program Educational
Objectives:
PEO1: Possess core theoretical and practical knowledge in Computer Science and Engineering for
successful career development in industry, pursuing higher studies or entrepreneurship.
PEO2: Ability to imbibe life-long learning for global challenges to impact society and the
environment.
PEO3: To demonstrate work productivity, leadership and managerial skills, ethics and human values
in progressive career path.
PEO4: To exhibit communication skill and collaborative skill plan and participate in
multidisciplinary Computer Science & Engineering fields.
B.Tech. Computer Science & Engineering Department has the following Program Specific
Outcomes:
PSO1: To analyze and demonstrate, the recent engineering practices, ethical values and strategies
in real time world problems to meet the challenges for the future.
PSO2: To develop an adaptive computing system using computational intelligence strategies and
algorithmic design to address diverse data analysis and machine learning challenges.
3
PROGRAM OUTCOMES
4
GENERAL LABORATORY INSTRUCTIONS
1. Students are advised to come to the laboratory at least 5 minutes before (to the starting time),
those who come after 5 minutes will not be allowed into the lab.
2. Plan your task properly much before to the commencement, come prepared to the lab with
the synopsis / program / experiment details.
Laboratory observation notes with all the details (Problem statement, Aim, Algorithm,
Procedure, Program, Expected Output, etc.,) filled in for the lab session.
Laboratory Record updated up to the last session experiments and other utensils (if
any) needed in the lab.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the computer system
allotted to you by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab observation
note book, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff, must maintain
the discipline and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded systems, which
should be utilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode during the lab
sessions. Misuse of the equipment, misbehaviors with the staff and systems etc., will attract
severe punishment.
9. Students must take the permission of the faculty in case of any urgency to go out; if anybody
found loitering outside the lab / class without permission during working hours will be treated
seriously and punished appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer system before he/she leaves the
lab after completing the task (experiment) in all aspects. He/she must ensure the system / seat
is kept properly.
5
DETAILS OF THE EXPERIMENTS CONDUCTED
INDEX
6
IMS Engineering College
NH-09, Adhyatmik Nagar, Near Dasna, Distt. Ghaziabad, U.P.
Tel: (0120) 4940000
Department of Computer Science and Engineering
Bloom’s
COURSE OUTCOMES
Level
CO321.1 Simulate different network topologies. K3, K4
CO321.2 Implement various framing methods of Data Link Layer. K3, K4
CO321.3 Implement various Error and flow control techniques. K3, K4
CO321.4 Implement network routing and addressing techniques. K3, K4
CO321.5 Implement transport and security mechanisms. K3, K4
CO-PO Matrix
Course
PO 1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
Outcome
CO321.1 3 3 3 3 3 1 1 2 3 3 1 3 1 1
CO321.2 3 3 3 2 3 1 1 2 3 3 1 3 1 1
CO321.3 3 3 3 3 3 1 1 2 3 3 1 3 1 1
CO321.4 3 3 3 3 3 1 1 2 3 3 1 3 1 1
CO321.5 3 3 3 3 3 1 1 2 3 3 1 3 1 1
C321 3.0 3.0 3.0 2.8 3.0 1.0 1.0 2.0 3.0 3.0 1.0 3.0 1.0 1.0
7
LIST OF PROGRAMS
5 Socket programming using UDP and TCP (e.g., simple DNS, data & time 321.5
client/server, echo client/server, iterative & concurrent servers) and raw
sockets.
6 Programming Using Raw Sockets. 321.5
7 Programs using Remote Procedure Call. 321.5
8 Write a code simulating PING and TRACEROUTE commands 321.4
9 Create a socket for HTTP for web page upload and download. 321.4
10 Perform a case study about the different routing algorithms to select the 321.4
network path with its optimum and economical during data transfer. i. Link
State routing ii. Flooding iii. Distance vector.
11 Implementation of Stop and Wait Protocol and Sliding Window Protocol 321.2
13 To implement socket programming date and time display from client to server 321.5
using TCP and UDP Sockets.
14 Study of Network simulator (NS).and Simulation of Congestion 321.4
ControlAlgorithms using NS
15 Applications using TCP Sockets like a. Echo client and echo server b. Chat 321.5
c. File Transfer
16 Applications using TCP and UDP Sockets like d. DNS e. SNMP f. File Transfer 321.5
8
EXPERIMENT NO. - 1
RJ-45 can be easily crimped to a cable with or without a crimping tool. If you have a
crimpingtool, 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.
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.
The stripping section is a round hole near the handle of the tool.
The sheathing should come off cleanly, leaving the wires exposed
9
2. Untwist and straighten the wires inside of the cable. Inside of the cable you’ll see a
bunchof smaller wires twisted together. Separate the twisted wires and straighten them
out so they’reeasier to sort into the right order.
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.
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 2colors.
10
4. Cut the wires into an even line 1⁄2 inch (13 mm) from sheathing. Hold the wires with
yourthumb and index finger to keep them in order. Then, use the cutting section of the
crimping tool to cut them into an even line.
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 cutthem 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
youcrimp the connector.
11
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.
If any of the pins aren’t pushed down, put the wire back into the crimping tool and crimp
it again.
12
EXPERIMENT NO. - 2
Aim: Configuration of router, hub, switch etc. (using real devices or
simulators)
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 themact 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 atthe 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.1 D standards. 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 multiplerouters 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 thepreferred paths between any two systems on the interconnected networks.
13
5. Gate Way: In a communications network, a network node equipped for interfacing
withanother 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.
14
EXPERIMENT NO. - 3
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++)
3. C++ defines the internal mechanism (a backend) of the Simulation objects also the simulation
kernel is implemented using C++
4. 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.
5. The C++ and the OTcl are linked together using TclCL.
15
Algorithm/Syntax:
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]
16
AWK file: (Open a new editor using “vi command” and write awk file
and savewith “.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); }
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 :”
keyssimultaneously 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
17
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 steps 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.
18
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.
System requirement
19
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.
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
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 'dev
toolset' 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
20
networks work and performs, 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 Wire shark runs out of memory it will crash.
1. Microsoft Windows
2. Unix/Linux
OmNet++
System Requirements
Summary
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.
22
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.
23
Simulation of LAN topologies using CISCO Packet Tracer
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.
24
Fig 4.1 Simulating network devices
25
Fig 4.3 : Establish the links between the network devices and generic switches
26
Fig 4.5: Enter the IP address to each network devices
27
EXPERIMENT NO. -5
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 controlprotocol.
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 accepts 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:\ProgramFiles\Java\jdk1.5.0\bin>java dateclient
THE date in the server is:Sat Jan 19 13:01:16 GMT+05:30 2024
C:\ProgramFiles\Java\jdk1.5.0\bin>F iles\Java\S E R V E R S I D E :
C:\ProgramFiles\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
28
EXPERIMENT NO. – 6
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 $nsflush-trace close
$nf close
$tf exec nam lab2.nam & exit 0
}
set n0 [$ns node]
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 byTCP = %d\n”, tcp); printf(“Number of packets sent
byUDP=%d\n”,udp);
}
30
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
simultaneouslyand 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 thesnapshot.
o Now press the play button in the simulation window and the
simulation willbegins.
After simulation is completed run awk file to see the output ,
31
EXPERIMENT NO. - 7
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.
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 implement.
4. Using public 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 :
32
EXPERIMENT NO. - 8
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 thenwaits 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 called a 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
whentraveling 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.
TheTTL 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.
33
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
incommand prompt).
Step6: The client program is then started by starting
socket.
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=newPrintStream(s.getOutputStream()); while(c<4)
{
out.println(str);
pingserver.java
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=newPrintStream(s.getOutputStream());
Sample Output:
35
Output: Thus the program for implementing ping and trace route command was executed
successfully.
36
EXPERIMENT NO.-9
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 anddownload.
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 the requested file or other information are embedded in a response
message.
Algorithm:
Step5: Close the Connection as soon the request is been serviced. Use Malformed
URL exception If any errors in grabbing the server
Sample Program:
Client.java
try {
System.out.println("Reading image from disk. ");
"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();
Sample Output:
Output:
Thus the program for creating sockets for HTTP web page upload and download was
implemented.
39
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:
Routing is the process of selecting best paths in a network. In the past, the term routing was
also used to mean forwarding network traffic among networks. However, this latter function
is much better described as simply forwarding. Routing is performed for many kinds of
networks, including the telephone network (circuit switching), electronic data networks
(such as the Internet), and transportation networks. This article is concernedprimarily 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 caseof overlapping/equal routes,
the following elements are considered in order to decide whichroutes 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
40
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).
41
Since flooding naturally utilizes every path through the network, it will also use the
shortest path. This algorithm 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 a 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.
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.
42
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 count to infinity problem. The core of the count-to-infinity problem is that if A
tells B that it has a path somewhere, there is no way for B to know if the path has B as a
part of it. To see the problem clearly, imagine a subnet connected like A–B–C–D–E–F, and
let the metric between the routers be "number of jumps". Now suppose that A is taken
offline. In the vector-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 Output:
45
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).
Algorithm/Syntax:
1. Start the program.
2. Get the frame size from the user
3. To create the frame based on the user request.
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
46
EXPERIMENT NO. - 12
Description:
Algorithm/Syntax:
Sender Side:
Receiver Side:
Numerical:
1001)1010000000
1001
0011000000
1001
01010000
1001
0011000
1001
01010
1001
0011
Receiver:
1001)1010000011
1001
0011000011
1001
01010011
1001
0011011
1001
01001
1001
0000
Important note:
1. If the remainder at receiver’s side is all zeroes, it means data is accepted.
2. If the remainder at receiver’s side is not all zeroes, it means data is not accepted.
EXPERIMENT NO. - 13
Description:
Hamming Code is an error-detecting and error-correcting code that can detect up to two-
bit errors and correct one-bit errors without the need for retransmission. In C(7,4)
Hamming code, 4 data bits are used along with 3 redundant bits (parity bits) placed at
specific positions. At the sender's end, the parity bits are calculated and added to the data.
At the receiver's end, the received code is checked for errors using the parity bits and the
position of the error (if any) is identified and corrected.
Algorithm/Syntax:
Sender:
1. Identify Data and Parity Bits: The C(7,4) code uses 4 data bits and 3 parity bits.
2. Calculate Parity Bits:
3. Parity Bit 1 (P1): XOR the data bits at positions 2, 3, and 5.
4. Parity Bit 2 (P2): XOR the data bits at positions 3, 5, and 6.
5. Parity Bit 3 (P3): XOR the data bits at positions 5, 6, and 7.
6. Form 7-bit Codeword: Place the calculated parity bits (P1, P2, P3) in positions 1, 2,
and 4, respectively. The data bits are placed in positions 3, 5, 6, and 7.
Receiver:
1. Receive 7-bit Codeword: The receiver receives the 7-bit codeword from the sender.
2. Calculate Parity Bits: The receiver recalculates the parity bits using the same algorithm
as the sender.
3. Error Detection: Compare the calculated parity bits with the received parity bits. If
they match, no error is detected. If they differ, an error is detected.
4. Error Correction:
Error Location: If an error is detected, the parity bits can be used to pinpoint the exact
location of the error.
Error Correction: Flip the bit at the error location.
Example:
Let's say the data bits are 1101.
7. Sender:
Calculate Parity Bits:
P1 = 1 XOR 0 XOR 1 = 0
P2 = 0 XOR 1 XOR 1 = 0
P3 = 1 XOR 1 XOR 0 = 0
Form Codeword: 0001101
8. Receiver:
Recalculate Parity Bits:
P1 = 0 XOR 0 XOR 1 = 1 (Error detected in P1)
Error Location: Error is in position 3.
Error Correction: Flip the bit at position 3. The corrected codeword is 0001101.
The data bits are now 1101.
1 P1
2 P2
3 Data
4 P3
5 Data
6 Data
7 Data
Important Notes:
The C(7,4) Hamming code can detect and correct any single-bit error.
It cannot detect or correct multiple errors.
The minimum Hamming distance between any two valid codewords is 3.