CN_LAB_Manual_2024-25[1]
CN_LAB_Manual_2024-25[1]
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 PSO
PO 1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO2
Outcome 1
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
Control Algorithms 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 321.5
Transfer
8
EXPERIMENT NO. - 1
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.
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 bunch of smaller wires twisted together. Separate the twisted wires and straighten
them out so they’re easier 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 2 colors.
10
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.
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.
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 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.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 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.
13
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.
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 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); }
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
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
23
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.
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 control protocol.
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.
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 $ns flush-trace close
$nf close
$tf exec nam lab2.nam & exit 0
}
set n0 [$ns node]
duplex-link $n2
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
29
$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);
}
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
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 ,
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 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 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 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.
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
in command 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=new PrintStream(s.getOutputStream()); while(c<4)
{
out.println(str);
pingserver.java
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 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 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 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 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
Aim: Implement Sub netting 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.
Host Address
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.
Super netting
Super netting 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
47
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
Socket Programming
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.
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.
49
Step 4:Read client’s IP address sent by the client.
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.
TCP Program:
dateserver.java
/* …To get
system time…
*/Date d=new
Date(); 50
ps.println(d);
dis=new DataInputStream(s.getInputStream());
inet=dis.readLine();System.out.println("THE CLIENT SYSTEM ADDRESS IS
:"+inet);
dateclient.java
/* …Socket class is having a constructor through this Client program can request to
server to getconnection…*/
Socket
soc;
DataInput
St ream
dis;
String
sdate;
PrintStrea
m ps;
/*… 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.getInputStrea
m()); sdate=dis.readLine();
System.out.println("THE date in the server is:"+sdate);
51
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();
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);
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 using TCP and UDP.
53
Output:
Thus, the program for implementing to display date and time from client to server
using TCP Sockets 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
Wireless
Ad hoc routing, mobile IP, sensor-MAC Tracing, visualization and various utilities
NS(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, switches and 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
54 for an accurate answer can be extremely
large. Specialized techniques such as "control variants" and "importance sampling" have
been developed to speed simulation.
55
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, IP etc. and Local Area
Network (LAN) technologies like Ethernet, token rings etc., can all be simulated with a
typical simulator and the user can test, analyze various standard results apart from
devising some novel protocol or strategy for routing etc. Network simulators are also
widely used to simulate battlefield networks in Network-centric warfare there are a wide
variety of network simulators, ranging from the very simple to the very complex.
Minimally, a network simulator must enable a user to represent a network topology,
specifying the nodes on the network, the links between those nodes and the traffic
between the nodes. More complicated systems may allow the user to specify everything
about the protocols used to handle traffic in a network. Graphical applications allow
users to easily visualize the workings of their simulated environment. Text-based
applications may provide a less intuitive interface, but may permit more advanced forms
of customization.
56
Packet loss occurs when one or more packets of data travelling across a computer
network fail to reach their destination. Packet loss is distinguished as one of the three
main error types encountered in digital communications; the other two being bit error
and spurious packets caused due to noise. Packets can be lost in a network because they
may be dropped when a queue in the network node
Overflows. The amount of packet loss during the steady state is another important
property of a congestion control scheme. The larger the value of packet loss, the more
difficult it is for transport layer protocols to maintain high bandwidths, the sensitivity to
loss of individual packets, as well as to frequency and patterns of loss among longer
packet sequences is strongly dependent on the application itself.
Throughput
This is the main performance measure characteristic, and most widely used. In
communication networks, such as Ethernet or packet radio, throughput or network
throughput is the average rate of successful message delivery over a communication
channel. The throughput is usually measured in bits per second (bit/s or bps), and
sometimes in data packets per second or data packets per time slot This measure how
soon the receiver is able to get a certain amount of data send by the sender. It is
determined as the ratio of the total data received to the end to end delay. Throughput is
an important factor which directly impacts the network performance
Delay
Delay is the time elapsed while a packet travels from one point e.g., source premise or
network ingress to destination premise or network degrees. The larger the value of
delay, the more difficult it is for transport layer protocols to maintain high bandwidths.
We will calculate end to end delay
Queue Length
A queuing system in networks can be described as packets arriving for service, waiting
for service if it is not immediate, and if having waited for service, leaving the system
after being served. Thus, queue length is very important characteristic to determine that
how well the active queue management of the congestion control algorithm has been
working.
57
.
58
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
Client
Sample code:
Se.java
InputStream is = socket.getInputStream();
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(); } }
60
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.
61
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 the corresponding IP address.
2. When the Internet was small, mapping was done by using a host file. The
host file had only two columns: 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();
62
/*...InetAddress class provides methods to get the IP of any host name...*/
InetAddress addr=InetAddress.getByName("127.0.0.1");
Serverdns12.java
DatagramSocket server=new DatagramSocket(1309);
while(true)
{byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
String str=new
String(receiver.getData());
String s=str.trim();
//System.out.println(s);
InetAddressaddr=receiver.get
A ddress();
int port=receiver.getPort();
Sample Output:
Test cases:
1 Give the domain name as google.com
2 Give the domain name as computer networks.in
Output:
Analysis of Result:
64