SlideShare a Scribd company logo
1 of 162
Download to read offline
18CSL51 - Network Laboratory Manual
SCHOOL OF COMMUNICATION AND COMPUTER SCIENCES
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
18CSL51 – Network Laboratory
18CSL51 NETWORK LABORATORY
Sem Category L T P Credit
V PC 0 0 2 1
Preamble It provides an exposure to implement the various services offered by network layers and to
measure the network performance. Also provide the knowledge to develop client/server
applications using TCP and UDP.
Prerequisites Nil
List of Exercises / Experiments :
1. Simulation of network topologies (bus, ring, star and mesh) using NS2 Simulator.
2. Write a AWK script to measure the network performance using NS2 Simulator
3. Write a simple program to calculate various delays such as propagation delay, transmission delay,
total delay and end-to-end delay.
4. Write a program to implement bit stuffing and byte stuffing.
5. Write a program to implement error detection techniques (parity check and checksum).
6. Write a program to implement CRC.
7. Write a simple program to find the classes of an IP address.
8. Implementation of ARP and RARP.
9. Demonstration of OSPF routing protocol.
10. Write a socket program to implement chat application using UDP.
11. Write a socket program to implement Go-Back-N Protocol using TCP.
12. Implementation of DNS Protocol using UDP/TCP socket program
Total: 30
REFERENCES / MANUALS / SOFTWARES:
1. Linux / GCC Compiler
2. NS2 Simulator
COURSE OUTCOMES:
On completion of the course, the students will be able to
BT Mapped
(Highest Level)
CO1: make use of the performance parameters to measure the network
performance and implement the services offered by data link layer.
Applying (K3)
CO2: identify the classes of IP address and demonstrate the various routing
protocols.
Applying (K3)
CO3: develop various UDP/TCP client-server applications using socket
programming.
Applying (K3)
Mapping of COs with POs and PSOs
COs/POs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
CO1 3 2 2 1 1 3 2
CO2 3 2 2 1 1 3 2
CO3 3 2 2 1 1 3 2
1 – Slight, 2 – Moderate, 3 – Substantial, BT – Bloom’s Taxonomy
18CSL51 – Network Laboratory
Experiment beyond the syllabus
1. Simulation of Nodes with UDP agents using NS2 Simulator.
2. Simulation of BGP routing protocol.
3. TCP Client Side Socket Operations.
4. TCP Server Side Socket Operations.
5. Write a Client to download a file from a HTTP Server.
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To simulate the nodes with UDP agents using NS2 simulator.
• To understand the various components in NS2 simulator such as NAM, NAM TRACE.
• OS : Linux
• Simulation Tool : Network Simulator 2 (ns2)
• Text Editor : vi or gedit
Step 1: Create a simulator object
Step 2: Open the nam trace file
Step 3: Define a 'finish' procedure
Step 4: Create two nodes n0 and n1.
Step 5: Create a duplex link between the nodes
Step 6: Create a UDP agent and attach it to node n0
Step 7: Create a CBR traffic source and attach it to udp0
Step 8: Create a Null agent (a traffic sink) and attach it to node n1
Step 9: Connect the traffic source with the traffic sink
Step 10: Schedule events for the CBR agent
Step 11: Call the finish procedure after 5 seconds of simulation time
Step 12: Run the simulation .
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number :01
Name of the Experiment : Simulation of Nodes With UDP Agents Using NS2
18CSL51 – Network Laboratory
Computations to be Made:
First of all, you need to create a simulator object. This is done with the command
Now open a file for writing that is going to be used for the nam trace data.
The first line opens the file 'out.nam' for writing and gives it the file handle 'nf'. In the second line tell
the simulator object that created above to write all simulation data that is going to be relevant for nam
into this file.
The next step is to add a 'finish' procedure that closes the trace file and starts nam.
The next line tells the simulator object to execute the 'finish' procedure after 5.0 seconds of simulation
time.
You probably understand what this line does just by looking at it. ns provides you with a very simple
way to schedule events with the 'at' command.
The last line finally starts the simulation.
Next to define a very simple topology with two nodes that are connected by a link. The following
two lines define the two nodes. (Note: You have to insert the code in this section before the line
'$ns run', or even better, before the line '$ns at 5.0 "finish"').
set n0 [$ns node]
set n1 [$ns node]
$ns run
$ns at 5.0 "finish"
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
set nf [open out.nam w]
$ns namtrace-all $nf
set ns [new Simulator]
18CSL51 – Network Laboratory
A new node object is created with the command '$ns node'. The above code creates two nodes and
assigns them to the handles 'n0' and 'n1'.
The next line connects the two nodes.
This line tells the simulator object to connect the nodes n0 and n1 with a duplex link with the
bandwidth 1Megabit, a delay of 10ms and a DropTail queue.
The next step is to send some data from node n0 to node n1. In ns, data is always being sent from one
'agent' to another. So the next step is to create an agent object that sends data from node n0, and another
agent object that receives the data on node n1.
These lines create a UDP agent and attach it to the node n0, then attach a CBR traffic generatot to the
UDP agent. CBR stands for 'constant bit rate'. Line 7 and 8 should be self-explaining. The packetSize is
being set to 500 bytes and a packet will be sent every 0.005 seconds (i.e. 200 packets per second).
The next lines create a Null agent which acts as traffic sink and attach it to node n1.
Now the two agents have to be connected with each other.
And now you have to tell the CBR agent when to send data and when to stop sending. Note: It's
probably best to put the following lines just before the line '$ns at 5.0 "finish"'.
Now you can save the file and start the simulation again. When you click on the 'play' button in the
nam window, you will see that after 0.5 simulation seconds, node 0 starts sending data packets to node
1. You might want to slow nam down then with the 'Step' slider.
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
$ns connect $udp0 $null0
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• List out the components in NS 2 Simulator.
• List out the versions of NS.
• Who Developed NS1?
• What is LBNL?
• Expand the terms
◦ TCL
◦ OTCL
◦ NAM
◦ NS
• Which language is used to develop NS2
◦ C
◦ C++
◦ JAVA
◦ PYTHON
• Which Language is used to develop NS3
◦ C++
◦ C++ and C#
◦ C++ and JAVA
◦ C++ and PYTHON
• Write the simulation work - flow
• How to run ns2 scripts in terminal?
• List out the Agents in NS2.
• List out the Traffic Sources in NS2.
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To simulate nodes with UDP agents by using NS2 simulator.
◦ To apply this knowledge in their project work to measure the packet delivery ratio, delay,
jitter, throughput, etc.
18CSL51 – Network Laboratory
Program:
#Create a simulator object
set ns [new Simulator]
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
#Create two nodes
set n0 [$ns node]
set n1 [$ns node]
#Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a Null agent (a traffic sink) and attach it to node n1
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
#Connect the traffic source with the traffic sink
$ns connect $udp0 $null0
#Schedule events for the CBR agent
$ns at 0.5 "$cbr0 start"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To simulate the star topology by using NS2 simulator.
• To understand the queuing and packet dropping concept in router or switch.
• OS : Linux
• Simulation Tool : Network Simulator 2 (ns2)
• Text Editor : vi or gedit
Step 1: Create a simulator object
Step 2: Define different colors for data flows
Step 3: Open the nam trace file
Step 4: Define a 'finish' procedure
Step 5: Create four nodes
Step 6: Create links between the nodes
Step 7: Monitor the queue for the link between node 2 and node 3
Step 8: Create a UDP agent and attach it to node n0
Step 9: Create a CBR traffic source and attach it to udp0
Step 10: Create a UDP agent and attach it to node n1
Step 11: Create a CBR traffic source and attach it to udp1
Step 12: Create a Null agent (a traffic sink) and attach it to node n3
Step 13: Connect the traffic sources with the traffic sink
Step 14: Schedule events for the CBR agents
Step 15: Call the finish procedure after 5 seconds of simulation time
Step 16: Run the simulation
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number :02
Name of the Experiment : Simulation of Network Topologies Using NS2
18CSL51 – Network Laboratory
Computations to be Made:
As always, the first step is to define the topology. You should create a file 'star.tcl'. You will
always have to create a simulator object, you will always have to start the simulation with the
same command, and if you want to run nam automatically, you will always have to open a trace
file, initialize it, and define a procedure which closes it and starts nam.
Now insert the following lines into the code to create four nodes.
The following piece of Tcl code creates three duplex links between the nodes.
You can save and start the script now. You might notice that the topology looks a bit awkward in nam.
You can hit the 're-layout' button to make it look better, but it would be nice to have some more control
over the layout. Add the next three lines to your Tcl script and start it again.
You will probably understand what this code does when you look at the topology in the nam window
now. It should look like the picture below.
Note that the autolayout related parts of nam are gone, since now you have taken the layout into your
own hands. The options for the orientation of a link are right, left, up, down and combinations of these
orientations. You can experiment with these settings later, but for now please leave the topology the
way it is.
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms DropTail
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
18CSL51 – Network Laboratory
Now create two UDP agents with CBR traffic sources and attach them to the nodes n0 and n1.
Then create a Null agent and attach it to node n3.
The two CBR agents have to be connected to the Null agent.
We want the first CBR agent to start sending at 0.5 seconds and to stop at 4.5 seconds while the second
CBR agent starts at 1.0 seconds and stops at 4.0 seconds.
When you start the script now with 'ns star.tcl', you will notice that there is more traffic on the links
from n0 to n2 and n1 to n2 than the link from n2 to n3 can carry. A simple calculation confirms this:
We are sending 200 packets per second on each of the first two links and the packet size is 500 bytes.
This results in a bandwidth of 0.8 megabits per second for the links from n0 to n2 and from n1 to n2.
That's a total bandwidth of 1.6Mb/s, but the link between n2 and n3 only has a capacity of 1Mb/s, so
obviously some packets are being discarded. But which ones? Both flows are black, so the only way to
find out what is happening to the packets is to monitor them in nam by clicking on them. In the next
two sections I'm going to show you how to distinguish between different flows and how to see what is
actually going on in the queue at the link from n2 to n3.
$ns at 0.5 "$cbr0 start"
$ns at 1.0 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
$ns connect $udp0 $null0
$ns connect $udp1 $null0
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a UDP agent and attach it to node n1
set udp1 [new Agent/UDP]
$ns attach-agent $n1 $udp1
# Create a CBR traffic source and attach it to udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
18CSL51 – Network Laboratory
Add the following two lines to your CBR agent definitions.
The parameter 'fid_' stands for 'flow id'.
Now add the following piece of code to your Tcl script, preferably at the beginning after the simulator
object has been created, since this is a part of the simulator setup.
This code allows you to set different colors for each flow id.
Now you can start the script again and one flow should be blue, while the other one is red. Watch the
link from node n2 to n3 for a while, and you will notice that after some time the distribution between
blue and red packets isn't too fair anymore (at least that's the way it is on my system). In the next
section I'll show you how you can look inside this link's queue to find out what is going on there.
You only have to add the following line to your code to monitor the queue for the link from n2 to n3.
$ns duplex-link-op $n2 $n3 queuePos 0.5
$ns color 1 Blue
$ns color 2 Red
$udp0 set class_ 1
$udp1 set class_ 2
18CSL51 – Network Laboratory
Start ns again and you will see a picture similar to the one below after a few moments.
You can see the packets in the queue now, and after a while you can even see how the packets are
being dropped, though (at least on my system, I guess it might be different in later or earlier releases)
only blue packets are being dropped. But you can't really expect too much 'fairness' from a simple
DropTail queue. So let's try to improve the queueing by using a SFQ (stochastic fair queueing) queue
for the link from n2 to n3. Change the link definition for the link between n2 and n3 to the following
line.
The queueing should be 'fair' now. The same amount of blue and red packets should be dropped.
$ns duplex-link $n3 $n2 1Mb 10ms SFQ
18CSL51 – Network Laboratory
Formation of Bus Topology
#Creating five nodes
set node1 [$ns node]
set node2 [$ns node]
set node3 [$ns node]
set node4 [$ns node]
set node5 [$ns node]
#Creating Lan connection between the nodes
set lan0 [$ns newLan “$node1 $node2$node3 $node4 $node5” 0.7Mb 20ms LL Queue/FQ MAC/Csma/C
d Channel]
#Creating a TCP agent and attaching it to node 1
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $node1 $tcp0
#Creating a TCP Sink agent for TCP and attaching it to node 3
set sink0 [new Agent/TCPSink]
$ns attach-agent $node3 $sink0
#Connecting the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Creating a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$ cbr0 set interval_ 0.05
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 “$cbr0 start time”
$ ns at 5.5 “$cbr0 stop time”
#Here we call the finish procedure after 10 seconds of simulation time
$ns at 10.0 “End”
#Finally run the simulation
$ns run
18CSL51 – Network Laboratory
Formation of Ring Topology
#Creating six nodes
set node1 [$ns node]
set node2 [$ns node]
set node3 [$ns node]
set node4 [$ns node]
set node5 [$ns node]
set node6 [$ns node]
#Creating links between the nodes
$ns duplex-link $node1 $node2 1Mb 15ms FQ
$ns duplex-link $node2 $node3 1Mb 15ms FQ
$ns duplex-link $node3 $node4 1Mb 15ms FQ
$ns duplex-link $node4 $node5 1Mb 15ms FQ
$ns duplex-link $node5 $node6 1Mb 15ms FQ
$ns duplex-link $node6 $node1 1Mb 15ms FQ”Forms Ring Topology”
#Creating a TCP agent and attaching it to node 1
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $node1 $tcp0
#Creating a TCP Sink agent for TCP and attaching it to node 3
set sink0 [new Agent/TCPSink]
$ns attach-agent $node3 $sink0
#Connecting the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Creating a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.05
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 “$cbr0 start time”
$ns at 5.5 “$cbr0 stop time”
#Here we call the finish procedure after 10 seconds of simulation time
$ns at 10.0 “End”
#Finally run the simulation
$ns run
18CSL51 – Network Laboratory
Formation of Mesh Topology
#Creating four nodes
set node1 [$ns node]
set node2 [$ns node]
set node3 [$ns node]
set node4 [$ns node]
#Creating links between the nodes
$ns duplex-link $node1 $node2 1Mb 20ms FQ
$ns duplex-link $node1 $node3 1Mb 20ms FQ
$ns duplex-link $node1 $node4 1Mb 20ms FQ
$ns duplex-link $node2 $node3 1Mb 20ms FQ
$ns duplex-link $node2 $node4 1Mb 20ms FQ
$ns duplex-link $node3 $node4 1Mb 20ms FQ“Forms Mesh Topology”
#Creating a TCP agent and attaching it to node 1
set tcp0 [new Agent/TCP]
$tcp0 set class_ 1
$ns attach-agent $node1 $tcp0
#Creating a TCP Sink agent for TCP and attaching it to node 3
set sink0 [new Agent/TCPSink]
$ns attach-agent $node3 $sink0
#Connecting the traffic sources with the traffic sink
$ns connect $tcp0 $sink0
# Creating a CBR traffic source and attach it to tcp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.05
$cbr0 attach-agent $tcp0
#Schedule events for the CBR agents
$ns at 0.5 “$cbr0 start time”
$ns at 5.5 “$cbr0 stop time”
#Here we call the finish procedure after 10 seconds of simulation time
$ns at 10.0 “End”
#Finally run the simulation
$ns run
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• Clarify the terminologies
◦ simplex link
◦ half duplex link
◦ full duplex link
• What is CBR?
• What is SFQ?
• Define DropTail.
• List out the network typologies.
• Which topology is most suitable topology
◦ Bus
◦ Ring
◦ Mesh
◦ Star
◦ Tree
• Which network component is used in star topology
◦ Hub
◦ Switch
◦ Router
◦ Repeater
◦ Gateway
◦ First Two
• When the packets will be loss or dropped by the node?
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To simulate the star topology by using NS2 simulator.
◦ To apply this star topology concept in their project work to measure the packet loss.
◦ To develop new protocol to make an efficient network topology.
18CSL51 – Network Laboratory
Program:
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows
$ns color 1 Blue
$ns color 2 Red
#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf
$ns flush-trace
#Close the trace file
close $nf
#Execute nam on the trace file
exec nam out.nam &
exit 0
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
#Create links between the nodes
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n3 $n2 1Mb 10ms SFQ
$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right
#Monitor the queue for the link between node 2 and node 3
$ns duplex-link-op $n2 $n3 queuePos 0.5
#Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$udp0 set class_ 1
$ns attach-agent $n0 $udp0
18CSL51 – Network Laboratory
# Create a CBR traffic source and attach it to udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
#Create a UDP agent and attach it to node n1
set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1
# Create a CBR traffic source and attach it to udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
#Create a Null agent (a traffic sink) and attach it to node n3
set null0 [new Agent/Null]
$ns attach-agent $n3 $null0
#Connect the traffic sources with the traffic sink
$ns connect $udp0 $null0
$ns connect $udp1 $null0
#Schedule events for the CBR agents
$ns at 0.5 "$cbr0 start"
$ns at 1.0 "$cbr1 start"
$ns at 4.0 "$cbr1 stop"
$ns at 4.5 "$cbr0 stop"
#Call the finish procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Run the simulation
$ns run
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
Computations to be Made:
On completion of the experiment the students will be able to
• To understand the various performance measurement parameters PDR, Throughput and Jitter.
• To calculate various network performance measurement parameters such as PDR, Throughput
and Jitter.
• OS : Linux
• Simulation Tool : Network Simulator 2 (ns2)
• Text Editor : vi or gedit
• Package : AWK
Step 1: Create any one type of network topology
Step 2: Run the Simulation and Record the Trace file
Step 3: Write AWK Script to measure the network performance such as PDR, Throughput and
Jitter.
Step 4: Run the AWK Script.
Step 5: Display the results to the user.
TRACE FILES AND DESCRIPTION
 The file written by an application (or by the Coverage Server) to store coverage information or overall
network information and In NS2 , it is called as Trace File.
 In order to generate a trace file. we have to create a trace file in Otcl script.
SYNTAX FOR CREATING A TRACE FILE
# Open the trace file
set nf [open out.tr w]
$ns trace-all $nf
 which means we are opening a newtrace file named as "out" and also telling that data must be stored in .tr
[trace] format.
 "nf" is the file handler that we are used here to handle the trace file.
 "w" means write i.e the file out.tr is opened for writing.
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number : 03
Name of the Experiment : AWK script to Measure the Network Performance
18CSL51 – Network Laboratory
 >> "r" means reading and "a" means appending
 The second line tells the simulator to trace each packet on every link in the topology and for that we give
file handler nf for the simulator ns.
# Define finish procedure
proc finish {} {
global ns nf
$ns flush-trace
close nf
exit 0
}
 In here the trace data is flushed into the file by using command $ns flush-trace and then file is closed.
 While running the ns2 program via terminal, trace file is generated in the selected directory (folder or
directory where the program stored).
 Sample Trace File
 Trace File Format
18CSL51 – Network Laboratory
In here, there are 12 fields and we can explain it as;
1. EVENT OR TYPE IDENTIFIER
+ :a packet enque event
- :a packet deque event
r :a packet reception event
d :a packet drop (e.g., sent to dropHead_) event
c :a packet collision at the MAC level
2. TIME : at which the packet tracing string is created.
3-4. SOURCE AND DESTINATION NODE : source and destination ID's of tracing objects.
5. PACKET NAME : Name of the packet type.
6. PACKET SIZE : Size of packet in bytes.
7. FLAGS : 7 digit flag string.
“-”: disable
1st = “E”: ECN (Explicit Congestion Notification) echo is enabled.
2nd = “P”: the priority in the IP header is enabled.
3rd : Not in use
4th = “A”: Congestion action
5th = “E”: Congestion has occurred.
6th = “F”: The TCP fast start is used.
7th = “N”: Explicit Congestion Notification (ECN) is on.
8. FLOW ID
9-10. SOURCE AND DESTINATION ADDRESS : The format of these two fields is “a.b”, where “a"
is the address and "b" is the port.
11. SEQUENCE NUMBER
12. PACKET UNIQUE ID
 Each trace line starts with an event (+, -, d, r) descriptor followed by the simulation time (in
seconds) of that event, and from and to node, which identify the link on which the event occurred.
 The next information in the line before flags (appeared as "------" since no flag is set) is packet
type and size (in Bytes).
 Currently, NS implements only the Explicit Congestion Notification (ECN) bit, and the remaining
bits are not used.
 The next field is flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script.
18CSL51 – Network Laboratory
 Even though fid field may not used in a simulation, users can use this field for analysis purposes.
 The fid field is also used when specifying stream color for the NAM display.
 The next two fields are source and destination address in forms of "node.port".
 The next field shows the network layer protocol's packet sequence number.
 Note that even though UDP implementations do not use sequence number, NS keeps track of UDP
packet sequence number for analysis purposes.
 The last field shows the unique id of the packet.
AWK Script:
 AWK was created at Bell Labs in the 1970s, and its name is derived from the surnames of its authors:
Alfred Aho, Peter Weinberger, and Brian Kernighan.
 The acronym is pronounced the same as the bird auk, which is on the cover of The AWK Programming
Language.
 When written in all lowercase letters, as awk, it refers to the Unix or Plan 9 program that runs scripts
written in the AWK programming language.
 Functional Blocks of AWK Script.
Packet Delivery Ratio (PDR):
• Packet delivery ratio is the ratio of packets that are successfully delivered to a destination
compared to the number of packets that have been sent by sender.
• In order to calculate packet delivery ratio we need total number of packets sent and number of
received packets.
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• Expand AWK.
• What are the functional blocks of AWK script?
• Define PDR.
• List the types of events in Trace File.
• +,- strands for in trace File.
• Define throughput.
• Define jitter.
• What is the difference between bandwidth and throughput?
• Suppose a source node is sending 200 packets to the destination node. In destination node only
100 packets are received. What is the Packet Delivery Ration Value?
• A network with bandwidth of 10 Mbps can pass only an average of 12, 000 frames per minute
where each frame carries an average of 10, 000 bits. What will be the throughput for this
network?
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To compute the performance measures using formulas.
◦ To solve problems that is related to computer network.
◦ To apply this computation knowledge in their project work.
18CSL51 – Network Laboratory
Program:
# AWK Script for Packet Delivery Calculation for Trace Format
BEGIN {
sent=0;
received=0;
}
{
if($1=="s" && $9=="CBR")
{
sent++;
}
else if($1=="r" && $9=="TCP")
{
received++;
}
}
END
{
printf " Packet Sent:%d",sent;
printf "n Packet Received:%d",received;
printf "n Packet Delivery Ratio:%.2fn",(sent/received)*100;
}
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
Computations to be Made:
On completion of the experiment the students will be able to
• To understand the various performance measurement parameters such as delay, end – to – end
delay, bandwidth, throughput and jitter.
• To calculate various delays such as propagation delay, transmission delay, processing delay,
queuing delay, nodal delay and end – to – end delay.
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Step 1: Read the inputs from the user such as distance between source and destination, message
size, bandwidth, number of routers, queuing delay and processing delay.
Step 2: Calculate propagation delay.
Step 3: Calculate transmission delay.
Step 4: Calculate nodal delay.
Step 5: Calculate end – to – end delay.
Step 6: Display the results to the user.
Delay:
Network delay is an important design and performance characteristic of a computer network or
telecommunications network. The delay of a network specifies how long it takes for a bit of data to
travel across the network from one node or endpoint to another. It is typically measured in multiples or
fractions of seconds. Delay may differ slightly, depending on the location of the specific pair of
communicating nodes. Although users only care about the total delay of a network, engineers need to
perform precise measurements. Thus, engineers usually report both the maximum and average delay,
and they divide the delay into several parts:
• Processing delay - time routers take to process the packet header
• Queuing delay - time the packet spends in routing queues
• Transmission delay - time it takes to push the packet's bits onto the link
• Propagation delay - time for a signal to reach its destination
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number : 04
Name of the Experiment : Network Performance Measurement
18CSL51 – Network Laboratory
dnodal = dtrans+ dprop+ dproc + dqueu
There is a certain minimum level of delay that will be experienced due to the time it takes to
transmit a packet serially through a link. Onto this is added a more variable level of delay due to
network congestion. IP network delays can range from just a few milliseconds to several hundred
milliseconds.
Propagation delay :
Propagation time measures the time required for a bit to travel from the source to the
destination. The propagation delay is calculated by dividing the distance by the propagation speed.
Propagation delay = Distance / Propagation speed
Transmission delay:
In data communications we don't send just 1 bit, we send a message. The first bit may take a
delay equal to the propagation delay to reach its destination; the last bit also may take the same amount
of time. However, there is a delay between the first bit leaving the sender and the last bit arriving at the
receiver. The first bit leaves earlier and arrives earlier; the last bit leaves later and arrives later. The
time required for transmission of a message depends on the size of the message and the bandwidth of
the channel.
Transmission delay = Message size / Bandwidth
End-to-End Delay:
End-to-End delay refers to the time taken for a packet to be transmitted across a network from
source to destination.
where
dend-end= N[ dtrans+ dprop+ dproc]
dend-end= end-to-end delay
dtrans= transmission delay
dprop= propagation delay
dproc= processing delay
N= number of links (Number of routers + 1)
Note: we have neglected queuing delays.
Each router will have its own dtrans, dprop, dproc hence this formula gives a rough estimate.
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• Name the performance parameters for measuring network performance.
• Define nodal delay or latency.
• Define end – to – end delay.
• List the delays needed to calculate nodal delay and end – to – end delay.
• Define throughput.
• Define bandwidth.
• Define jitter.
• How many bits can fit on a link with a 3 ms delay if the bandwidth of the link is
◦ 1 Mbps?
◦ 10 Mbps?
◦ 100 Mbps?
◦ 1000 Mbps?
• A file contains 3 million bytes. How long does it take to download this file using a
◦ 100 Kbps channel?
◦ 10 Mbps channel?
• Assume you have an image of size 2MB that is being sent on a link with 15 routers each having
a queuing delay of 0.15 sec and processing delay of 0.20 sec. The length of the link is 12000
Km. The speed of the light inside the link is 2 X 10 8
m/s. The link has a bandwidth of 1 Gbps.
◦ What is the total delay?
◦ What is the end – to – end delay?
◦ Which component of the total delay is dominant?
◦ Which one is negligible?
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To compute the performance measures using formulas.
◦ To solve problems that are related to computer network.
◦ To apply this computation knowledge in their project work.
◦ To make an effective network topology.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#define PSPEED 2*100000000
void main()
{
double n,dist,band,msize,queudelay,procdelay;
float progdelay,trandelay,delay,end2enddelay;
printf("Enter the distance between source and destination (in Km):");
scanf("%lf",&dist);
printf("Enter the bandwidth (in Gbps):");
scanf("%lf",&band);
printf("Enter the Message Size (in MB):");
scanf("%lf",&msize);
printf("Enter the Number of Routers bewteen Source and Destination (in Nos):");
scanf("%lf",&n);
printf("Enter the Queuing Delay in Routers (in sec):");
scanf("%lf",&queudelay);
printf("Enter the Prosessing Delay in Routers (in sec):");
scanf("%lf",&procdelay);
progdelay = (dist*1000)/(PSPEED);
trandelay = (msize*1000000*8)/(band*1000000000);
delay = progdelay+trandelay+queudelay+procdelay;
end2enddelay = n*(progdelay+trandelay+procdelay);
printf("nn********MEASURING NETWORK PERFORMANCE*************nn");
printf("Propagation Delay (in sec):%fn",progdelay);
printf("Transmission Delay (in sec):%fn",trandelay);
printf("Delay (in sec):%fn",delay);
printf("End to End Delay (in sec):%fn",end2enddelay);
}
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
Computations to be Made:
On completion of the experiment the students will be able to
• To know framing of bits in data link layer.
• To implement bit stuffing concept in data link layer protocols such as SDLC (HDLC), PPP.
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Step 1: Read the input data from the user by using array.
Step 2: In sender side, check if five consecutive 1's present in data then add (stuff) a zero (0).
Step 3: Display the stuffed data.
Step 4: In receiver side, check if a zero (0) occurs after five consecutive 1's in data then remove
(destuff) zero (0) in the data.
Step 5: Display the destuffed data.
In data transmission and telecommunication, bit stuffing (also known—uncommonly—as
positive justification) is the insertion of non information bits into data. Stuffed bits should not be
confused with overhead bits.
Bit stuffing is used for various purposes, such as for bringing bit streams that do not necessarily
have the same or rationally related bit rates up to a common rate, or to fill buffers or frames. The
location of the stuffing bits is communicated to the receiving end of the data link, where these extra bits
are removed to return the bit streams to their original bit rates or form. Bit stuffing may be used to
synchronize several channels before multiplexing or to rate-match two single channels to each other.
Another use of bit stuffing is for run length limited coding: to limit the number of consecutive
bits of the same value in the data to be transmitted. A bit of the opposite value is inserted after the
maximum allowed number of consecutive bits. Since this is a general rule the receiver doesn't need
extra information about the location of the stuffing bits in order to do the destuffing.
This is done to create additional signal transitions to ensure reliable reception or to escape
special reserved code words such as frame sync sequences when the data happens to contain them.
Applications include Controller Area Network, HDLC, and Universal Serial Bus.
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number :05
Name of the Experiment : Implementation of Bit Stuffing
18CSL51 – Network Laboratory
Zero-bit insertion is a particular type of bit stuffing used in some data transmission protocols to
aid clock recovery from the data stream. It was popularized by IBM's SDLC (later renamed HDLC).
The name relates to the insertion of only 0 bits. No 1 bits are inserted to limit sequences of 0 bits.
SDLC and Low- and full-speed USB data are sent NRZI encoded: a 0 bit causes a signal transition,
whereas a 1 bit causes no change. After a long sequence of 1 bits there could be no transitions in the
transmitted data, and it would be possible for the transmitter and receiver clocks to lose
synchronisation. By inserting a 0 after five (SDLC) or six (USB) sequential 1s the transmitter
guarantees a maximum time between transitions. The receiver can synchronise its clock against the
transitions to ensure proper data recovery.
In SDLC the transmitted bit sequence "01111110" containing six adjacent 1 bits is the Flag
byte. Bit stuffing ensures that this pattern can never occur in normal data, so it can be used as a marker
for the beginning and end of frame without any possibility of being confused with normal data. The
main disadvantage of this form of bit-stuffing is that the code rate is unpredictable; it depends on the
data being transmitted.
Questions and problems for assessing the achievement of objective:
• What is framing?
• Give example for fixed size framing and variable size framing.
• List some bit – oriented and character – oriented protocols.
• Why bit – oriented protocols are more useful and efficient than character – oriented protocols?
• What is bit stuffing?
• What is HDLC?
• What is PPP?
• Write the flag byte value for PPP/HDLC.
• Stuff the following data
◦ 01111110
◦ 1111111111111111111111111
◦ 11111101111101111101111110
◦ 01111110111111101111011111111101111101111110
◦ 01111110000001000001111011110000010101111110
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To stuff at the bit level too
◦ To interpret bits(physical layer) as a sequence of frames(link layer).
◦ To link host and nodes with PPP.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#include<stdlib.h>
#define BLACK "033[22;30m"
#define RED "033[01;31m"
#define G "033[01;32m"
main()
{
char str[100],dest[100],str1[100];
int l,i,j,k,c,m,bit[100];
printf("nEnter the message :");
scanf("%s",str);
printf("nn ***************** BIT STUFFING ********************nn");
for(j=0,k=0,c=0,i=0;str[i]!='0';i++)
{
if(str[i]=='1')
{
c++;
if(c==5)
{
}
else
dest[j++]=str[i];
dest[j++]='0';
c=0;
}
else
{
}
}
dest[j++]=str[i];
c=0;
dest[j++]=str[i];
dest[j]='0';
printf("nThe Bit Stuffed Message is:nn");
printf(RED " | 01111110 | " );
for(i=0,c=0;dest[i]!='0';i++)
{
if(dest[i]=='1')
{
c++;
18CSL51 – Network Laboratory
printf(BLACK "%c",dest[i]);
if(c==5)
{
}
else
{
}
c=0;
printf(G "%c",dest[++i]);
c=0;
printf(BLACK "%c",dest[i]);
}
}
printf(RED " | 01111110 | "BLACK );
printf("nn ***************** BIT DESTUFFING ********************nn");
for(i=0,k=0,c=0;dest[i]!='0';i++)
{
if(dest[i]=='1')
{
c++;
if(c==5)
{
str1[k++]=dest[i++];
str1[k++]=dest[++i];
if(dest[i]=='1')
c=1;
}
else
else
c=0;
}
else
{
}
}
str1[k++]=dest[i];
str1[k++]=dest[i];
c=0;
str1[k]='0';
printf("nThe Bit Destuffed Message is:nn");
printf(RED " | 01111110 | " BLACK "%s" RED " | 01111110 |nn" BLACK, str1);
}
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
Computations to be Made:
On completion of the experiment the students will be able to
• To know framing of characters (bytes) in data link layer.
• To implement byte stuffing concept in data link layer protocols such as SDLC(HDLC), PPP.
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Step 1: Read the flag byte (character) from the user. For example 'G'.
Step 2: Read the length of the data.
Step 3: Read the data using array.
Step 4: In sender side, check the data contains the flag byte (G) then add (stuff) a escape
sequence character 'E' in the data.
Step 5: Also verify, if the escape sequence character 'E' present in the data then add (stuff) one
more escape sequence character 'E' in the data.
Step 6: Display the byte stuffed data.
Step 7: In receiver side, check if the escape sequence character 'E' present in the data followed
by flag byte 'G' and escape sequence character present in data then remove (destuff) that
escape sequence character 'E'.
Step 8: Display the destuffed data.
In a character-oriented protocol, data to be carried are 8-bit characters from a coding system
such as ASCII . The header, which normally carries the source and destination addresses and other
control information, and the trailer, which carries error detection or error correction redundant bits, are
also multiples of 8 bits. To separate one frame from the next, an 8-bit (1-byte) flag is added at the
beginning and the end of a frame. The flag, composed of protocol-dependent special characters, signals
the start or end of a frame.
Character-oriented framing was popular when only text was exchanged by the data link layers.
The flag could be selected to be any character not used for text communication. Now, however, we
send other types of information such as graphs, audio, and video. Any pattern used for the flag could
also be part of the information. If this happens, the receiver, when it encounters this pattern in the
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number :06
Name of the Experiment : Implementation of Byte Stuffing
18CSL51 – Network Laboratory
middle of the data, thinks it has reached the end of the frame. To fix this problem, a byte-stuffing
strategy was added to character-oriented framing.
In byte stuffing (or character stuffing), a special byte is added to the data section of the frame
when there is a character with the same pattern as the flag. The data section is stuffed with an extra
byte. This byte is usually called the escape character (ESC), which has a predefined bit pattern.
Whenever the receiver encounters the ESC character, it removes it from the data section and treats the
next character as data, not a delimiting flag.
Byte stuffing by the escape character allows the presence of the flag in the data section of the
frame, but it creates another problem. What happens if the text contains one or more escape characters
followed by a flag? The receiver removes the escape character, but keeps the flag, which is incorrectly
interpreted as the end of the frame. To solve this problem, the escape characters that are part of the text
must also be marked by another escape character. In other words, if the escape character is part of the
text, an extra one is added to show that the second one is part of the text.
Note: Character-oriented protocols present another problem in data communications. The universal
coding systems in use today, such as Unicode, have 16-bit and 32-bit characters that conflict
with 8-bit characters. We can say that in general, the tendency is moving toward the bit-oriented
protocols
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• Define byte stuffing.
• Compare and contrast byte-oriented and bit-oriented protocols. Which category has been
popular in the past (explain the reason)? Which category is popular now (explain the reason)?
• Compare and contrast byte-stuffing and bit-stuffing. Which technique is used in byte-oriented
protocols? Which technique is used in bit-oriented protocols?
• Stuff the following data using byte stuffing: assume the flag byte as 'G' and escape byte as 'E'
◦ KONGU
◦ ENGINEERING
◦ COLLEGE
◦ KONGU ENGINEERING COLLEGE
• Stuff the following data using byte stuffing: assume the flag bit as 'A' and escape byte as 'E'
◦ DESIGN AND ANALYSIS OF ALGORITHM
◦ COMPUTER SCIENCE ENGINEEER
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To stuff at the character (byte) level too
◦ To interpret bytes as a sequence of frames(link layer).
◦ To link host and nodes with HDLC.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#include<stdlib.h>
#define BLACK "033[22;30m"
#define RED "033[01;31m"
#define GREEN "033[01;32m"
main()
{
char str[100],dest[100],str1[100],f;
int l,i,j,k;
printf("nEnetr the name of the flag bit:");
scanf("%c",&f);
printf("nEnter the length of the message:");
scanf("%d",&l);
printf("nEnter the message :");
for(i=0;i<=l;i++)
{
str[i]=getchar();
}
str[i]='0';
printf("nn********************* BYTE STUFFING ************************nn");
printf("nMessage after Byte Stuffing is:nn" GREEN "| %c | " BLACK,f);
for(i=0,j=0;i<=l;i++)
{
if(str[i]=='E')
dest[j++]='E';
if(str[i]==f)
dest[j++]='E';
dest[j++]=str[i];
}
dest[j]='0';
for(i=0;dest[i]!='0';i++)
{
if(dest[i]=='E')
{
}
else
printf(RED "%c" BLACK,dest[i]);
if(dest[i+1]=='E')
printf("%c",dest[++i]);
printf("%c",dest[i]);
}
printf(GREEN " | %c | " BLACK,f);
18CSL51 – Network Laboratory
printf("nn********************* BYTE DESTUFFING ***********************nn");
printf("nMessage after Byte Destuffing is:nn" GREEN "| %c | " BLACK,f);
for(i=0,k=0;i<j;i++)
{
if(dest[i]=='E')
{
if(dest[i+1]=='E')
str1[k++]=dest[++i];
}
else
else
str1[k++]=dest[++i];
str1[k++]=dest[i];
}
str1[k]='0';
printf("%s",str1);
printf(GREEN " | %c |nn" BLACK,f);
}
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To know how the parity check can be used to detect the errors at the receiver side.
• To implement parity check in data link layer.
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Do the following steps in sender side:
Step 1: Read the message to be send from the user using an array.
Step 2: Count the number of 1's present in the message.
Step 3: In even parity, if the number of 1's present in the message is even then add the parity bit
value is 0 otherwise add 1 at the end of message.
Step 4: In odd parity, if the number of 1's present in the message is odd then add the parity bit
value is 0 otherwise add 1 at the end of message.
Step 5: Send the message with parity bit.
Do the following steps in receiver side:
Step 6: Read the data from the sender side.
Step 7: Count the number of 1's present in the message.
Step 8: In even parity, if the number of 1's present in the message is even then the parity value is
0 otherwise it is 1
Step 9: In odd parity, if the number of 1's present in the message is odd then the parity value is 0
otherwise it is 1.
Step 10: if the parity bit value is 0 in both cases ( even and odd parity) then the received message
is “correct” otherwise the received message is “incorrect”.
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number 07
Name of the Experiment : Implementation of Parity Check
18CSL51 – Network Laboratory
Computations to be Made:
Parity Check:
A parity bit, or check bit, is a bit added to the end of a string of binary code that indicates
whether the number of bits in the string with the value one is even or odd. Parity bits are used as the
simplest form of error detecting code.
There are two variants of parity bits: even parity bit and odd parity bit. In case of even parity,
the parity bit is set to 1, if the number of ones in a given set of bits (not including the parity bit) is odd,
making the number of ones in the entire set of bits (including the parity bit) even. If the number of ones
in a given set of bits is already even, it is set to a 0. When using odd parity, the parity bit is set to 1 if
the number of ones in a given set of bits (not including the parity bit) is even, making the number of
ones in the entire set of bits (including the parity bit) odd. When the number of set bits is odd, then the
odd parity bit is set to 0.
Even parity is a special case of a cyclic redundancy check (CRC), where the 1-bit CRC is
generated by the polynomial x+1.
If the parity bit is present but not used, it may be referred to as mark parity (when the parity bit
is always 1) or space parity (the bit is always 0).
In mathematics, parity refers to the evenness or oddness of an integer, which for a binary
number is determined only by the least significant bit. In telecommunications and computing, parity
refers to the evenness or oddness of the number of bits with value one within a given set of bits, and is
thus determined by the value of all the bits. It can be calculated via an XOR sum of the bits, yielding 0
for even parity and 1 for odd parity. This property of being dependent upon all the bits and changing
value if any one bit changes allows for its use in error detection schemes.
If an odd number of bits (including the parity bit) are transmitted incorrectly, the parity bit will
be incorrect, thus indicating that a parity error occurred in the transmission. The parity bit is only
suitable for detecting errors; it cannot correct any errors, as there is no way to determine which
particular bit is corrupted. The data must be discarded entirely, and re-transmitted from scratch. On a
noisy transmission medium, successful transmission can therefore take a long time, or even never
occur. However, parity has the advantage that it uses only a single bit and requires only a number of
XOR gates to generate. See Hamming code for an example of an error-correcting code.
Parity bit checking is used occasionally for transmitting ASCII characters, which have 7 bits,
leaving the 8th bit as a parity bit.
18CSL51 – Network Laboratory
For example, the parity bit can be computed as follows, assuming we are sending a simple 4-bit
value 1001 with the parity bit following on the right, and with ^ denoting an XOR gate:
This mechanism enables the detection of single bit errors, because if one bit gets flipped due to
line noise, there will be an incorrect number of ones in the received data. In the two examples above,
B's calculated parity value matches the parity bit in its received value, indicating there are no single bit
errors. Consider the following example with a transmission error in the second bit:
18CSL51 – Network Laboratory
There is a limitation to parity schemes. A parity bit is only guaranteed to detect an odd number
of bit errors. If an even number of bits have errors, the parity bit records the correct number of ones,
even though the data is corrupt. (See also error detection and correction.) Consider the same example as
before with an even number of corrupted bits:
Uses:
B observes even parity, as expected, thereby failing to catch the two bit errors.
Because of its simplicity, parity is used in many hardware applications where an operation can
be repeated in case of difficulty, or where simply detecting the error is helpful. For example, the SCSI
and PCI buses use parity to detect transmission errors, and many microprocessor instruction caches
include parity protection. Because the I-cache data is just a copy of main memory, it can be disregarded
and re-fetched if it is found to be corrupted.
In serial data transmission, a common format is 7 data bit, an even parity bit, and one or two
stop bits. This format neatly accommodates all the 7-bit ASCII characters in a convenient 8-bit byte.
Other formats are possible; 8 bits of data plus a parity bit can convey all 8-bit byte values.
In serial communication contexts, parity is usually generated and checked by interface hardware
(e.g., a UART) and, on reception, the result made available to the CPU (and so to, for instance, the
operating system) via a status bit in a hardware register in the interface hardware. Recovery from the
error is usually done by retransmitting the data, the details of which are usually handled by software
(e.g., the operating system I/O routines).
Parity data is used by some RAID levels to achieve redundancy. If a drive in the array fails,
remaining data on the other drives can be combined with the parity data (using the Boolean XOR
function) to reconstruct the missing data.
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• What is parity bit?
• What are the two variants of parity bit?
• What is mark parity and space parity?
• What is the advantage of parity check?
• What is the disadvantage of parity check?
• How many bits can detect and correct by using checksum, parity check and CRC?
• '^' this symbol denotes which of the following gate with respect to programming
◦ AND
◦ OR
◦ NOT
◦ Ex-OR
• What is the length of the following representations (in terms of bits):
◦ BCD
◦ ASCII
◦ EBCDIC
• List the uses of parity check.
• Find out the even parity and odd parity of the following 7-bit data:
◦ 1101101
◦ Z
◦ &
◦ ACK
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To detect errors at the receiver side using parity check.
◦ To apply this concept in RAID.
◦ To use many hardware applications such as SCSI, USB, etc.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#include<string.h>
main()
{
char mes[100],parval,sent[100],recieve[100];
int par,i,count=0;
printf("nEnter the message:");
scanf("%s",mes);
printf("n***************** EVEN PARITY *******************n");
for(i=0;mes[i]!='0';i++)
{
if(mes[i]=='1')
count++;
sent[i]=mes[i];
}
if(count%2==0)
parval='0';
else
parval='1';
sent[i]=parval;
sent[++i]='0';
printf("n***************** SENDER SIDE *******************n");
printf("nEven pairty value is :%cn",parval);
printf("nFinal Sending messgae is with parity %sn",sent);
strcpy(recieve,sent);
//recieve[3]='1'; // -> This is for checking errored frame
printf("n***************** RECEIVER SIDE *******************n");
printf("nFinal Recieved messgae is %s",recieve);
for(i=0,count=0;recieve[i]!='0';i++)
{
if(recieve[i]=='1')
count++;
}
if(count%2==0)
{
}
else
{
}
parval='0';
printf("nEven pairty value is :%cnNo Error in framenn",parval);
parval='1';
printf("nEven pairty value is :%cnError in framenn",parval);
18CSL51 – Network Laboratory
printf("n***************** ODD PARITY *******************n");
for(i=0;mes[i]!='0';i++)
{
if(mes[i]=='1')
count++;
sent[i]=mes[i];
}
if(count%2==0)
parval='1';
else
parval='0';
sent[i]=parval;
sent[++i]='0';
printf("n***************** SENDER SIDE *******************n");
printf("nOdd pairty value is :%cn",parval);
printf("nFinal Sending messgae is with parity %sn",sent);
strcpy(recieve,sent);
//recieve[3]='1'; //-> This is for checking errored frame
printf("n***************** RECEIVER SIDE *******************n");
printf("nFinal Recieved messgae is %s",recieve);
for(i=0,count=0;recieve[i]!='0';i++)
{
if(recieve[i]=='1')
count++;
}
if(count%2==0)
{
}
else
{
}
}
parval='1';
printf("nOdd pairty value is :%cnError in framenn",parval);
parval='0';
printf("nOdd pairty value is :%cnNo Error in framenn",parval);
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To know error detection methods available in data link layer for transfer the messages from
source to destination.
• To perform check-summing method in trailer part of the frame.
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Do the following steps in sender side:
Step 1: Read the total length of the message to be send from the user.
Step 2: Read the data from the user using array.
Step 3: Calculate the sum of the messages.
Step 4: Convert the decimal sum value into binary sum value.
Step 5: If the total number of bits exceeds the limit of the 'n' bits the wrap up the the binary
values into 'n' bits representation.
Step 6: Find the decimal value (checksum) for the corresponding wrapped binary value.
Step 7: Finally add it to the message list and send to the receiver end.
Do the following steps in receiver side:
Step 8: Read the data from the sender side
Step 9: Calculate the sum of the messages.
Step 10: Convert the decimal sum value into binary sum value.
Step 11: If the total number of bits exceeds the limit of the 'n' bits the wrap up the the binary
values into 'n' bits representation.
Step 12: Find the decimal value for the corresponding wrapped binary value.
Step 13: Check if the binary value(checksum) is all zeros then print “the received messages are
correct” otherwise print “error is occurred in the received data”
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number 08
Name of the Experiment : Implementation of Checksum
18CSL51 – Network Laboratory
Computations to be Made:
Checksum
A checksum or hash sum is a small-size datum computed from an arbitrary block of digital data
for the purpose of detecting errors that may have been introduced during its transmission or storage.
The integrity of the data can be checked at any later time by recomputing the checksum and comparing
it with the stored one. If the checksums match, the data was likely not accidentally altered.
The procedure that yields the checksum from the data is called a checksum function or
checksum algorithm. A good checksum algorithm will yield a different result with high probability
when the data is accidentally corrupted; if the checksums match, the data has the same high probability
of being free of accidental errors. Checksum functions are related to hash functions, fingerprints,
randomization functions, and cryptographic hash functions. However, each of those concepts has
different applications and therefore different design goals. It is important to not use a checksum in a
security related application, as a checksum does not have the properties required to protect data from
intentional tampering.
Example:
Suppose our data is a list of five 4-bit numbers that we want to send to a destination. In addition
to sending these numbers, we send the sum of the numbers. For example, if the set of numbers is (7, 11,
12, 0, 6), we send (7, 11, 12,0,6,36), where 36 is the sum of the original numbers. The receiver adds the
five numbers and compares the result with the sum. If the two are the same, the receiver assumes no
error, accepts the five numbers, and discards the sum. Otherwise, there is an error somewhere and the
data are not accepted.
We can make the job of the receiver easier if we send the negative (complement) of the sum,
called the checksum. In this case, we send (7, 11, 12,0,6, -36). The receiver can add all the numbers
received (including the checksum). If the result is 0, it assumes no error; otherwise, there is an error .
One's Complement
The previous example has one major drawback. All of our data can be written as a 4-bit word
(they are less than 15) except for the checksum. One solution is to use one's complement arithmetic. In
this arithmetic, we can represent unsigned numbers between 0 and 2n
- 1 using only n bits. t If the
number has more than n bits, the extra leftmost bits need to be added to the n rightmost bits (wrapping).
In one's complement arithmetic, a negative number can be represented by inverting all bits (changing a
0 to a 1 and a 1 to a 0). This is the same as subtracting the number from 2n
– 1.
Let us redo our example using one's complement arithmetic. Figure shows the process at the
sender and at the receiver. The sender initializes the checksum to 0 and adds all data items and the
checksum (the checksum is considered as one data item and is shown in color). The result is 36.
However, 36 cannot be expressed in 4 bits. The extra two bits are wrapped and added with the sum to
create the wrapped sum value 6. In the figure, we have shown the details in binary. The sum is then
complemented, resulting in the checksum value 9 (15 - 6 = 9). The sender now sends six data items to
the receiver including the checksum 9. The receiver follows the same procedure as the sender. It adds
all data items (including the checksum); the result is 45. The sum is wrapped and becomes 15. The
wrapped sum is complemented and becomes O. Since the value of the checksum is 0, this means that
the data is not corrupted. The receiver drops the checksum and keeps the other data items. If the
checksum is not zero, the entire packet is dropped.
18CSL51 – Network Laboratory
Internet Checksum
Traditionally, the Internet has been using a 16-bit checksum. The sender calculates the checksum by
following these steps.
Sender site:
1. The message is divided into 16-bit words.
2. The value of the checksum word is set to 0.
3. All words including the checksum are added ushtg one's complement addition.
4. The sum is complemented and becomes the checksum.
5. The checksum is sent with the data.
The receiver uses the following steps for error detection.
Receiver site:
1. The message (including checksum) is divided into 16-bit words.
2. All words are added using one's complement addition.
3. The sum is complemented and becomes the new checksum.
4. If the value of checksum is 0, the message is accepted; otherwise, it is rejected.
The nature of the checksum (treating words as numbers and adding and complementing them) is
well-suited for software implementation. Short programs can be written to calculate the checksum at
the receiver site or to check the validity of the message at the receiver site.
18CSL51 – Network Laboratory
Example:
Let us calculate the checksum for a text of 8 characters ("Forouzan"). The text needs to be
divided into 2-byte (l6-bit) words. We use ASCII to change each byte to a 2-digit hexadecimal number.
For example, F is represented as Ox46 and 0 is represented as Ox6F. Figure 10.25 shows how the
checksum is calculated at the sender and receiver sites. In part a of the figure, the value of partial sum
for the first column is Ox36. We keep the rightmost digit (6) and insert the leftmost dight (3) as the
carry in the second column. The process is repeated for each column. Note that if there is any
corruption, the checksum recalculated by the receiver is not all as. We leave this an exercise.
Questions and problems for assessing the achievement of objective:
• What is single-bit error?
• What is burst error?
• How does a single bit error is differ from burst error?
• What kind of arithmetic is used to add data items in checkum calculation?
• Define checksum.
• What is Internet Checksum?
• What kind of error is undetectable b the checksum?
• Do the internet checksum operation at sender side of the following data
◦ ANDREW TANENBAUM
◦ DAVID WETHERALL
• Do the internet checksum operation at sender side of the following data
◦ 7,11,12,0,6
◦ 12,4,8,6,4,5,2,14
• How can we represent the number 21 in one's complement arithmetic using only four bits?
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To detect the error at receiver side.
◦ To apply this concept in their project work.
◦ To send error free data.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int a[10],n,sum=0,i,binary[100]={0};
int j,binary1[100],l,result[10],c=0,k;
int sum1;
printf("n************** SENDER SIDE ******************n");
printf("nEnter the total length of message:");
scanf("%d",&n);
printf("nEnter the data one by one :");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
printf("nThe messages are:");
for(i=0;i<n;i++)
printf("n%d",a[i]);
printf("nThe sum is: %d",sum);
for(i=0;sum>0;i++)
{
binary1[i]=sum%2;
sum=sum/2;
}
for(;i<8;i++)
binary1[i]=0;
l=i;
for(i=l-1,j=0;i>=0;i--,j++)
binary[j]=binary1[i];
printf("nThe equivalent binary digit is :");
for(i=0;i<l;i++)
printf("%d",binary[i]);
for(c=0,i=l-1;i>=4;i--) {
if(c==0) {
if(binary[i]==1&&binary[i-4]==1) {
result[i-4]=0;
c=1;
}
else if(binary[i]==1&&binary[i-4]==0) {
result[i-4]=1;
c=0;
}
else if(binary[i]==0&&binary[i-4]==0) {
18CSL51 – Network Laboratory
}
else {
}
else {
}
result[i-4]=0;
c=0;
result[i-4]=1;
c=0;
if(binary[i]==1&&binary[i-4]==1) {
result[i-4]=1;
c=1;
}
else if(binary[i]==1&&binary[i-4]==0) {
result[i-4]=0;
c=1;
}
else if(binary[i]==0&&binary[i-4]==0) {
result[i-4]=1;
c=0;
}
else {
}
}
}
result[i-4]=0;
c=1;
printf("nThe binary value of wrapped sum is:");
for(i=0;i<4;i++)
printf("%d",result[i]);
printf("nThe binary value of checksum is:");
for(i=0,sum=0,j=3;i<4;i++,j--)
{
sum1=1;
if(result[i]==1)
result[i]=0;
else
result[i]=1;
for(k=1;k<=j;k++,sum1=sum1*2);
sum=sum+(result[i]*sum1);
printf("%d",result[i]);
}
printf("nThe checksum value is : %d",sum);
printf("nThe sender side sending messages are:");
a[n++]=sum;
for(i=0;i<n;i++)
printf("n%d",a[i]);
18CSL51 – Network Laboratory
printf("nn*************** RECEIVER SIDE ****************nn");
printf("nThe Reciever side messages recieved messages are:");
sum=0;
//a[0]=3; //to check incorrect message
for(i=0;i<n;i++)
{
printf("n%d",a[i]);
sum=sum+a[i];
}
printf("nThe sum is: %d",sum);
for(i=0;sum>0;i++)
{
binary1[i]=sum%2;
sum=sum/2;
}
for(;i<8;i++)
binary1[i]=0;
l=i;
for(i=l-1,j=0;i>=0;i--,j++)
binary[j]=binary1[i];
printf("nThe equivalent binary digit is :");
for(i=0;i<l;i++)
printf("%d",binary[i]);
for(c=0,i=l-1;i>=4;i--) {
if(c==0) {
if(binary[i]==1&&binary[i-4]==1) {
result[i-4]=0;
c=1;
}
else if(binary[i]==1&&binary[i-4]==0) {
result[i-4]=1;
c=0;
}
else if(binary[i]==0&&binary[i-4]==0) {
result[i-4]=0;
c=0;
}
else {
result[i-4]=1;
c=0;
}
else {
}
if(binary[i]==1&&binary[i-4]==1) {
result[i-4]=1;
c=1;
}
18CSL51 – Network Laboratory
else if(binary[i]==1&&binary[i-4]==0) {
result[i-4]=0;
c=1;
}
else if(binary[i]==0&&binary[i-4]==0) {
result[i-4]=1;
c=0;
}
else {
}
}
}
result[i-4]=0;
c=1;
printf("nThe binary value of wrapped sum is:");
for(i=0;i<4;i++)
printf("%d",result[i]);
printf("nThe binary value of checksum is:");
for(i=0,sum=0,j=3;i<4;i++,j--)
{
sum1=1;
if(result[i]==1)
result[i]=0;
else
result[i]=1;
for(k=1;k<=j;k++,sum1=sum1*2);
sum=sum+(result[i]*sum1);
printf("%d",result[i]);
}
printf("nThe checksum value is : %d",sum);
if(sum==0)
printf("nThe recieved message is correctn");
else
printf("nThe recieved message is incorrectn");
}
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To know detect the errors at the receiver side.
• To implement CRC method for error detection in data link layer.
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Do the following steps in sender side:
Step 1: Read the dataword (message) to be send from the user using an array.
Step 2: Read the 'n' bit common divisor from the user using an array.
Step 3: At sender side append n-1 zeros in dataword
Step 4: check if the MSB bit position of the divisor and dataword is same then do the Ex-OR
operation as stated below
crc[j]=itoc((ctoi(crc[j]))^(ctoi(div[j])));
Step 5: Repeat step 4 until the LSB bit of the dataword comes to end. Finally the n-1 bit
remainder value (CRC value) is replaced with appended zeros
position of the dataword. This message is called codeword.
Step 6: At last, the codeword (dataword+remainder) is send to the receiver.
Do the following steps in receiver side:
Step 7: Read the codeword rom the sender side
Step 8: check if the MSB bit position of the divisor and dataword is same then do the Ex-OR
operation as stated below
crc[j]=itoc((ctoi(crc[j]))^(ctoi(div[j])));
Step 9: Repeat step 4 until the LSB bit of the dataword comes to end.
Step 10: Display the receiver side remainder value.
Step 11: Check if the remainder value is all zeros then print “the received messages are
correct” otherwise print “error is occurred in the received data”
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number 09
Name of the Experiment : Implementation of CRC
18CSL51 – Network Laboratory
Computations to be Made:
CRC
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks
and storage devices to detect accidental changes to raw data. Blocks of data entering these systems get
a short check value attached, based on the remainder of a polynomial division of their contents; on
retrieval the calculation is repeated, and corrective action can be taken against presumed data
corruption if the check values do not match.
CRCs are so called because the check (data verification) value is a redundancy (it expands the
message without adding information) and the algorithm is based on cyclic codes. CRCs are popular
because they are simple to implement in binary hardware, easy to analyze mathematically, and
particularly good at detecting common errors caused by noise in transmission channels. Because the
check value has a fixed length, the function that generates it is occasionally used as a hash function.
The CRC was invented by W. Wesley Peterson in 1961; the 32-bit polynomial used in the CRC
function of Ethernet and many other standards is the work of several researchers and was published
during 1975.
CRC Operation
18CSL51 – Network Laboratory
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• Name the coding categories.
• What is modular arithmetic?
• What is cyclic codes?
• Write the Ex-OR operation.
• In CRC, show the relationship between the following entities ( size means the number of bits)
◦ The size of the dataword and the size of the codeword
◦ The size of the divisor and the remainder
◦ The degree of the polynomial generator and the size of the divisor
◦ The degree of the polynomial generator and the size of the remainder
• Given the dataword 1010011010 and the divisor 10111
◦ show the generation of codeword at the sender side ( using binary division)
◦ show the checking of the code word at he receiver side (assume no error)
◦ show the checking of the code word at he receiver side (assume 5th
bit is error from left to
right)
• Which of the following CRC generators guarantee the detection of a single bit error?
◦ X4
+ X2
◦ X3
+ X+1
◦ X2
+ 1
◦ 1
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To detect errors at the receiver side.
◦ To perform CRC error detection method in data link layer.
◦ To apply this concept in their project work.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#include<string.h>
int ctoi(char a) {
return (a-48);
}
char itoc(int a) {
return (a+48);
}
void main()
{
char ip[100],ipm[100],div[20],crc[10],sent[100],rec[100];
int i,lm,ld,j;
printf("n************ SENDER SIDE(CRC ENCODING)***********n");
printf("nEnter Data Word ( Message):");
scanf("%s",ip);
printf("nEnter Divisor :");
scanf("%s",div);
strcpy(ipm,ip);
lm=strlen(ipm);
ld=strlen(div);
if(lm>=ld)
{
for(i=lm,j=0;j<ld-1;j++)
ipm[i++]='0';
ipm[i]='0';
printf("nThe Data Word After Appending Zeros: %s",ipm);
for(i=0;i<ld;i++)
crc[i]=ipm[i];
crc[i]='0';
for(;i<strlen(ipm);i++)
{
if(crc[0]=='1')
{
for(j=0;j<ld;j++)
{
crc[j]=itoc((ctoi(crc[j]))^(ctoi(div[j])));
}
}
crc[ld]=ipm[i];
crc[ld+1]='0';
for(j=0;crc[j]!='0';j++)
crc[j]=crc[j+1];
crc[j]='0';
}
18CSL51 – Network Laboratory
for(j=0;crc[j]!='0';j++)
crc[j]=crc[j+1];
crc[j]='0';
printf("nThe CRC Remainder is : %s",crc);
strcat(sent,ip);
strcat(sent,crc);
printf("nThe Code Word in sender side is: %s",sent);
printf("nn************ RECEIVER SIDE(CRC DECODING)*************");
strcpy(rec,sent);
//rec[2]='1'; // to check error data
printf("nnThe recieved message in reciever side is: %s",rec);
for(i=0;i<ld;i++)
crc[i]=rec[i];
crc[i]='0';
for(;i<strlen(rec);i++)
{
if(crc[0]=='1')
{
for(j=0;j<ld;j++)
{
crc[j]=itoc((ctoi(crc[j]))^(ctoi(div[j])));
}
}
crc[ld]=rec[i];
crc[ld+1]='0';
for(j=0;crc[j]!='0';j++)
crc[j]=crc[j+1];
crc[j]='0';
}
for(j=0;crc[j+1]!='0';j++)
crc[j]=crc[j+1];
crc[j]='0';
for(j=0;crc[j]!='0';j++)
{
if(crc[j]!='0')
break;
}
}
else
printf("nnThe CRC Remainder is: %s",crc);
if(j==strlen(crc))
printf("nnThe received message is error free!nn");
else
printf("nError in recieved message!!!nn");
printf("nEnter proper divisor");
}
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To understand the uses of IP address.
• To know the various classes of IP Address and range of each classes IP Address.
• To identify the classes of IP Address.
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Step 1: Read the IP Address as input from the user (ex. 10.1.1.1) using character array ip[100].
Step 2: Find out the string length using strlen() function.
Step 3: Check out the IP address format using isdigit() function (ex. 12.3a.1.1, 10/1.1.1.12 are
incorrect IP Address format)
Step 4: Check the loopback IP address (127.0.0.0) by using strcmp() function .
Step 5: Convert the IP address as decimal number from string by using the following line of
coding
for(i=0,s1=0;ip[i]!='.';i++)
s1=(s1*10)+ip[i]-48;
Step 6: Check the IP address range from 0 to 255 for each part (totally 4: namely s1,s2,s3, s4)
Step 7: Check and print the classes of IP address according to the first portion of the IP address
range.
Step 8: If s1 range of IP address is between 0 to 127 then print the IP address is Class A.
Step 9: If s1 range of IP address is between 128 to 191 then print the IP address is Class B.
Step 10: If s1 range of IP address is between 192 to 223 then print the IP address is Class C.
Step 11: If s1 range of IP address is between 224 to 239 then print the IP address is Class D.
Step 12: If s1 range of IP address is between 240 to 255 then print the IP address is Class E.
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number 10
Name of the Experiment : Finding the Classes of IP Address
18CSL51 – Network Laboratory
Computations to be Made:
An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g.,
computer, printer) participating in a computer network that uses the Internet Protocol for
communication. An IP address serves two principal functions: host or network interface identification
and location addressing. Its role has been characterized as follows: "A name indicates what we seek.
An address indicates where it is. A route indicates how to get there."
The designers of the Internet Protocol defined an IP address as a 32-bit number and this system,
known as Internet Protocol Version 4 (IPv4), is still in use today. However, due to the enormous
growth of the Internet and the predicted depletion of available addresses, a new version of IP (IPv6),
using 128 bits for the address, was developed in 1995. IPv6 was standardized as RFC 2460 in 1998,
and its deployment has been ongoing since the mid-2000s.
IP addresses are binary numbers, but they are usually stored in text files and displayed in
human-readable notations, such as 172.16.254.1 (for IPv4), and 2001:db8:0:1234:0:567:8:1 (for IPv6).
The Internet Assigned Numbers Authority (IANA) manages the IP address space allocations
globally and delegates five regional Internet registries (RIRs) to allocate IP address blocks to local
Internet registries (Internet service providers) and other entities.
Note : The following test cases should be done
• IP address format
• Check IP Address range is 0 – 255 in each part.
• Check Loopback IP Address
• Check Multicast IP addresses
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• List the range for each classes of IP address.
• Define Unicast, Multicast, Broadcast.
• What is Loopback Ip Address? Mention the Use of it.
• What is the Length of Ipv4 and Ipv6?
• What is ICANN?
• What is IANA?
• List the IANA reserved private Ipv4 network ranges.
• What is CIDR?
• What is Subnetting and Supernetting?
• Give an example for Ipv6.
• What is NAT?
• Find the error, if any, in the following Ipv4 address.
◦ 111.56.045.78
◦ 221.34.7.8.20
◦ 75.45.301.14
◦ 11100010.23.14.67
• Find the classes of each IP address
◦ 00000001 00001011 00001011 11101111
◦ 11000001 10000011 00011011 11111111
◦ 14.23.120.8
◦ 252.5.15.111
• Write the uses of the following IP addresses
◦ 0.0.0.0
◦ 10.0.0.0
◦ 127.0.0.0.
◦ 172.16.0.0
◦ 192.168.0.0
◦ 224.0.0.0
◦ 240.0.0.0
◦ 255.255.255.255
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To assign IP address for computer.
◦ To find the classe of IP Address.
◦ To differentiate unicast, multicast, broadcast IP addresses.
◦ To use the various private IP addresses.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
main()
{
char ip[100],part1[100],part2[100],part3[100],part4[100];
int i,j,s1,s2,s3,s4,c,sp,d,l;
printf("nn ***************** IP ADDRESS CLASSES ********************nn");
printf("nEnter IP Address : ");
scanf("%s",ip);
l=strlen(ip);
// Testt Case 1: To Check IP Address Format
for(i=0,d=0;ip[i]!='0';i++)
{
if(isdigit(ip[i]))
d++;
else if((ip[i]=='.')&&(d>0))
d=0;
else
break;
}
if(d==0||(i<l))
{
printf("n The IP Address is in Wrong Format !!! n ");
printf("So please enter correct IP Address:n");
main();
}
// Test Case 2: To Check Loopback IP Address
else if(strcmp(ip,"127.0.0.0")==0)
printf("n%s is a Loopback addressnn");
18CSL51 – Network Laboratory
else
{
// To Convert the the IP Address as Decimal Number from String
for(i=0,s1=0;ip[i]!='.';i++)
s1=(s1*10)+ip[i]-48;
for(i=i+1,s2=0;ip[i]!='.';i++)
s2=(s2*10)+ip[i]-48;
for(i=i+1,s3=0;ip[i]!='.';i++)
s3=(s3*10)+ip[i]-48;
for(i=i+1,s4=0;ip[i]!='0';i++)
s4=(s4*10)+ip[i]-48;
// Test Case 3: To Check IP Addess Range 0 - 255 for each part
if((s1>255)||(s2>255)||(s3>255)||(s4>255))
{
}
else
{
printf("n The IP Address is in Wrong Format !!! n");
printf("So please enter correct IP Address:n");
main();
// To Find the Classess of IP Address
if((s1>=0)&&(s1<128))
printf("n %s is Class A IP Addressnn",ip);
else if((s1>127)&&(s1<192))
printf("n %s is Class B IP Addressnn",ip);
else if((s1>191)&&(s1<224))
printf("n %s is Class C IP Addressnn",ip);
else if((s1>223)&&(s1<240))
printf("n %s is Class D IP Addressnn",ip);
else
printf("n %s is Class E IP Addressnn",ip);
}
}
}
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To know the use of ARP protocol
• To mapping logical (IP) to physical address (MAC).
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Step 1: Create an ARP table which contains the IP Address and their corresponding MAC
address. And store it as “ARPTABLE.txt” in home directory.
Step 2: Create an file descriptor or file pointer to access the file (ARPTABLE.txt) using FILE.
FILE *f1;
Step 3: First read the file contents using fopen() funtion.
f1=fopen("/student/ARPTABLE.txt","r");
Step 4: Check if the file pointer value is null the display the error message. Otherwise read the
IP address from the user.
Step 5: Check the IP address is in correct format by using the test case.
Step 6: Read the IP address and MAC address from ARP table by using fscanf() function.
fscanf(f1,"%s%s",ip,mac)
Step 7: Compare the user IP address with ARP table IP address by using strcmp() function.
strcmp(inip,ip)
Step 8: If the IP address matches with APR table then print the corresponding MAC address of
the IP address.
Step 9: Otherwise check file thoroughly by using feof() funtion.
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number 11
Name of the Experiment : Implementation of ARP
18CSL51 – Network Laboratory
Computations to be Made:
ARP:
Address Resolution Protocol (ARP) is a telecommunications protocol used for resolution of
network layer addresses into link layer addresses, a critical function in multiple-access networks. ARP
was defined by RFC 826 in 1982. It is Internet Standard STD 37. It is also the name of the program for
manipulating these addresses in most operating systems.
ARP is used to convert an IP address to a physical address such as an Ethernet address. ARP
has been implemented with many combinations of network and data link layer technologies, such as
IPv4, Chaosnet, DECnet and Xerox PARC Universal Packet (PUP) using IEEE 802 standards, FDDI,
X.25, Frame Relay and Asynchronous Transfer Mode (ATM). IPv4 over IEEE 802.3 and IEEE 802.11
is the most common case.
In Internet Protocol Version 6 (IPv6) networks, the functionality of ARP is provided by the
Neighbor Discovery Protocol (NDP).
The Address Resolution Protocol is a request and reply protocol that runs encapsulated by the
line protocol. It is communicated within the boundaries of a single network, never routed across
internetwork nodes. This property places ARP into the Link Layer of the Internet Protocol Suite, while
in the Open Systems Interconnection (OSI) model, it is often described as residing between Layers 2
and 3, being encapsulated by Layer 2 protocols. However, ARP was not developed in the OSI
framework.
Proxy ARP:
Proxy ARP (Address Resolution Protocol) is a technique by which a device on a given network
answers the ARP queries for a network address that is not on that network. The ARP Proxy is aware of
the location of the traffic's destination, and offers its own MAC address in reply, effectively saying,
"send it to me, and I'll get it to where it needs to go." Serving as an ARP Proxy for another host
effectively directs LAN traffic to the Proxy. The "captured" traffic is then typically routed by the Proxy
to the intended destination via another interface or via a tunnel.
The process which results in the node responding with its own MAC address to an ARP request
for a different IP address for proxying purposes is sometimes referred to as 'publishing'.
ARP Spoofing:
ARP spoofing is a technique whereby an attacker sends fake ("spoofed") Address Resolution
Protocol (ARP) messages onto a Local Area Network. Generally, the aim is to associate the attacker's
MAC address with the IP address of another host (such as the default gateway), causing any traffic
meant for that IP address to be sent to the attacker instead.
ARP spoofing may allow an attacker to intercept data frames on a LAN, modify the traffic, or
stop the traffic altogether. Often the attack is used as an opening for other attacks, such as denial of
service, man in the middle, or session hijacking attacks.
The attack can only be used on networks that make use of the Address Resolution Protocol
(ARP), and is limited to local network segments.
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• What is physical address?
• What is logical address?
• How to map a logical address to its corresponding physical address and vice versa?
• What protocol is used to map logical to physical address?
• What are all the protocol is used to map physical to logical address?
• Draw the ARP Packet format.
• What is mean by APR table?
• Which one of the following is broadcast and unicast:
◦ APR request
◦ ARP reply
• What is the use of proxy ARP?
• Define ARP spoofing.
• Type the following commands in your terminal and make a note what you understand.
◦ $ ping www.google.com
◦ $ traceroute www.google.com
• What is the length of the following addresses ( in terms of bits):
◦ Port Address
◦ IP Address
◦ MAC Address
◦ IPv6 Address
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To map the MAC address for the corresponding IP address of the computer.
◦ To make use of the IP address and MAC address in their project work.
◦ To assign, modify and delete the ARP table in server.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main()
{
FILE *f1;
int i,d,l;
char mac[100],ip[100],inip[100];
f1=fopen("/root/ARPTABLE.txt","r");
printf("n**************** ADDRESS RESOLUTION PROTOCOL*************nn");
if(f1==NULL)
printf("nCann't open the file");
else
{
printf("nEnter the ip address of the host:");
scanf("%s",inip);
l=strlen(inip);
for(i=0,d=0;inip[i]!='0';i++) {
if(isdigit(inip[i]))
d++;
else if((inip[i]=='.')&&(d>0))
d=0;
else
break;
}
if(d==0||(i<l)) {
printf("n The IP Address is in Wrong Format !!! n");
printf("n So please enter correct IP Address.n");
main();
}
else {
while((fscanf(f1,"%s%s",ip,mac))==2) {
if(strcmp(inip,ip)==0)
{
printf("nThe Equivalent MAC address is %snn",mac);
break;
}
}
Databasen");
}
}
}
if(feof(f1))
printf("nEquivalent MAC address is not present in Database. So update your
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To know the use of RARP protocol.
• To mapping physical address (MAC) to logical (IP).
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Step 1: Create an ARP table which contains the IP Address and their corresponding MAC
address. And store it as “ARPTABLE.txt” in home directory.
Step 2: Create an file descriptor or file pointer to access the file (ARPTABLE.txt) using FILE.
FILE *f1;
Step 3: First read the file contents using fopen() funtion.
f1=fopen("/student/ARPTABLE.txt","r");
Step 4: Check if the file pointer value is null the display the error message. Otherwise read the
MAC address from the user.
Step 5: Check the MAC address is in correct format by using the test case.
Step 6: Read the IP address and MAC address from ARP table by using fscanf() function.
fscanf(f1,"%s%s",ip,mac)
Step 7: Compare the user MAC address with ARP table MAC address by using strcmp()
function.
strcmp(inmac,mac)
Step 8: If the MAC address matches with APR table then print the corresponding IP address of
the MAC address.
Step 9: Otherwise check file thoroughly by using feof() funtion.
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number 12
Name of the Experiment : Implementation of RARP
18CSL51 – Network Laboratory
Computations to be Made:
RARP:
The Reverse Address Resolution Protocol (RARP) is an obsolete computer networking protocol
used by a host computer to request its Internet Protocol (IPv4) address from an administrative host,
when it has available its Link Layer or hardware address, such as a MAC address.
RARP is described in Internet Engineering Task Force (IETF) publication RFC 903. It has been
rendered obsolete by the Bootstrap Protocol (BOOTP) and the modern Dynamic Host Configuration
Protocol (DHCP), which both support a much greater feature set than RARP.
RARP requires one or more server hosts to maintain a database of mappings of Link Layer
addresses to their respective protocol addresses. Media Access Control (MAC) addresses needed to be
individually configured on the servers by an administrator. RARP was limited to serving only IP
addresses.
Reverse ARP differs from the Inverse Address Resolution Protocol (InARP) described in RFC
2390, which is designed to obtain the IP address associated with a local Frame Relay data link
connection identifier. InARP is not used in Ethernet.
The machine can get its physical address (by reading its NIC, for example), which is unique
locally. It can then use the physical address to get the logical address by using the RARP protocol. A
RARP request is created and broadcast on the local network. Another machine on the local network
that knows all the IP addresses will respond with a RARP reply. The requesting machine must be
running a RARP client program; the responding machine must be running a RARP server program.
There is a serious problem with RARP: Broadcasting is done at the data link layer. The physical
broadcast address, all is in the case of Ethernet, does not pass the boundaries of a network. This means
that if an administrator has several networks or several subnets, it needs to assign a RARP server for
each network or subnet. This is the reason that RARP is almost obsolete. Two protocols, BOOTP and
DHCP, are replacing RARP.
MAC Address Format:
18CSL51 – Network Laboratory
BOOTP:
In computer networking, the Bootstrap Protocol, or BOOTP, is a network protocol used by a
network client to obtain an IP address from a configuration server. The BOOTP protocol was originally
defined in RFC 951.
BOOTP is usually used during the bootstrap process when a computer is starting up. A BOOTP
configuration server assigns an IP address to each client from a pool of addresses. BOOTP uses the
User Datagram Protocol (UDP) as a transport on IPv4 networks only.
Historically, BOOTP has also been used for Unix-like diskless workstations to obtain the
network location of their boot image in addition to an IP address, and also by enterprises to roll out a
pre-configured client (e.g., Windows) installation to newly installed PCs.
Originally requiring the use of a boot floppy disk to establish the initial network connection,
manufacturers of network cards later embedded the protocol in the BIOS of the interface cards as well
as system boards with on-board network adapters, thus allowing direct network booting.
The Dynamic Host Configuration Protocol (DHCP) is a more advanced protocol for the same
purpose and has superseded the use of BOOTP. Most DHCP servers also function as BOOTP servers.
DHCP:
The Dynamic Host Configuration Protocol (DHCP) is a network protocol used to configure
devices that are connected to a network so they can communicate on that network using the Internet
Protocol (IP). The protocol is implemented in a client-server model, in which DHCP clients request
configuration data, such as an IP address, a default route, and one or more DNS server addresses from a
DHCP server.
An example of use of the protocol is in a residential local area network (LAN). In this case, a
DHCP server is contained in the router while the clients are hosts, e.g., personal computers, smart
phones, or printers on the local network. The router itself is a client within the network of the Internet
service provider (ISP) and receives its configuration information upstream from the ISP's DHCP
server.
A DHCP server maintains a database of available IP addresses and configuration information.
When the server receives a request from a client, the DHCP server determines the network to which the
DHCP client is connected, and then allocates an IP address or prefix that is appropriate for the client,
and sends configuration information appropriate for that client. DHCP servers typically grant IP
addresses to clients only for a limited interval. DHCP clients are responsible for renewing their IP
address before that interval has expired, and must stop using the address once the interval has expired,
if they have not been able to renew it.
DHCP is used for Internet Protocol version 4 (IPv4), as well as IPv6. While both versions serve
the same purpose, the details of the protocol for IPv4 and IPv6 are sufficiently different that they may
be considered separate protocols.
Hosts that do not use DHCP for address configuration may still use it to obtain other
configuration information. Alternatively, IPv6 hosts may use stateless address autoconfiguration. IPv4
hosts may use link-local addressing to achieve limited local connectivity.
18CSL51 – Network Laboratory
Questions and problems for assessing the achievement of objective:
• What are the protocols are used to map physical to logical address?
• What is the problem with RARP protocol?
• What is BOOTP?
• What is DHCP?
• What is InARP? In what ways this protocol is differs from ARP?
• What is the advantage of DHCP protocol?
• What is the use of FF:FF:FF:FF:FF:FF MAC address?
• What is the protocol used to map MAC to IP in Wi-Fi?
• Write an Example of the following
◦ Host Name or Host Addressing
◦ Port Address
◦ IP Address
◦ MAC Address
• Find the odd man out
◦ ARP
◦ RARP
◦ BOOTP
◦ DHCP
• In which layer the following protocols are used:
◦ ARP
◦ InARP
◦ RARP
◦ BOOTP
◦ DHCP
Outcome of the Experiment / Practical work:
• On completion of the experiment the students will be able to
◦ To map the IP address for the corresponding MAC address of the computer.
◦ To make use of the IP address and MAC address in their project work.
◦ To assign, modify and delete the ARP table in server.
18CSL51 – Network Laboratory
Program:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main()
{
FILE *f1;
int i,sp;
char mac[100],ip[100],inmac[100];
f1=fopen("/root/ARPTABLE.txt","r");
printf("n*********** REVERSE ADDRESS RESOLUTION PROTOCOL**********nn");
if(f1==NULL)
printf("nCann't open the file");
else
{
printf("nEnter the MAC Address of the Host:");
scanf("%s",inmac);
for(i=0,sp=0;inmac[i]!='0';i++)
{
if(!isalnum(inmac[i]))
sp++;
if(islower(inmac[i])||((inmac[i]-65)>5))
break;
}
if(inmac[i]!='0'|| (sp!=5))
{
}
else
{
printf("nThe MAC address is not in exact formatn");
printf("nSo please enter correct MAC Address.n");
main();
while((fscanf(f1,"%s%s",ip,mac))==2)
{
if(strcmp(inmac,mac)==0)
{
printf("nThe Equivalent IP Address is: %snn",ip);
break;
}
}
if(feof(f1))
printf("nEquivalent IP address is not present in Database. So update your Databasen");
}
}
}
18CSL51 – Network Laboratory
Sample Output:
18CSL51 – Network Laboratory
Objectives of the Experiment / Practical work:
Resource Required:
Step-wise Experimental Procedure:
On completion of the experiment the students will be able to
• To know the responsibilities of network layer.
• To understand how the packets are routed within the Autonomous System by using OSPF
routing protocol.
• To understand the Link State (LS) routing algorithm.
• To know the use of Dijkstra's Algorithm.
• To know the various routing protocols and its use.
• OS : Linux / Windows
• C Compiler : cc or gcc / Turbo C
• Text Editor : vi or gedit / notepad
Step 1: Read the number of nodes in the autonomous system.
Step 2: Read the cost matrix values by using an array ( Note: use 999 for infinity symbol (∞)).
Step 3: Display the cost matrix.
Step 4: Find the shortest path by calling the dijkstra's algorithm
lcost=dij(a,n,0,v2);
Step 5: In dij() function, find the minimum cost path by calling the srch_min() function.
j=srch_min(length,set,n);
Step 6: Display the shortest path for all neighbor node from the source node.
Course Code : 18CSL51
Course Name : Network Laboratory
Experiment Number 13
Name of the Experiment : Implementation of OSPF Routing Protocol
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf
18CSL51 - Network Lab Manual.pdf

More Related Content

Similar to 18CSL51 - Network Lab Manual.pdf

study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
Jayaprasanna4
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
AAKASH S
 

Similar to 18CSL51 - Network Lab Manual.pdf (20)

NS2 (1).docx
NS2 (1).docxNS2 (1).docx
NS2 (1).docx
 
Tut hemant ns2
Tut hemant ns2Tut hemant ns2
Tut hemant ns2
 
Ns2
Ns2Ns2
Ns2
 
Ns 2 Network Simulator An Introduction
Ns 2 Network Simulator An IntroductionNs 2 Network Simulator An Introduction
Ns 2 Network Simulator An Introduction
 
Ns tutorial
Ns tutorialNs tutorial
Ns tutorial
 
Ns2: OTCL - PArt II
Ns2: OTCL - PArt IINs2: OTCL - PArt II
Ns2: OTCL - PArt II
 
opnet lab report
opnet lab reportopnet lab report
opnet lab report
 
Network simulator 2 a simulation tool for linux
Network simulator 2 a simulation tool for linuxNetwork simulator 2 a simulation tool for linux
Network simulator 2 a simulation tool for linux
 
link-state-routing-3.pdf
link-state-routing-3.pdflink-state-routing-3.pdf
link-state-routing-3.pdf
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
Ns network simulator
Ns network simulatorNs network simulator
Ns network simulator
 
NP-lab-manual.docx
NP-lab-manual.docxNP-lab-manual.docx
NP-lab-manual.docx
 
NP-lab-manual (1).pdf
NP-lab-manual (1).pdfNP-lab-manual (1).pdf
NP-lab-manual (1).pdf
 
NP-lab-manual.pdf
NP-lab-manual.pdfNP-lab-manual.pdf
NP-lab-manual.pdf
 
Ns2
Ns2Ns2
Ns2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Network simulator 2
Network simulator 2Network simulator 2
Network simulator 2
 
Ns2 ns3 training in mohali
Ns2 ns3 training in mohaliNs2 ns3 training in mohali
Ns2 ns3 training in mohali
 

More from Selvaraj Seerangan

Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Selvaraj Seerangan
 
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
Selvaraj Seerangan
 

More from Selvaraj Seerangan (20)

Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
Unit 2,3,4 _ Internet of Things A Hands-On Approach (Arshdeep Bahga, Vijay Ma...
 
Unit 5 _ Fog Computing .pdf
Unit 5 _ Fog Computing .pdfUnit 5 _ Fog Computing .pdf
Unit 5 _ Fog Computing .pdf
 
CAT III Answer Key.pdf
CAT III Answer Key.pdfCAT III Answer Key.pdf
CAT III Answer Key.pdf
 
END SEM _ Design Thinking _ 16 Templates.pptx
END SEM _ Design Thinking _ 16 Templates.pptxEND SEM _ Design Thinking _ 16 Templates.pptx
END SEM _ Design Thinking _ 16 Templates.pptx
 
Design Thinking _ Complete Templates.pptx
Design Thinking _ Complete Templates.pptxDesign Thinking _ Complete Templates.pptx
Design Thinking _ Complete Templates.pptx
 
CAT 3 _ List of Templates.pptx
CAT 3 _ List of Templates.pptxCAT 3 _ List of Templates.pptx
CAT 3 _ List of Templates.pptx
 
[PPT] _ Unit 5 _ Evolve.pptx
[PPT] _ Unit 5 _ Evolve.pptx[PPT] _ Unit 5 _ Evolve.pptx
[PPT] _ Unit 5 _ Evolve.pptx
 
[PPT] _ Unit 4 _ Engage.pptx
[PPT] _ Unit 4 _ Engage.pptx[PPT] _ Unit 4 _ Engage.pptx
[PPT] _ Unit 4 _ Engage.pptx
 
[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptx[PPT] _ Unit 3 _ Experiment.pptx
[PPT] _ Unit 3 _ Experiment.pptx
 
CAT 2 _ List of Templates.pptx
CAT 2 _ List of Templates.pptxCAT 2 _ List of Templates.pptx
CAT 2 _ List of Templates.pptx
 
Design Thinking - Empathize Phase
Design Thinking - Empathize PhaseDesign Thinking - Empathize Phase
Design Thinking - Empathize Phase
 
CAT-II Answer Key.pdf
CAT-II Answer Key.pdfCAT-II Answer Key.pdf
CAT-II Answer Key.pdf
 
PSP LAB MANUAL.pdf
PSP LAB MANUAL.pdfPSP LAB MANUAL.pdf
PSP LAB MANUAL.pdf
 
DS LAB MANUAL.pdf
DS LAB MANUAL.pdfDS LAB MANUAL.pdf
DS LAB MANUAL.pdf
 
CAT 1 _ List of Templates.pptx
CAT 1 _ List of Templates.pptxCAT 1 _ List of Templates.pptx
CAT 1 _ List of Templates.pptx
 
[PPT] _ UNIT 1 _ COMPLETE.pptx
[PPT] _ UNIT 1 _ COMPLETE.pptx[PPT] _ UNIT 1 _ COMPLETE.pptx
[PPT] _ UNIT 1 _ COMPLETE.pptx
 
CAT-1 Answer Key.doc
CAT-1 Answer Key.docCAT-1 Answer Key.doc
CAT-1 Answer Key.doc
 
Unit 3 Complete.pptx
Unit 3 Complete.pptxUnit 3 Complete.pptx
Unit 3 Complete.pptx
 
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
[PPT] _ Unit 2 _ 9.0 _ Domain Specific IoT _Home Automation.pdf
 
[PPT] _ Unit 2 _ Complete PPT.pptx
[PPT] _ Unit 2 _ Complete PPT.pptx[PPT] _ Unit 2 _ Complete PPT.pptx
[PPT] _ Unit 2 _ Complete PPT.pptx
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 

18CSL51 - Network Lab Manual.pdf

  • 1. 18CSL51 - Network Laboratory Manual SCHOOL OF COMMUNICATION AND COMPUTER SCIENCES DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
  • 2. 18CSL51 – Network Laboratory 18CSL51 NETWORK LABORATORY Sem Category L T P Credit V PC 0 0 2 1 Preamble It provides an exposure to implement the various services offered by network layers and to measure the network performance. Also provide the knowledge to develop client/server applications using TCP and UDP. Prerequisites Nil List of Exercises / Experiments : 1. Simulation of network topologies (bus, ring, star and mesh) using NS2 Simulator. 2. Write a AWK script to measure the network performance using NS2 Simulator 3. Write a simple program to calculate various delays such as propagation delay, transmission delay, total delay and end-to-end delay. 4. Write a program to implement bit stuffing and byte stuffing. 5. Write a program to implement error detection techniques (parity check and checksum). 6. Write a program to implement CRC. 7. Write a simple program to find the classes of an IP address. 8. Implementation of ARP and RARP. 9. Demonstration of OSPF routing protocol. 10. Write a socket program to implement chat application using UDP. 11. Write a socket program to implement Go-Back-N Protocol using TCP. 12. Implementation of DNS Protocol using UDP/TCP socket program Total: 30 REFERENCES / MANUALS / SOFTWARES: 1. Linux / GCC Compiler 2. NS2 Simulator COURSE OUTCOMES: On completion of the course, the students will be able to BT Mapped (Highest Level) CO1: make use of the performance parameters to measure the network performance and implement the services offered by data link layer. Applying (K3) CO2: identify the classes of IP address and demonstrate the various routing protocols. Applying (K3) CO3: develop various UDP/TCP client-server applications using socket programming. Applying (K3) Mapping of COs with POs and PSOs COs/POs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 CO1 3 2 2 1 1 3 2 CO2 3 2 2 1 1 3 2 CO3 3 2 2 1 1 3 2 1 – Slight, 2 – Moderate, 3 – Substantial, BT – Bloom’s Taxonomy
  • 3. 18CSL51 – Network Laboratory Experiment beyond the syllabus 1. Simulation of Nodes with UDP agents using NS2 Simulator. 2. Simulation of BGP routing protocol. 3. TCP Client Side Socket Operations. 4. TCP Server Side Socket Operations. 5. Write a Client to download a file from a HTTP Server.
  • 4. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To simulate the nodes with UDP agents using NS2 simulator. • To understand the various components in NS2 simulator such as NAM, NAM TRACE. • OS : Linux • Simulation Tool : Network Simulator 2 (ns2) • Text Editor : vi or gedit Step 1: Create a simulator object Step 2: Open the nam trace file Step 3: Define a 'finish' procedure Step 4: Create two nodes n0 and n1. Step 5: Create a duplex link between the nodes Step 6: Create a UDP agent and attach it to node n0 Step 7: Create a CBR traffic source and attach it to udp0 Step 8: Create a Null agent (a traffic sink) and attach it to node n1 Step 9: Connect the traffic source with the traffic sink Step 10: Schedule events for the CBR agent Step 11: Call the finish procedure after 5 seconds of simulation time Step 12: Run the simulation . Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number :01 Name of the Experiment : Simulation of Nodes With UDP Agents Using NS2
  • 5. 18CSL51 – Network Laboratory Computations to be Made: First of all, you need to create a simulator object. This is done with the command Now open a file for writing that is going to be used for the nam trace data. The first line opens the file 'out.nam' for writing and gives it the file handle 'nf'. In the second line tell the simulator object that created above to write all simulation data that is going to be relevant for nam into this file. The next step is to add a 'finish' procedure that closes the trace file and starts nam. The next line tells the simulator object to execute the 'finish' procedure after 5.0 seconds of simulation time. You probably understand what this line does just by looking at it. ns provides you with a very simple way to schedule events with the 'at' command. The last line finally starts the simulation. Next to define a very simple topology with two nodes that are connected by a link. The following two lines define the two nodes. (Note: You have to insert the code in this section before the line '$ns run', or even better, before the line '$ns at 5.0 "finish"'). set n0 [$ns node] set n1 [$ns node] $ns run $ns at 5.0 "finish" proc finish {} { global ns nf $ns flush-trace close $nf exec nam out.nam & exit 0 } set nf [open out.nam w] $ns namtrace-all $nf set ns [new Simulator]
  • 6. 18CSL51 – Network Laboratory A new node object is created with the command '$ns node'. The above code creates two nodes and assigns them to the handles 'n0' and 'n1'. The next line connects the two nodes. This line tells the simulator object to connect the nodes n0 and n1 with a duplex link with the bandwidth 1Megabit, a delay of 10ms and a DropTail queue. The next step is to send some data from node n0 to node n1. In ns, data is always being sent from one 'agent' to another. So the next step is to create an agent object that sends data from node n0, and another agent object that receives the data on node n1. These lines create a UDP agent and attach it to the node n0, then attach a CBR traffic generatot to the UDP agent. CBR stands for 'constant bit rate'. Line 7 and 8 should be self-explaining. The packetSize is being set to 500 bytes and a packet will be sent every 0.005 seconds (i.e. 200 packets per second). The next lines create a Null agent which acts as traffic sink and attach it to node n1. Now the two agents have to be connected with each other. And now you have to tell the CBR agent when to send data and when to stop sending. Note: It's probably best to put the following lines just before the line '$ns at 5.0 "finish"'. Now you can save the file and start the simulation again. When you click on the 'play' button in the nam window, you will see that after 0.5 simulation seconds, node 0 starts sending data packets to node 1. You might want to slow nam down then with the 'Step' slider. $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" $ns connect $udp0 $null0 set null0 [new Agent/Null] $ns attach-agent $n1 $null0 #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 # Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 $ns duplex-link $n0 $n1 1Mb 10ms DropTail
  • 7. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • List out the components in NS 2 Simulator. • List out the versions of NS. • Who Developed NS1? • What is LBNL? • Expand the terms ◦ TCL ◦ OTCL ◦ NAM ◦ NS • Which language is used to develop NS2 ◦ C ◦ C++ ◦ JAVA ◦ PYTHON • Which Language is used to develop NS3 ◦ C++ ◦ C++ and C# ◦ C++ and JAVA ◦ C++ and PYTHON • Write the simulation work - flow • How to run ns2 scripts in terminal? • List out the Agents in NS2. • List out the Traffic Sources in NS2. Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To simulate nodes with UDP agents by using NS2 simulator. ◦ To apply this knowledge in their project work to measure the packet delivery ratio, delay, jitter, throughput, etc.
  • 8. 18CSL51 – Network Laboratory Program: #Create a simulator object set ns [new Simulator] #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file exec nam out.nam & exit 0 } #Create two nodes set n0 [$ns node] set n1 [$ns node] #Create a duplex link between the nodes $ns duplex-link $n0 $n1 1Mb 10ms DropTail #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 # Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 #Create a Null agent (a traffic sink) and attach it to node n1 set null0 [new Agent/Null] $ns attach-agent $n1 $null0 #Connect the traffic source with the traffic sink $ns connect $udp0 $null0 #Schedule events for the CBR agent $ns at 0.5 "$cbr0 start" $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run
  • 9. 18CSL51 – Network Laboratory Sample Output:
  • 10. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To simulate the star topology by using NS2 simulator. • To understand the queuing and packet dropping concept in router or switch. • OS : Linux • Simulation Tool : Network Simulator 2 (ns2) • Text Editor : vi or gedit Step 1: Create a simulator object Step 2: Define different colors for data flows Step 3: Open the nam trace file Step 4: Define a 'finish' procedure Step 5: Create four nodes Step 6: Create links between the nodes Step 7: Monitor the queue for the link between node 2 and node 3 Step 8: Create a UDP agent and attach it to node n0 Step 9: Create a CBR traffic source and attach it to udp0 Step 10: Create a UDP agent and attach it to node n1 Step 11: Create a CBR traffic source and attach it to udp1 Step 12: Create a Null agent (a traffic sink) and attach it to node n3 Step 13: Connect the traffic sources with the traffic sink Step 14: Schedule events for the CBR agents Step 15: Call the finish procedure after 5 seconds of simulation time Step 16: Run the simulation Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number :02 Name of the Experiment : Simulation of Network Topologies Using NS2
  • 11. 18CSL51 – Network Laboratory Computations to be Made: As always, the first step is to define the topology. You should create a file 'star.tcl'. You will always have to create a simulator object, you will always have to start the simulation with the same command, and if you want to run nam automatically, you will always have to open a trace file, initialize it, and define a procedure which closes it and starts nam. Now insert the following lines into the code to create four nodes. The following piece of Tcl code creates three duplex links between the nodes. You can save and start the script now. You might notice that the topology looks a bit awkward in nam. You can hit the 're-layout' button to make it look better, but it would be nice to have some more control over the layout. Add the next three lines to your Tcl script and start it again. You will probably understand what this code does when you look at the topology in the nam window now. It should look like the picture below. Note that the autolayout related parts of nam are gone, since now you have taken the layout into your own hands. The options for the orientation of a link are right, left, up, down and combinations of these orientations. You can experiment with these settings later, but for now please leave the topology the way it is. $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right $ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n3 $n2 1Mb 10ms DropTail set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node]
  • 12. 18CSL51 – Network Laboratory Now create two UDP agents with CBR traffic sources and attach them to the nodes n0 and n1. Then create a Null agent and attach it to node n3. The two CBR agents have to be connected to the Null agent. We want the first CBR agent to start sending at 0.5 seconds and to stop at 4.5 seconds while the second CBR agent starts at 1.0 seconds and stops at 4.0 seconds. When you start the script now with 'ns star.tcl', you will notice that there is more traffic on the links from n0 to n2 and n1 to n2 than the link from n2 to n3 can carry. A simple calculation confirms this: We are sending 200 packets per second on each of the first two links and the packet size is 500 bytes. This results in a bandwidth of 0.8 megabits per second for the links from n0 to n2 and from n1 to n2. That's a total bandwidth of 1.6Mb/s, but the link between n2 and n3 only has a capacity of 1Mb/s, so obviously some packets are being discarded. But which ones? Both flows are black, so the only way to find out what is happening to the packets is to monitor them in nam by clicking on them. In the next two sections I'm going to show you how to distinguish between different flows and how to see what is actually going on in the queue at the link from n2 to n3. $ns at 0.5 "$cbr0 start" $ns at 1.0 "$cbr1 start" $ns at 4.0 "$cbr1 stop" $ns at 4.5 "$cbr0 stop" $ns connect $udp0 $null0 $ns connect $udp1 $null0 #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $ns attach-agent $n0 $udp0 # Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 #Create a UDP agent and attach it to node n1 set udp1 [new Agent/UDP] $ns attach-agent $n1 $udp1 # Create a CBR traffic source and attach it to udp1 set cbr1 [new Application/Traffic/CBR] $cbr1 set packetSize_ 500 $cbr1 set interval_ 0.005 $cbr1 attach-agent $udp1 set null0 [new Agent/Null] $ns attach-agent $n3 $null0
  • 13. 18CSL51 – Network Laboratory Add the following two lines to your CBR agent definitions. The parameter 'fid_' stands for 'flow id'. Now add the following piece of code to your Tcl script, preferably at the beginning after the simulator object has been created, since this is a part of the simulator setup. This code allows you to set different colors for each flow id. Now you can start the script again and one flow should be blue, while the other one is red. Watch the link from node n2 to n3 for a while, and you will notice that after some time the distribution between blue and red packets isn't too fair anymore (at least that's the way it is on my system). In the next section I'll show you how you can look inside this link's queue to find out what is going on there. You only have to add the following line to your code to monitor the queue for the link from n2 to n3. $ns duplex-link-op $n2 $n3 queuePos 0.5 $ns color 1 Blue $ns color 2 Red $udp0 set class_ 1 $udp1 set class_ 2
  • 14. 18CSL51 – Network Laboratory Start ns again and you will see a picture similar to the one below after a few moments. You can see the packets in the queue now, and after a while you can even see how the packets are being dropped, though (at least on my system, I guess it might be different in later or earlier releases) only blue packets are being dropped. But you can't really expect too much 'fairness' from a simple DropTail queue. So let's try to improve the queueing by using a SFQ (stochastic fair queueing) queue for the link from n2 to n3. Change the link definition for the link between n2 and n3 to the following line. The queueing should be 'fair' now. The same amount of blue and red packets should be dropped. $ns duplex-link $n3 $n2 1Mb 10ms SFQ
  • 15. 18CSL51 – Network Laboratory Formation of Bus Topology #Creating five nodes set node1 [$ns node] set node2 [$ns node] set node3 [$ns node] set node4 [$ns node] set node5 [$ns node] #Creating Lan connection between the nodes set lan0 [$ns newLan “$node1 $node2$node3 $node4 $node5” 0.7Mb 20ms LL Queue/FQ MAC/Csma/C d Channel] #Creating a TCP agent and attaching it to node 1 set tcp0 [new Agent/TCP] $tcp0 set class_ 1 $ns attach-agent $node1 $tcp0 #Creating a TCP Sink agent for TCP and attaching it to node 3 set sink0 [new Agent/TCPSink] $ns attach-agent $node3 $sink0 #Connecting the traffic sources with the traffic sink $ns connect $tcp0 $sink0 # Creating a CBR traffic source and attach it to tcp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $ cbr0 set interval_ 0.05 $cbr0 attach-agent $tcp0 #Schedule events for the CBR agents $ns at 0.5 “$cbr0 start time” $ ns at 5.5 “$cbr0 stop time” #Here we call the finish procedure after 10 seconds of simulation time $ns at 10.0 “End” #Finally run the simulation $ns run
  • 16. 18CSL51 – Network Laboratory Formation of Ring Topology #Creating six nodes set node1 [$ns node] set node2 [$ns node] set node3 [$ns node] set node4 [$ns node] set node5 [$ns node] set node6 [$ns node] #Creating links between the nodes $ns duplex-link $node1 $node2 1Mb 15ms FQ $ns duplex-link $node2 $node3 1Mb 15ms FQ $ns duplex-link $node3 $node4 1Mb 15ms FQ $ns duplex-link $node4 $node5 1Mb 15ms FQ $ns duplex-link $node5 $node6 1Mb 15ms FQ $ns duplex-link $node6 $node1 1Mb 15ms FQ”Forms Ring Topology” #Creating a TCP agent and attaching it to node 1 set tcp0 [new Agent/TCP] $tcp0 set class_ 1 $ns attach-agent $node1 $tcp0 #Creating a TCP Sink agent for TCP and attaching it to node 3 set sink0 [new Agent/TCPSink] $ns attach-agent $node3 $sink0 #Connecting the traffic sources with the traffic sink $ns connect $tcp0 $sink0 # Creating a CBR traffic source and attach it to tcp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.05 $cbr0 attach-agent $tcp0 #Schedule events for the CBR agents $ns at 0.5 “$cbr0 start time” $ns at 5.5 “$cbr0 stop time” #Here we call the finish procedure after 10 seconds of simulation time $ns at 10.0 “End” #Finally run the simulation $ns run
  • 17. 18CSL51 – Network Laboratory Formation of Mesh Topology #Creating four nodes set node1 [$ns node] set node2 [$ns node] set node3 [$ns node] set node4 [$ns node] #Creating links between the nodes $ns duplex-link $node1 $node2 1Mb 20ms FQ $ns duplex-link $node1 $node3 1Mb 20ms FQ $ns duplex-link $node1 $node4 1Mb 20ms FQ $ns duplex-link $node2 $node3 1Mb 20ms FQ $ns duplex-link $node2 $node4 1Mb 20ms FQ $ns duplex-link $node3 $node4 1Mb 20ms FQ“Forms Mesh Topology” #Creating a TCP agent and attaching it to node 1 set tcp0 [new Agent/TCP] $tcp0 set class_ 1 $ns attach-agent $node1 $tcp0 #Creating a TCP Sink agent for TCP and attaching it to node 3 set sink0 [new Agent/TCPSink] $ns attach-agent $node3 $sink0 #Connecting the traffic sources with the traffic sink $ns connect $tcp0 $sink0 # Creating a CBR traffic source and attach it to tcp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.05 $cbr0 attach-agent $tcp0 #Schedule events for the CBR agents $ns at 0.5 “$cbr0 start time” $ns at 5.5 “$cbr0 stop time” #Here we call the finish procedure after 10 seconds of simulation time $ns at 10.0 “End” #Finally run the simulation $ns run
  • 18. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • Clarify the terminologies ◦ simplex link ◦ half duplex link ◦ full duplex link • What is CBR? • What is SFQ? • Define DropTail. • List out the network typologies. • Which topology is most suitable topology ◦ Bus ◦ Ring ◦ Mesh ◦ Star ◦ Tree • Which network component is used in star topology ◦ Hub ◦ Switch ◦ Router ◦ Repeater ◦ Gateway ◦ First Two • When the packets will be loss or dropped by the node? Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To simulate the star topology by using NS2 simulator. ◦ To apply this star topology concept in their project work to measure the packet loss. ◦ To develop new protocol to make an efficient network topology.
  • 19. 18CSL51 – Network Laboratory Program: #Create a simulator object set ns [new Simulator] #Define different colors for data flows $ns color 1 Blue $ns color 2 Red #Open the nam trace file set nf [open out.nam w] $ns namtrace-all $nf #Define a 'finish' procedure proc finish {} { global ns nf $ns flush-trace #Close the trace file close $nf #Execute nam on the trace file exec nam out.nam & exit 0 } #Create four nodes set n0 [$ns node] set n1 [$ns node] set n2 [$ns node] set n3 [$ns node] #Create links between the nodes $ns duplex-link $n0 $n2 1Mb 10ms DropTail $ns duplex-link $n1 $n2 1Mb 10ms DropTail $ns duplex-link $n3 $n2 1Mb 10ms SFQ $ns duplex-link-op $n0 $n2 orient right-down $ns duplex-link-op $n1 $n2 orient right-up $ns duplex-link-op $n2 $n3 orient right #Monitor the queue for the link between node 2 and node 3 $ns duplex-link-op $n2 $n3 queuePos 0.5 #Create a UDP agent and attach it to node n0 set udp0 [new Agent/UDP] $udp0 set class_ 1 $ns attach-agent $n0 $udp0
  • 20. 18CSL51 – Network Laboratory # Create a CBR traffic source and attach it to udp0 set cbr0 [new Application/Traffic/CBR] $cbr0 set packetSize_ 500 $cbr0 set interval_ 0.005 $cbr0 attach-agent $udp0 #Create a UDP agent and attach it to node n1 set udp1 [new Agent/UDP] $udp1 set class_ 2 $ns attach-agent $n1 $udp1 # Create a CBR traffic source and attach it to udp1 set cbr1 [new Application/Traffic/CBR] $cbr1 set packetSize_ 500 $cbr1 set interval_ 0.005 $cbr1 attach-agent $udp1 #Create a Null agent (a traffic sink) and attach it to node n3 set null0 [new Agent/Null] $ns attach-agent $n3 $null0 #Connect the traffic sources with the traffic sink $ns connect $udp0 $null0 $ns connect $udp1 $null0 #Schedule events for the CBR agents $ns at 0.5 "$cbr0 start" $ns at 1.0 "$cbr1 start" $ns at 4.0 "$cbr1 stop" $ns at 4.5 "$cbr0 stop" #Call the finish procedure after 5 seconds of simulation time $ns at 5.0 "finish" #Run the simulation $ns run
  • 21. 18CSL51 – Network Laboratory Sample Output:
  • 22. 18CSL51 – Network Laboratory
  • 23. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: Computations to be Made: On completion of the experiment the students will be able to • To understand the various performance measurement parameters PDR, Throughput and Jitter. • To calculate various network performance measurement parameters such as PDR, Throughput and Jitter. • OS : Linux • Simulation Tool : Network Simulator 2 (ns2) • Text Editor : vi or gedit • Package : AWK Step 1: Create any one type of network topology Step 2: Run the Simulation and Record the Trace file Step 3: Write AWK Script to measure the network performance such as PDR, Throughput and Jitter. Step 4: Run the AWK Script. Step 5: Display the results to the user. TRACE FILES AND DESCRIPTION  The file written by an application (or by the Coverage Server) to store coverage information or overall network information and In NS2 , it is called as Trace File.  In order to generate a trace file. we have to create a trace file in Otcl script. SYNTAX FOR CREATING A TRACE FILE # Open the trace file set nf [open out.tr w] $ns trace-all $nf  which means we are opening a newtrace file named as "out" and also telling that data must be stored in .tr [trace] format.  "nf" is the file handler that we are used here to handle the trace file.  "w" means write i.e the file out.tr is opened for writing. Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number : 03 Name of the Experiment : AWK script to Measure the Network Performance
  • 24. 18CSL51 – Network Laboratory  >> "r" means reading and "a" means appending  The second line tells the simulator to trace each packet on every link in the topology and for that we give file handler nf for the simulator ns. # Define finish procedure proc finish {} { global ns nf $ns flush-trace close nf exit 0 }  In here the trace data is flushed into the file by using command $ns flush-trace and then file is closed.  While running the ns2 program via terminal, trace file is generated in the selected directory (folder or directory where the program stored).  Sample Trace File  Trace File Format
  • 25. 18CSL51 – Network Laboratory In here, there are 12 fields and we can explain it as; 1. EVENT OR TYPE IDENTIFIER + :a packet enque event - :a packet deque event r :a packet reception event d :a packet drop (e.g., sent to dropHead_) event c :a packet collision at the MAC level 2. TIME : at which the packet tracing string is created. 3-4. SOURCE AND DESTINATION NODE : source and destination ID's of tracing objects. 5. PACKET NAME : Name of the packet type. 6. PACKET SIZE : Size of packet in bytes. 7. FLAGS : 7 digit flag string. “-”: disable 1st = “E”: ECN (Explicit Congestion Notification) echo is enabled. 2nd = “P”: the priority in the IP header is enabled. 3rd : Not in use 4th = “A”: Congestion action 5th = “E”: Congestion has occurred. 6th = “F”: The TCP fast start is used. 7th = “N”: Explicit Congestion Notification (ECN) is on. 8. FLOW ID 9-10. SOURCE AND DESTINATION ADDRESS : The format of these two fields is “a.b”, where “a" is the address and "b" is the port. 11. SEQUENCE NUMBER 12. PACKET UNIQUE ID  Each trace line starts with an event (+, -, d, r) descriptor followed by the simulation time (in seconds) of that event, and from and to node, which identify the link on which the event occurred.  The next information in the line before flags (appeared as "------" since no flag is set) is packet type and size (in Bytes).  Currently, NS implements only the Explicit Congestion Notification (ECN) bit, and the remaining bits are not used.  The next field is flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script.
  • 26. 18CSL51 – Network Laboratory  Even though fid field may not used in a simulation, users can use this field for analysis purposes.  The fid field is also used when specifying stream color for the NAM display.  The next two fields are source and destination address in forms of "node.port".  The next field shows the network layer protocol's packet sequence number.  Note that even though UDP implementations do not use sequence number, NS keeps track of UDP packet sequence number for analysis purposes.  The last field shows the unique id of the packet. AWK Script:  AWK was created at Bell Labs in the 1970s, and its name is derived from the surnames of its authors: Alfred Aho, Peter Weinberger, and Brian Kernighan.  The acronym is pronounced the same as the bird auk, which is on the cover of The AWK Programming Language.  When written in all lowercase letters, as awk, it refers to the Unix or Plan 9 program that runs scripts written in the AWK programming language.  Functional Blocks of AWK Script. Packet Delivery Ratio (PDR): • Packet delivery ratio is the ratio of packets that are successfully delivered to a destination compared to the number of packets that have been sent by sender. • In order to calculate packet delivery ratio we need total number of packets sent and number of received packets.
  • 27. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • Expand AWK. • What are the functional blocks of AWK script? • Define PDR. • List the types of events in Trace File. • +,- strands for in trace File. • Define throughput. • Define jitter. • What is the difference between bandwidth and throughput? • Suppose a source node is sending 200 packets to the destination node. In destination node only 100 packets are received. What is the Packet Delivery Ration Value? • A network with bandwidth of 10 Mbps can pass only an average of 12, 000 frames per minute where each frame carries an average of 10, 000 bits. What will be the throughput for this network? Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To compute the performance measures using formulas. ◦ To solve problems that is related to computer network. ◦ To apply this computation knowledge in their project work.
  • 28. 18CSL51 – Network Laboratory Program: # AWK Script for Packet Delivery Calculation for Trace Format BEGIN { sent=0; received=0; } { if($1=="s" && $9=="CBR") { sent++; } else if($1=="r" && $9=="TCP") { received++; } } END { printf " Packet Sent:%d",sent; printf "n Packet Received:%d",received; printf "n Packet Delivery Ratio:%.2fn",(sent/received)*100; } Sample Output:
  • 29. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: Computations to be Made: On completion of the experiment the students will be able to • To understand the various performance measurement parameters such as delay, end – to – end delay, bandwidth, throughput and jitter. • To calculate various delays such as propagation delay, transmission delay, processing delay, queuing delay, nodal delay and end – to – end delay. • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Step 1: Read the inputs from the user such as distance between source and destination, message size, bandwidth, number of routers, queuing delay and processing delay. Step 2: Calculate propagation delay. Step 3: Calculate transmission delay. Step 4: Calculate nodal delay. Step 5: Calculate end – to – end delay. Step 6: Display the results to the user. Delay: Network delay is an important design and performance characteristic of a computer network or telecommunications network. The delay of a network specifies how long it takes for a bit of data to travel across the network from one node or endpoint to another. It is typically measured in multiples or fractions of seconds. Delay may differ slightly, depending on the location of the specific pair of communicating nodes. Although users only care about the total delay of a network, engineers need to perform precise measurements. Thus, engineers usually report both the maximum and average delay, and they divide the delay into several parts: • Processing delay - time routers take to process the packet header • Queuing delay - time the packet spends in routing queues • Transmission delay - time it takes to push the packet's bits onto the link • Propagation delay - time for a signal to reach its destination Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number : 04 Name of the Experiment : Network Performance Measurement
  • 30. 18CSL51 – Network Laboratory dnodal = dtrans+ dprop+ dproc + dqueu There is a certain minimum level of delay that will be experienced due to the time it takes to transmit a packet serially through a link. Onto this is added a more variable level of delay due to network congestion. IP network delays can range from just a few milliseconds to several hundred milliseconds. Propagation delay : Propagation time measures the time required for a bit to travel from the source to the destination. The propagation delay is calculated by dividing the distance by the propagation speed. Propagation delay = Distance / Propagation speed Transmission delay: In data communications we don't send just 1 bit, we send a message. The first bit may take a delay equal to the propagation delay to reach its destination; the last bit also may take the same amount of time. However, there is a delay between the first bit leaving the sender and the last bit arriving at the receiver. The first bit leaves earlier and arrives earlier; the last bit leaves later and arrives later. The time required for transmission of a message depends on the size of the message and the bandwidth of the channel. Transmission delay = Message size / Bandwidth End-to-End Delay: End-to-End delay refers to the time taken for a packet to be transmitted across a network from source to destination. where dend-end= N[ dtrans+ dprop+ dproc] dend-end= end-to-end delay dtrans= transmission delay dprop= propagation delay dproc= processing delay N= number of links (Number of routers + 1) Note: we have neglected queuing delays. Each router will have its own dtrans, dprop, dproc hence this formula gives a rough estimate.
  • 31. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • Name the performance parameters for measuring network performance. • Define nodal delay or latency. • Define end – to – end delay. • List the delays needed to calculate nodal delay and end – to – end delay. • Define throughput. • Define bandwidth. • Define jitter. • How many bits can fit on a link with a 3 ms delay if the bandwidth of the link is ◦ 1 Mbps? ◦ 10 Mbps? ◦ 100 Mbps? ◦ 1000 Mbps? • A file contains 3 million bytes. How long does it take to download this file using a ◦ 100 Kbps channel? ◦ 10 Mbps channel? • Assume you have an image of size 2MB that is being sent on a link with 15 routers each having a queuing delay of 0.15 sec and processing delay of 0.20 sec. The length of the link is 12000 Km. The speed of the light inside the link is 2 X 10 8 m/s. The link has a bandwidth of 1 Gbps. ◦ What is the total delay? ◦ What is the end – to – end delay? ◦ Which component of the total delay is dominant? ◦ Which one is negligible? Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To compute the performance measures using formulas. ◦ To solve problems that are related to computer network. ◦ To apply this computation knowledge in their project work. ◦ To make an effective network topology.
  • 32. 18CSL51 – Network Laboratory Program: #include<stdio.h> #define PSPEED 2*100000000 void main() { double n,dist,band,msize,queudelay,procdelay; float progdelay,trandelay,delay,end2enddelay; printf("Enter the distance between source and destination (in Km):"); scanf("%lf",&dist); printf("Enter the bandwidth (in Gbps):"); scanf("%lf",&band); printf("Enter the Message Size (in MB):"); scanf("%lf",&msize); printf("Enter the Number of Routers bewteen Source and Destination (in Nos):"); scanf("%lf",&n); printf("Enter the Queuing Delay in Routers (in sec):"); scanf("%lf",&queudelay); printf("Enter the Prosessing Delay in Routers (in sec):"); scanf("%lf",&procdelay); progdelay = (dist*1000)/(PSPEED); trandelay = (msize*1000000*8)/(band*1000000000); delay = progdelay+trandelay+queudelay+procdelay; end2enddelay = n*(progdelay+trandelay+procdelay); printf("nn********MEASURING NETWORK PERFORMANCE*************nn"); printf("Propagation Delay (in sec):%fn",progdelay); printf("Transmission Delay (in sec):%fn",trandelay); printf("Delay (in sec):%fn",delay); printf("End to End Delay (in sec):%fn",end2enddelay); }
  • 33. 18CSL51 – Network Laboratory Sample Output:
  • 34. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: Computations to be Made: On completion of the experiment the students will be able to • To know framing of bits in data link layer. • To implement bit stuffing concept in data link layer protocols such as SDLC (HDLC), PPP. • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Step 1: Read the input data from the user by using array. Step 2: In sender side, check if five consecutive 1's present in data then add (stuff) a zero (0). Step 3: Display the stuffed data. Step 4: In receiver side, check if a zero (0) occurs after five consecutive 1's in data then remove (destuff) zero (0) in the data. Step 5: Display the destuffed data. In data transmission and telecommunication, bit stuffing (also known—uncommonly—as positive justification) is the insertion of non information bits into data. Stuffed bits should not be confused with overhead bits. Bit stuffing is used for various purposes, such as for bringing bit streams that do not necessarily have the same or rationally related bit rates up to a common rate, or to fill buffers or frames. The location of the stuffing bits is communicated to the receiving end of the data link, where these extra bits are removed to return the bit streams to their original bit rates or form. Bit stuffing may be used to synchronize several channels before multiplexing or to rate-match two single channels to each other. Another use of bit stuffing is for run length limited coding: to limit the number of consecutive bits of the same value in the data to be transmitted. A bit of the opposite value is inserted after the maximum allowed number of consecutive bits. Since this is a general rule the receiver doesn't need extra information about the location of the stuffing bits in order to do the destuffing. This is done to create additional signal transitions to ensure reliable reception or to escape special reserved code words such as frame sync sequences when the data happens to contain them. Applications include Controller Area Network, HDLC, and Universal Serial Bus. Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number :05 Name of the Experiment : Implementation of Bit Stuffing
  • 35. 18CSL51 – Network Laboratory Zero-bit insertion is a particular type of bit stuffing used in some data transmission protocols to aid clock recovery from the data stream. It was popularized by IBM's SDLC (later renamed HDLC). The name relates to the insertion of only 0 bits. No 1 bits are inserted to limit sequences of 0 bits. SDLC and Low- and full-speed USB data are sent NRZI encoded: a 0 bit causes a signal transition, whereas a 1 bit causes no change. After a long sequence of 1 bits there could be no transitions in the transmitted data, and it would be possible for the transmitter and receiver clocks to lose synchronisation. By inserting a 0 after five (SDLC) or six (USB) sequential 1s the transmitter guarantees a maximum time between transitions. The receiver can synchronise its clock against the transitions to ensure proper data recovery. In SDLC the transmitted bit sequence "01111110" containing six adjacent 1 bits is the Flag byte. Bit stuffing ensures that this pattern can never occur in normal data, so it can be used as a marker for the beginning and end of frame without any possibility of being confused with normal data. The main disadvantage of this form of bit-stuffing is that the code rate is unpredictable; it depends on the data being transmitted. Questions and problems for assessing the achievement of objective: • What is framing? • Give example for fixed size framing and variable size framing. • List some bit – oriented and character – oriented protocols. • Why bit – oriented protocols are more useful and efficient than character – oriented protocols? • What is bit stuffing? • What is HDLC? • What is PPP? • Write the flag byte value for PPP/HDLC. • Stuff the following data ◦ 01111110 ◦ 1111111111111111111111111 ◦ 11111101111101111101111110 ◦ 01111110111111101111011111111101111101111110 ◦ 01111110000001000001111011110000010101111110 Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To stuff at the bit level too ◦ To interpret bits(physical layer) as a sequence of frames(link layer). ◦ To link host and nodes with PPP.
  • 36. 18CSL51 – Network Laboratory Program: #include<stdio.h> #include<stdlib.h> #define BLACK "033[22;30m" #define RED "033[01;31m" #define G "033[01;32m" main() { char str[100],dest[100],str1[100]; int l,i,j,k,c,m,bit[100]; printf("nEnter the message :"); scanf("%s",str); printf("nn ***************** BIT STUFFING ********************nn"); for(j=0,k=0,c=0,i=0;str[i]!='0';i++) { if(str[i]=='1') { c++; if(c==5) { } else dest[j++]=str[i]; dest[j++]='0'; c=0; } else { } } dest[j++]=str[i]; c=0; dest[j++]=str[i]; dest[j]='0'; printf("nThe Bit Stuffed Message is:nn"); printf(RED " | 01111110 | " ); for(i=0,c=0;dest[i]!='0';i++) { if(dest[i]=='1') { c++;
  • 37. 18CSL51 – Network Laboratory printf(BLACK "%c",dest[i]); if(c==5) { } else { } c=0; printf(G "%c",dest[++i]); c=0; printf(BLACK "%c",dest[i]); } } printf(RED " | 01111110 | "BLACK ); printf("nn ***************** BIT DESTUFFING ********************nn"); for(i=0,k=0,c=0;dest[i]!='0';i++) { if(dest[i]=='1') { c++; if(c==5) { str1[k++]=dest[i++]; str1[k++]=dest[++i]; if(dest[i]=='1') c=1; } else else c=0; } else { } } str1[k++]=dest[i]; str1[k++]=dest[i]; c=0; str1[k]='0'; printf("nThe Bit Destuffed Message is:nn"); printf(RED " | 01111110 | " BLACK "%s" RED " | 01111110 |nn" BLACK, str1); }
  • 38. 18CSL51 – Network Laboratory Sample Output:
  • 39. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: Computations to be Made: On completion of the experiment the students will be able to • To know framing of characters (bytes) in data link layer. • To implement byte stuffing concept in data link layer protocols such as SDLC(HDLC), PPP. • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Step 1: Read the flag byte (character) from the user. For example 'G'. Step 2: Read the length of the data. Step 3: Read the data using array. Step 4: In sender side, check the data contains the flag byte (G) then add (stuff) a escape sequence character 'E' in the data. Step 5: Also verify, if the escape sequence character 'E' present in the data then add (stuff) one more escape sequence character 'E' in the data. Step 6: Display the byte stuffed data. Step 7: In receiver side, check if the escape sequence character 'E' present in the data followed by flag byte 'G' and escape sequence character present in data then remove (destuff) that escape sequence character 'E'. Step 8: Display the destuffed data. In a character-oriented protocol, data to be carried are 8-bit characters from a coding system such as ASCII . The header, which normally carries the source and destination addresses and other control information, and the trailer, which carries error detection or error correction redundant bits, are also multiples of 8 bits. To separate one frame from the next, an 8-bit (1-byte) flag is added at the beginning and the end of a frame. The flag, composed of protocol-dependent special characters, signals the start or end of a frame. Character-oriented framing was popular when only text was exchanged by the data link layers. The flag could be selected to be any character not used for text communication. Now, however, we send other types of information such as graphs, audio, and video. Any pattern used for the flag could also be part of the information. If this happens, the receiver, when it encounters this pattern in the Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number :06 Name of the Experiment : Implementation of Byte Stuffing
  • 40. 18CSL51 – Network Laboratory middle of the data, thinks it has reached the end of the frame. To fix this problem, a byte-stuffing strategy was added to character-oriented framing. In byte stuffing (or character stuffing), a special byte is added to the data section of the frame when there is a character with the same pattern as the flag. The data section is stuffed with an extra byte. This byte is usually called the escape character (ESC), which has a predefined bit pattern. Whenever the receiver encounters the ESC character, it removes it from the data section and treats the next character as data, not a delimiting flag. Byte stuffing by the escape character allows the presence of the flag in the data section of the frame, but it creates another problem. What happens if the text contains one or more escape characters followed by a flag? The receiver removes the escape character, but keeps the flag, which is incorrectly interpreted as the end of the frame. To solve this problem, the escape characters that are part of the text must also be marked by another escape character. In other words, if the escape character is part of the text, an extra one is added to show that the second one is part of the text. Note: Character-oriented protocols present another problem in data communications. The universal coding systems in use today, such as Unicode, have 16-bit and 32-bit characters that conflict with 8-bit characters. We can say that in general, the tendency is moving toward the bit-oriented protocols
  • 41. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • Define byte stuffing. • Compare and contrast byte-oriented and bit-oriented protocols. Which category has been popular in the past (explain the reason)? Which category is popular now (explain the reason)? • Compare and contrast byte-stuffing and bit-stuffing. Which technique is used in byte-oriented protocols? Which technique is used in bit-oriented protocols? • Stuff the following data using byte stuffing: assume the flag byte as 'G' and escape byte as 'E' ◦ KONGU ◦ ENGINEERING ◦ COLLEGE ◦ KONGU ENGINEERING COLLEGE • Stuff the following data using byte stuffing: assume the flag bit as 'A' and escape byte as 'E' ◦ DESIGN AND ANALYSIS OF ALGORITHM ◦ COMPUTER SCIENCE ENGINEEER Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To stuff at the character (byte) level too ◦ To interpret bytes as a sequence of frames(link layer). ◦ To link host and nodes with HDLC.
  • 42. 18CSL51 – Network Laboratory Program: #include<stdio.h> #include<stdlib.h> #define BLACK "033[22;30m" #define RED "033[01;31m" #define GREEN "033[01;32m" main() { char str[100],dest[100],str1[100],f; int l,i,j,k; printf("nEnetr the name of the flag bit:"); scanf("%c",&f); printf("nEnter the length of the message:"); scanf("%d",&l); printf("nEnter the message :"); for(i=0;i<=l;i++) { str[i]=getchar(); } str[i]='0'; printf("nn********************* BYTE STUFFING ************************nn"); printf("nMessage after Byte Stuffing is:nn" GREEN "| %c | " BLACK,f); for(i=0,j=0;i<=l;i++) { if(str[i]=='E') dest[j++]='E'; if(str[i]==f) dest[j++]='E'; dest[j++]=str[i]; } dest[j]='0'; for(i=0;dest[i]!='0';i++) { if(dest[i]=='E') { } else printf(RED "%c" BLACK,dest[i]); if(dest[i+1]=='E') printf("%c",dest[++i]); printf("%c",dest[i]); } printf(GREEN " | %c | " BLACK,f);
  • 43. 18CSL51 – Network Laboratory printf("nn********************* BYTE DESTUFFING ***********************nn"); printf("nMessage after Byte Destuffing is:nn" GREEN "| %c | " BLACK,f); for(i=0,k=0;i<j;i++) { if(dest[i]=='E') { if(dest[i+1]=='E') str1[k++]=dest[++i]; } else else str1[k++]=dest[++i]; str1[k++]=dest[i]; } str1[k]='0'; printf("%s",str1); printf(GREEN " | %c |nn" BLACK,f); }
  • 44. 18CSL51 – Network Laboratory Sample Output:
  • 45. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To know how the parity check can be used to detect the errors at the receiver side. • To implement parity check in data link layer. • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Do the following steps in sender side: Step 1: Read the message to be send from the user using an array. Step 2: Count the number of 1's present in the message. Step 3: In even parity, if the number of 1's present in the message is even then add the parity bit value is 0 otherwise add 1 at the end of message. Step 4: In odd parity, if the number of 1's present in the message is odd then add the parity bit value is 0 otherwise add 1 at the end of message. Step 5: Send the message with parity bit. Do the following steps in receiver side: Step 6: Read the data from the sender side. Step 7: Count the number of 1's present in the message. Step 8: In even parity, if the number of 1's present in the message is even then the parity value is 0 otherwise it is 1 Step 9: In odd parity, if the number of 1's present in the message is odd then the parity value is 0 otherwise it is 1. Step 10: if the parity bit value is 0 in both cases ( even and odd parity) then the received message is “correct” otherwise the received message is “incorrect”. Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number 07 Name of the Experiment : Implementation of Parity Check
  • 46. 18CSL51 – Network Laboratory Computations to be Made: Parity Check: A parity bit, or check bit, is a bit added to the end of a string of binary code that indicates whether the number of bits in the string with the value one is even or odd. Parity bits are used as the simplest form of error detecting code. There are two variants of parity bits: even parity bit and odd parity bit. In case of even parity, the parity bit is set to 1, if the number of ones in a given set of bits (not including the parity bit) is odd, making the number of ones in the entire set of bits (including the parity bit) even. If the number of ones in a given set of bits is already even, it is set to a 0. When using odd parity, the parity bit is set to 1 if the number of ones in a given set of bits (not including the parity bit) is even, making the number of ones in the entire set of bits (including the parity bit) odd. When the number of set bits is odd, then the odd parity bit is set to 0. Even parity is a special case of a cyclic redundancy check (CRC), where the 1-bit CRC is generated by the polynomial x+1. If the parity bit is present but not used, it may be referred to as mark parity (when the parity bit is always 1) or space parity (the bit is always 0). In mathematics, parity refers to the evenness or oddness of an integer, which for a binary number is determined only by the least significant bit. In telecommunications and computing, parity refers to the evenness or oddness of the number of bits with value one within a given set of bits, and is thus determined by the value of all the bits. It can be calculated via an XOR sum of the bits, yielding 0 for even parity and 1 for odd parity. This property of being dependent upon all the bits and changing value if any one bit changes allows for its use in error detection schemes. If an odd number of bits (including the parity bit) are transmitted incorrectly, the parity bit will be incorrect, thus indicating that a parity error occurred in the transmission. The parity bit is only suitable for detecting errors; it cannot correct any errors, as there is no way to determine which particular bit is corrupted. The data must be discarded entirely, and re-transmitted from scratch. On a noisy transmission medium, successful transmission can therefore take a long time, or even never occur. However, parity has the advantage that it uses only a single bit and requires only a number of XOR gates to generate. See Hamming code for an example of an error-correcting code. Parity bit checking is used occasionally for transmitting ASCII characters, which have 7 bits, leaving the 8th bit as a parity bit.
  • 47. 18CSL51 – Network Laboratory For example, the parity bit can be computed as follows, assuming we are sending a simple 4-bit value 1001 with the parity bit following on the right, and with ^ denoting an XOR gate: This mechanism enables the detection of single bit errors, because if one bit gets flipped due to line noise, there will be an incorrect number of ones in the received data. In the two examples above, B's calculated parity value matches the parity bit in its received value, indicating there are no single bit errors. Consider the following example with a transmission error in the second bit:
  • 48. 18CSL51 – Network Laboratory There is a limitation to parity schemes. A parity bit is only guaranteed to detect an odd number of bit errors. If an even number of bits have errors, the parity bit records the correct number of ones, even though the data is corrupt. (See also error detection and correction.) Consider the same example as before with an even number of corrupted bits: Uses: B observes even parity, as expected, thereby failing to catch the two bit errors. Because of its simplicity, parity is used in many hardware applications where an operation can be repeated in case of difficulty, or where simply detecting the error is helpful. For example, the SCSI and PCI buses use parity to detect transmission errors, and many microprocessor instruction caches include parity protection. Because the I-cache data is just a copy of main memory, it can be disregarded and re-fetched if it is found to be corrupted. In serial data transmission, a common format is 7 data bit, an even parity bit, and one or two stop bits. This format neatly accommodates all the 7-bit ASCII characters in a convenient 8-bit byte. Other formats are possible; 8 bits of data plus a parity bit can convey all 8-bit byte values. In serial communication contexts, parity is usually generated and checked by interface hardware (e.g., a UART) and, on reception, the result made available to the CPU (and so to, for instance, the operating system) via a status bit in a hardware register in the interface hardware. Recovery from the error is usually done by retransmitting the data, the details of which are usually handled by software (e.g., the operating system I/O routines). Parity data is used by some RAID levels to achieve redundancy. If a drive in the array fails, remaining data on the other drives can be combined with the parity data (using the Boolean XOR function) to reconstruct the missing data.
  • 49. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • What is parity bit? • What are the two variants of parity bit? • What is mark parity and space parity? • What is the advantage of parity check? • What is the disadvantage of parity check? • How many bits can detect and correct by using checksum, parity check and CRC? • '^' this symbol denotes which of the following gate with respect to programming ◦ AND ◦ OR ◦ NOT ◦ Ex-OR • What is the length of the following representations (in terms of bits): ◦ BCD ◦ ASCII ◦ EBCDIC • List the uses of parity check. • Find out the even parity and odd parity of the following 7-bit data: ◦ 1101101 ◦ Z ◦ & ◦ ACK Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To detect errors at the receiver side using parity check. ◦ To apply this concept in RAID. ◦ To use many hardware applications such as SCSI, USB, etc.
  • 50. 18CSL51 – Network Laboratory Program: #include<stdio.h> #include<string.h> main() { char mes[100],parval,sent[100],recieve[100]; int par,i,count=0; printf("nEnter the message:"); scanf("%s",mes); printf("n***************** EVEN PARITY *******************n"); for(i=0;mes[i]!='0';i++) { if(mes[i]=='1') count++; sent[i]=mes[i]; } if(count%2==0) parval='0'; else parval='1'; sent[i]=parval; sent[++i]='0'; printf("n***************** SENDER SIDE *******************n"); printf("nEven pairty value is :%cn",parval); printf("nFinal Sending messgae is with parity %sn",sent); strcpy(recieve,sent); //recieve[3]='1'; // -> This is for checking errored frame printf("n***************** RECEIVER SIDE *******************n"); printf("nFinal Recieved messgae is %s",recieve); for(i=0,count=0;recieve[i]!='0';i++) { if(recieve[i]=='1') count++; } if(count%2==0) { } else { } parval='0'; printf("nEven pairty value is :%cnNo Error in framenn",parval); parval='1'; printf("nEven pairty value is :%cnError in framenn",parval);
  • 51. 18CSL51 – Network Laboratory printf("n***************** ODD PARITY *******************n"); for(i=0;mes[i]!='0';i++) { if(mes[i]=='1') count++; sent[i]=mes[i]; } if(count%2==0) parval='1'; else parval='0'; sent[i]=parval; sent[++i]='0'; printf("n***************** SENDER SIDE *******************n"); printf("nOdd pairty value is :%cn",parval); printf("nFinal Sending messgae is with parity %sn",sent); strcpy(recieve,sent); //recieve[3]='1'; //-> This is for checking errored frame printf("n***************** RECEIVER SIDE *******************n"); printf("nFinal Recieved messgae is %s",recieve); for(i=0,count=0;recieve[i]!='0';i++) { if(recieve[i]=='1') count++; } if(count%2==0) { } else { } } parval='1'; printf("nOdd pairty value is :%cnError in framenn",parval); parval='0'; printf("nOdd pairty value is :%cnNo Error in framenn",parval);
  • 52. 18CSL51 – Network Laboratory Sample Output:
  • 53. 18CSL51 – Network Laboratory
  • 54. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To know error detection methods available in data link layer for transfer the messages from source to destination. • To perform check-summing method in trailer part of the frame. • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Do the following steps in sender side: Step 1: Read the total length of the message to be send from the user. Step 2: Read the data from the user using array. Step 3: Calculate the sum of the messages. Step 4: Convert the decimal sum value into binary sum value. Step 5: If the total number of bits exceeds the limit of the 'n' bits the wrap up the the binary values into 'n' bits representation. Step 6: Find the decimal value (checksum) for the corresponding wrapped binary value. Step 7: Finally add it to the message list and send to the receiver end. Do the following steps in receiver side: Step 8: Read the data from the sender side Step 9: Calculate the sum of the messages. Step 10: Convert the decimal sum value into binary sum value. Step 11: If the total number of bits exceeds the limit of the 'n' bits the wrap up the the binary values into 'n' bits representation. Step 12: Find the decimal value for the corresponding wrapped binary value. Step 13: Check if the binary value(checksum) is all zeros then print “the received messages are correct” otherwise print “error is occurred in the received data” Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number 08 Name of the Experiment : Implementation of Checksum
  • 55. 18CSL51 – Network Laboratory Computations to be Made: Checksum A checksum or hash sum is a small-size datum computed from an arbitrary block of digital data for the purpose of detecting errors that may have been introduced during its transmission or storage. The integrity of the data can be checked at any later time by recomputing the checksum and comparing it with the stored one. If the checksums match, the data was likely not accidentally altered. The procedure that yields the checksum from the data is called a checksum function or checksum algorithm. A good checksum algorithm will yield a different result with high probability when the data is accidentally corrupted; if the checksums match, the data has the same high probability of being free of accidental errors. Checksum functions are related to hash functions, fingerprints, randomization functions, and cryptographic hash functions. However, each of those concepts has different applications and therefore different design goals. It is important to not use a checksum in a security related application, as a checksum does not have the properties required to protect data from intentional tampering. Example: Suppose our data is a list of five 4-bit numbers that we want to send to a destination. In addition to sending these numbers, we send the sum of the numbers. For example, if the set of numbers is (7, 11, 12, 0, 6), we send (7, 11, 12,0,6,36), where 36 is the sum of the original numbers. The receiver adds the five numbers and compares the result with the sum. If the two are the same, the receiver assumes no error, accepts the five numbers, and discards the sum. Otherwise, there is an error somewhere and the data are not accepted. We can make the job of the receiver easier if we send the negative (complement) of the sum, called the checksum. In this case, we send (7, 11, 12,0,6, -36). The receiver can add all the numbers received (including the checksum). If the result is 0, it assumes no error; otherwise, there is an error . One's Complement The previous example has one major drawback. All of our data can be written as a 4-bit word (they are less than 15) except for the checksum. One solution is to use one's complement arithmetic. In this arithmetic, we can represent unsigned numbers between 0 and 2n - 1 using only n bits. t If the number has more than n bits, the extra leftmost bits need to be added to the n rightmost bits (wrapping). In one's complement arithmetic, a negative number can be represented by inverting all bits (changing a 0 to a 1 and a 1 to a 0). This is the same as subtracting the number from 2n – 1. Let us redo our example using one's complement arithmetic. Figure shows the process at the sender and at the receiver. The sender initializes the checksum to 0 and adds all data items and the checksum (the checksum is considered as one data item and is shown in color). The result is 36. However, 36 cannot be expressed in 4 bits. The extra two bits are wrapped and added with the sum to create the wrapped sum value 6. In the figure, we have shown the details in binary. The sum is then complemented, resulting in the checksum value 9 (15 - 6 = 9). The sender now sends six data items to the receiver including the checksum 9. The receiver follows the same procedure as the sender. It adds all data items (including the checksum); the result is 45. The sum is wrapped and becomes 15. The wrapped sum is complemented and becomes O. Since the value of the checksum is 0, this means that the data is not corrupted. The receiver drops the checksum and keeps the other data items. If the checksum is not zero, the entire packet is dropped.
  • 56. 18CSL51 – Network Laboratory Internet Checksum Traditionally, the Internet has been using a 16-bit checksum. The sender calculates the checksum by following these steps. Sender site: 1. The message is divided into 16-bit words. 2. The value of the checksum word is set to 0. 3. All words including the checksum are added ushtg one's complement addition. 4. The sum is complemented and becomes the checksum. 5. The checksum is sent with the data. The receiver uses the following steps for error detection. Receiver site: 1. The message (including checksum) is divided into 16-bit words. 2. All words are added using one's complement addition. 3. The sum is complemented and becomes the new checksum. 4. If the value of checksum is 0, the message is accepted; otherwise, it is rejected. The nature of the checksum (treating words as numbers and adding and complementing them) is well-suited for software implementation. Short programs can be written to calculate the checksum at the receiver site or to check the validity of the message at the receiver site.
  • 57. 18CSL51 – Network Laboratory Example: Let us calculate the checksum for a text of 8 characters ("Forouzan"). The text needs to be divided into 2-byte (l6-bit) words. We use ASCII to change each byte to a 2-digit hexadecimal number. For example, F is represented as Ox46 and 0 is represented as Ox6F. Figure 10.25 shows how the checksum is calculated at the sender and receiver sites. In part a of the figure, the value of partial sum for the first column is Ox36. We keep the rightmost digit (6) and insert the leftmost dight (3) as the carry in the second column. The process is repeated for each column. Note that if there is any corruption, the checksum recalculated by the receiver is not all as. We leave this an exercise. Questions and problems for assessing the achievement of objective: • What is single-bit error? • What is burst error? • How does a single bit error is differ from burst error? • What kind of arithmetic is used to add data items in checkum calculation? • Define checksum. • What is Internet Checksum? • What kind of error is undetectable b the checksum? • Do the internet checksum operation at sender side of the following data ◦ ANDREW TANENBAUM ◦ DAVID WETHERALL • Do the internet checksum operation at sender side of the following data ◦ 7,11,12,0,6 ◦ 12,4,8,6,4,5,2,14 • How can we represent the number 21 in one's complement arithmetic using only four bits? Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To detect the error at receiver side. ◦ To apply this concept in their project work. ◦ To send error free data.
  • 58. 18CSL51 – Network Laboratory Program: #include<stdio.h> #include<math.h> #include<string.h> int main() { int a[10],n,sum=0,i,binary[100]={0}; int j,binary1[100],l,result[10],c=0,k; int sum1; printf("n************** SENDER SIDE ******************n"); printf("nEnter the total length of message:"); scanf("%d",&n); printf("nEnter the data one by one :"); for(i=0;i<n;i++) { scanf("%d",&a[i]); sum+=a[i]; } printf("nThe messages are:"); for(i=0;i<n;i++) printf("n%d",a[i]); printf("nThe sum is: %d",sum); for(i=0;sum>0;i++) { binary1[i]=sum%2; sum=sum/2; } for(;i<8;i++) binary1[i]=0; l=i; for(i=l-1,j=0;i>=0;i--,j++) binary[j]=binary1[i]; printf("nThe equivalent binary digit is :"); for(i=0;i<l;i++) printf("%d",binary[i]); for(c=0,i=l-1;i>=4;i--) { if(c==0) { if(binary[i]==1&&binary[i-4]==1) { result[i-4]=0; c=1; } else if(binary[i]==1&&binary[i-4]==0) { result[i-4]=1; c=0; } else if(binary[i]==0&&binary[i-4]==0) {
  • 59. 18CSL51 – Network Laboratory } else { } else { } result[i-4]=0; c=0; result[i-4]=1; c=0; if(binary[i]==1&&binary[i-4]==1) { result[i-4]=1; c=1; } else if(binary[i]==1&&binary[i-4]==0) { result[i-4]=0; c=1; } else if(binary[i]==0&&binary[i-4]==0) { result[i-4]=1; c=0; } else { } } } result[i-4]=0; c=1; printf("nThe binary value of wrapped sum is:"); for(i=0;i<4;i++) printf("%d",result[i]); printf("nThe binary value of checksum is:"); for(i=0,sum=0,j=3;i<4;i++,j--) { sum1=1; if(result[i]==1) result[i]=0; else result[i]=1; for(k=1;k<=j;k++,sum1=sum1*2); sum=sum+(result[i]*sum1); printf("%d",result[i]); } printf("nThe checksum value is : %d",sum); printf("nThe sender side sending messages are:"); a[n++]=sum; for(i=0;i<n;i++) printf("n%d",a[i]);
  • 60. 18CSL51 – Network Laboratory printf("nn*************** RECEIVER SIDE ****************nn"); printf("nThe Reciever side messages recieved messages are:"); sum=0; //a[0]=3; //to check incorrect message for(i=0;i<n;i++) { printf("n%d",a[i]); sum=sum+a[i]; } printf("nThe sum is: %d",sum); for(i=0;sum>0;i++) { binary1[i]=sum%2; sum=sum/2; } for(;i<8;i++) binary1[i]=0; l=i; for(i=l-1,j=0;i>=0;i--,j++) binary[j]=binary1[i]; printf("nThe equivalent binary digit is :"); for(i=0;i<l;i++) printf("%d",binary[i]); for(c=0,i=l-1;i>=4;i--) { if(c==0) { if(binary[i]==1&&binary[i-4]==1) { result[i-4]=0; c=1; } else if(binary[i]==1&&binary[i-4]==0) { result[i-4]=1; c=0; } else if(binary[i]==0&&binary[i-4]==0) { result[i-4]=0; c=0; } else { result[i-4]=1; c=0; } else { } if(binary[i]==1&&binary[i-4]==1) { result[i-4]=1; c=1; }
  • 61. 18CSL51 – Network Laboratory else if(binary[i]==1&&binary[i-4]==0) { result[i-4]=0; c=1; } else if(binary[i]==0&&binary[i-4]==0) { result[i-4]=1; c=0; } else { } } } result[i-4]=0; c=1; printf("nThe binary value of wrapped sum is:"); for(i=0;i<4;i++) printf("%d",result[i]); printf("nThe binary value of checksum is:"); for(i=0,sum=0,j=3;i<4;i++,j--) { sum1=1; if(result[i]==1) result[i]=0; else result[i]=1; for(k=1;k<=j;k++,sum1=sum1*2); sum=sum+(result[i]*sum1); printf("%d",result[i]); } printf("nThe checksum value is : %d",sum); if(sum==0) printf("nThe recieved message is correctn"); else printf("nThe recieved message is incorrectn"); }
  • 62. 18CSL51 – Network Laboratory Sample Output:
  • 63. 18CSL51 – Network Laboratory
  • 64. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To know detect the errors at the receiver side. • To implement CRC method for error detection in data link layer. • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Do the following steps in sender side: Step 1: Read the dataword (message) to be send from the user using an array. Step 2: Read the 'n' bit common divisor from the user using an array. Step 3: At sender side append n-1 zeros in dataword Step 4: check if the MSB bit position of the divisor and dataword is same then do the Ex-OR operation as stated below crc[j]=itoc((ctoi(crc[j]))^(ctoi(div[j]))); Step 5: Repeat step 4 until the LSB bit of the dataword comes to end. Finally the n-1 bit remainder value (CRC value) is replaced with appended zeros position of the dataword. This message is called codeword. Step 6: At last, the codeword (dataword+remainder) is send to the receiver. Do the following steps in receiver side: Step 7: Read the codeword rom the sender side Step 8: check if the MSB bit position of the divisor and dataword is same then do the Ex-OR operation as stated below crc[j]=itoc((ctoi(crc[j]))^(ctoi(div[j]))); Step 9: Repeat step 4 until the LSB bit of the dataword comes to end. Step 10: Display the receiver side remainder value. Step 11: Check if the remainder value is all zeros then print “the received messages are correct” otherwise print “error is occurred in the received data” Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number 09 Name of the Experiment : Implementation of CRC
  • 65. 18CSL51 – Network Laboratory Computations to be Made: CRC A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data. Blocks of data entering these systems get a short check value attached, based on the remainder of a polynomial division of their contents; on retrieval the calculation is repeated, and corrective action can be taken against presumed data corruption if the check values do not match. CRCs are so called because the check (data verification) value is a redundancy (it expands the message without adding information) and the algorithm is based on cyclic codes. CRCs are popular because they are simple to implement in binary hardware, easy to analyze mathematically, and particularly good at detecting common errors caused by noise in transmission channels. Because the check value has a fixed length, the function that generates it is occasionally used as a hash function. The CRC was invented by W. Wesley Peterson in 1961; the 32-bit polynomial used in the CRC function of Ethernet and many other standards is the work of several researchers and was published during 1975. CRC Operation
  • 66. 18CSL51 – Network Laboratory
  • 67. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • Name the coding categories. • What is modular arithmetic? • What is cyclic codes? • Write the Ex-OR operation. • In CRC, show the relationship between the following entities ( size means the number of bits) ◦ The size of the dataword and the size of the codeword ◦ The size of the divisor and the remainder ◦ The degree of the polynomial generator and the size of the divisor ◦ The degree of the polynomial generator and the size of the remainder • Given the dataword 1010011010 and the divisor 10111 ◦ show the generation of codeword at the sender side ( using binary division) ◦ show the checking of the code word at he receiver side (assume no error) ◦ show the checking of the code word at he receiver side (assume 5th bit is error from left to right) • Which of the following CRC generators guarantee the detection of a single bit error? ◦ X4 + X2 ◦ X3 + X+1 ◦ X2 + 1 ◦ 1 Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To detect errors at the receiver side. ◦ To perform CRC error detection method in data link layer. ◦ To apply this concept in their project work.
  • 68. 18CSL51 – Network Laboratory Program: #include<stdio.h> #include<string.h> int ctoi(char a) { return (a-48); } char itoc(int a) { return (a+48); } void main() { char ip[100],ipm[100],div[20],crc[10],sent[100],rec[100]; int i,lm,ld,j; printf("n************ SENDER SIDE(CRC ENCODING)***********n"); printf("nEnter Data Word ( Message):"); scanf("%s",ip); printf("nEnter Divisor :"); scanf("%s",div); strcpy(ipm,ip); lm=strlen(ipm); ld=strlen(div); if(lm>=ld) { for(i=lm,j=0;j<ld-1;j++) ipm[i++]='0'; ipm[i]='0'; printf("nThe Data Word After Appending Zeros: %s",ipm); for(i=0;i<ld;i++) crc[i]=ipm[i]; crc[i]='0'; for(;i<strlen(ipm);i++) { if(crc[0]=='1') { for(j=0;j<ld;j++) { crc[j]=itoc((ctoi(crc[j]))^(ctoi(div[j]))); } } crc[ld]=ipm[i]; crc[ld+1]='0'; for(j=0;crc[j]!='0';j++) crc[j]=crc[j+1]; crc[j]='0'; }
  • 69. 18CSL51 – Network Laboratory for(j=0;crc[j]!='0';j++) crc[j]=crc[j+1]; crc[j]='0'; printf("nThe CRC Remainder is : %s",crc); strcat(sent,ip); strcat(sent,crc); printf("nThe Code Word in sender side is: %s",sent); printf("nn************ RECEIVER SIDE(CRC DECODING)*************"); strcpy(rec,sent); //rec[2]='1'; // to check error data printf("nnThe recieved message in reciever side is: %s",rec); for(i=0;i<ld;i++) crc[i]=rec[i]; crc[i]='0'; for(;i<strlen(rec);i++) { if(crc[0]=='1') { for(j=0;j<ld;j++) { crc[j]=itoc((ctoi(crc[j]))^(ctoi(div[j]))); } } crc[ld]=rec[i]; crc[ld+1]='0'; for(j=0;crc[j]!='0';j++) crc[j]=crc[j+1]; crc[j]='0'; } for(j=0;crc[j+1]!='0';j++) crc[j]=crc[j+1]; crc[j]='0'; for(j=0;crc[j]!='0';j++) { if(crc[j]!='0') break; } } else printf("nnThe CRC Remainder is: %s",crc); if(j==strlen(crc)) printf("nnThe received message is error free!nn"); else printf("nError in recieved message!!!nn"); printf("nEnter proper divisor"); }
  • 70. 18CSL51 – Network Laboratory Sample Output:
  • 71. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To understand the uses of IP address. • To know the various classes of IP Address and range of each classes IP Address. • To identify the classes of IP Address. • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Step 1: Read the IP Address as input from the user (ex. 10.1.1.1) using character array ip[100]. Step 2: Find out the string length using strlen() function. Step 3: Check out the IP address format using isdigit() function (ex. 12.3a.1.1, 10/1.1.1.12 are incorrect IP Address format) Step 4: Check the loopback IP address (127.0.0.0) by using strcmp() function . Step 5: Convert the IP address as decimal number from string by using the following line of coding for(i=0,s1=0;ip[i]!='.';i++) s1=(s1*10)+ip[i]-48; Step 6: Check the IP address range from 0 to 255 for each part (totally 4: namely s1,s2,s3, s4) Step 7: Check and print the classes of IP address according to the first portion of the IP address range. Step 8: If s1 range of IP address is between 0 to 127 then print the IP address is Class A. Step 9: If s1 range of IP address is between 128 to 191 then print the IP address is Class B. Step 10: If s1 range of IP address is between 192 to 223 then print the IP address is Class C. Step 11: If s1 range of IP address is between 224 to 239 then print the IP address is Class D. Step 12: If s1 range of IP address is between 240 to 255 then print the IP address is Class E. Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number 10 Name of the Experiment : Finding the Classes of IP Address
  • 72. 18CSL51 – Network Laboratory Computations to be Made: An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. An IP address serves two principal functions: host or network interface identification and location addressing. Its role has been characterized as follows: "A name indicates what we seek. An address indicates where it is. A route indicates how to get there." The designers of the Internet Protocol defined an IP address as a 32-bit number and this system, known as Internet Protocol Version 4 (IPv4), is still in use today. However, due to the enormous growth of the Internet and the predicted depletion of available addresses, a new version of IP (IPv6), using 128 bits for the address, was developed in 1995. IPv6 was standardized as RFC 2460 in 1998, and its deployment has been ongoing since the mid-2000s. IP addresses are binary numbers, but they are usually stored in text files and displayed in human-readable notations, such as 172.16.254.1 (for IPv4), and 2001:db8:0:1234:0:567:8:1 (for IPv6). The Internet Assigned Numbers Authority (IANA) manages the IP address space allocations globally and delegates five regional Internet registries (RIRs) to allocate IP address blocks to local Internet registries (Internet service providers) and other entities. Note : The following test cases should be done • IP address format • Check IP Address range is 0 – 255 in each part. • Check Loopback IP Address • Check Multicast IP addresses
  • 73. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • List the range for each classes of IP address. • Define Unicast, Multicast, Broadcast. • What is Loopback Ip Address? Mention the Use of it. • What is the Length of Ipv4 and Ipv6? • What is ICANN? • What is IANA? • List the IANA reserved private Ipv4 network ranges. • What is CIDR? • What is Subnetting and Supernetting? • Give an example for Ipv6. • What is NAT? • Find the error, if any, in the following Ipv4 address. ◦ 111.56.045.78 ◦ 221.34.7.8.20 ◦ 75.45.301.14 ◦ 11100010.23.14.67 • Find the classes of each IP address ◦ 00000001 00001011 00001011 11101111 ◦ 11000001 10000011 00011011 11111111 ◦ 14.23.120.8 ◦ 252.5.15.111 • Write the uses of the following IP addresses ◦ 0.0.0.0 ◦ 10.0.0.0 ◦ 127.0.0.0. ◦ 172.16.0.0 ◦ 192.168.0.0 ◦ 224.0.0.0 ◦ 240.0.0.0 ◦ 255.255.255.255 Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To assign IP address for computer. ◦ To find the classe of IP Address. ◦ To differentiate unicast, multicast, broadcast IP addresses. ◦ To use the various private IP addresses.
  • 74. 18CSL51 – Network Laboratory Program: #include<stdio.h> #include<string.h> #include<ctype.h> main() { char ip[100],part1[100],part2[100],part3[100],part4[100]; int i,j,s1,s2,s3,s4,c,sp,d,l; printf("nn ***************** IP ADDRESS CLASSES ********************nn"); printf("nEnter IP Address : "); scanf("%s",ip); l=strlen(ip); // Testt Case 1: To Check IP Address Format for(i=0,d=0;ip[i]!='0';i++) { if(isdigit(ip[i])) d++; else if((ip[i]=='.')&&(d>0)) d=0; else break; } if(d==0||(i<l)) { printf("n The IP Address is in Wrong Format !!! n "); printf("So please enter correct IP Address:n"); main(); } // Test Case 2: To Check Loopback IP Address else if(strcmp(ip,"127.0.0.0")==0) printf("n%s is a Loopback addressnn");
  • 75. 18CSL51 – Network Laboratory else { // To Convert the the IP Address as Decimal Number from String for(i=0,s1=0;ip[i]!='.';i++) s1=(s1*10)+ip[i]-48; for(i=i+1,s2=0;ip[i]!='.';i++) s2=(s2*10)+ip[i]-48; for(i=i+1,s3=0;ip[i]!='.';i++) s3=(s3*10)+ip[i]-48; for(i=i+1,s4=0;ip[i]!='0';i++) s4=(s4*10)+ip[i]-48; // Test Case 3: To Check IP Addess Range 0 - 255 for each part if((s1>255)||(s2>255)||(s3>255)||(s4>255)) { } else { printf("n The IP Address is in Wrong Format !!! n"); printf("So please enter correct IP Address:n"); main(); // To Find the Classess of IP Address if((s1>=0)&&(s1<128)) printf("n %s is Class A IP Addressnn",ip); else if((s1>127)&&(s1<192)) printf("n %s is Class B IP Addressnn",ip); else if((s1>191)&&(s1<224)) printf("n %s is Class C IP Addressnn",ip); else if((s1>223)&&(s1<240)) printf("n %s is Class D IP Addressnn",ip); else printf("n %s is Class E IP Addressnn",ip); } } }
  • 76. 18CSL51 – Network Laboratory Sample Output:
  • 77. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To know the use of ARP protocol • To mapping logical (IP) to physical address (MAC). • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Step 1: Create an ARP table which contains the IP Address and their corresponding MAC address. And store it as “ARPTABLE.txt” in home directory. Step 2: Create an file descriptor or file pointer to access the file (ARPTABLE.txt) using FILE. FILE *f1; Step 3: First read the file contents using fopen() funtion. f1=fopen("/student/ARPTABLE.txt","r"); Step 4: Check if the file pointer value is null the display the error message. Otherwise read the IP address from the user. Step 5: Check the IP address is in correct format by using the test case. Step 6: Read the IP address and MAC address from ARP table by using fscanf() function. fscanf(f1,"%s%s",ip,mac) Step 7: Compare the user IP address with ARP table IP address by using strcmp() function. strcmp(inip,ip) Step 8: If the IP address matches with APR table then print the corresponding MAC address of the IP address. Step 9: Otherwise check file thoroughly by using feof() funtion. Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number 11 Name of the Experiment : Implementation of ARP
  • 78. 18CSL51 – Network Laboratory Computations to be Made: ARP: Address Resolution Protocol (ARP) is a telecommunications protocol used for resolution of network layer addresses into link layer addresses, a critical function in multiple-access networks. ARP was defined by RFC 826 in 1982. It is Internet Standard STD 37. It is also the name of the program for manipulating these addresses in most operating systems. ARP is used to convert an IP address to a physical address such as an Ethernet address. ARP has been implemented with many combinations of network and data link layer technologies, such as IPv4, Chaosnet, DECnet and Xerox PARC Universal Packet (PUP) using IEEE 802 standards, FDDI, X.25, Frame Relay and Asynchronous Transfer Mode (ATM). IPv4 over IEEE 802.3 and IEEE 802.11 is the most common case. In Internet Protocol Version 6 (IPv6) networks, the functionality of ARP is provided by the Neighbor Discovery Protocol (NDP). The Address Resolution Protocol is a request and reply protocol that runs encapsulated by the line protocol. It is communicated within the boundaries of a single network, never routed across internetwork nodes. This property places ARP into the Link Layer of the Internet Protocol Suite, while in the Open Systems Interconnection (OSI) model, it is often described as residing between Layers 2 and 3, being encapsulated by Layer 2 protocols. However, ARP was not developed in the OSI framework. Proxy ARP: Proxy ARP (Address Resolution Protocol) is a technique by which a device on a given network answers the ARP queries for a network address that is not on that network. The ARP Proxy is aware of the location of the traffic's destination, and offers its own MAC address in reply, effectively saying, "send it to me, and I'll get it to where it needs to go." Serving as an ARP Proxy for another host effectively directs LAN traffic to the Proxy. The "captured" traffic is then typically routed by the Proxy to the intended destination via another interface or via a tunnel. The process which results in the node responding with its own MAC address to an ARP request for a different IP address for proxying purposes is sometimes referred to as 'publishing'. ARP Spoofing: ARP spoofing is a technique whereby an attacker sends fake ("spoofed") Address Resolution Protocol (ARP) messages onto a Local Area Network. Generally, the aim is to associate the attacker's MAC address with the IP address of another host (such as the default gateway), causing any traffic meant for that IP address to be sent to the attacker instead. ARP spoofing may allow an attacker to intercept data frames on a LAN, modify the traffic, or stop the traffic altogether. Often the attack is used as an opening for other attacks, such as denial of service, man in the middle, or session hijacking attacks. The attack can only be used on networks that make use of the Address Resolution Protocol (ARP), and is limited to local network segments.
  • 79. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • What is physical address? • What is logical address? • How to map a logical address to its corresponding physical address and vice versa? • What protocol is used to map logical to physical address? • What are all the protocol is used to map physical to logical address? • Draw the ARP Packet format. • What is mean by APR table? • Which one of the following is broadcast and unicast: ◦ APR request ◦ ARP reply • What is the use of proxy ARP? • Define ARP spoofing. • Type the following commands in your terminal and make a note what you understand. ◦ $ ping www.google.com ◦ $ traceroute www.google.com • What is the length of the following addresses ( in terms of bits): ◦ Port Address ◦ IP Address ◦ MAC Address ◦ IPv6 Address Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To map the MAC address for the corresponding IP address of the computer. ◦ To make use of the IP address and MAC address in their project work. ◦ To assign, modify and delete the ARP table in server.
  • 80. 18CSL51 – Network Laboratory Program: #include<stdio.h> #include<ctype.h> #include<string.h> main() { FILE *f1; int i,d,l; char mac[100],ip[100],inip[100]; f1=fopen("/root/ARPTABLE.txt","r"); printf("n**************** ADDRESS RESOLUTION PROTOCOL*************nn"); if(f1==NULL) printf("nCann't open the file"); else { printf("nEnter the ip address of the host:"); scanf("%s",inip); l=strlen(inip); for(i=0,d=0;inip[i]!='0';i++) { if(isdigit(inip[i])) d++; else if((inip[i]=='.')&&(d>0)) d=0; else break; } if(d==0||(i<l)) { printf("n The IP Address is in Wrong Format !!! n"); printf("n So please enter correct IP Address.n"); main(); } else { while((fscanf(f1,"%s%s",ip,mac))==2) { if(strcmp(inip,ip)==0) { printf("nThe Equivalent MAC address is %snn",mac); break; } } Databasen"); } } } if(feof(f1)) printf("nEquivalent MAC address is not present in Database. So update your
  • 81. 18CSL51 – Network Laboratory Sample Output:
  • 82. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To know the use of RARP protocol. • To mapping physical address (MAC) to logical (IP). • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Step 1: Create an ARP table which contains the IP Address and their corresponding MAC address. And store it as “ARPTABLE.txt” in home directory. Step 2: Create an file descriptor or file pointer to access the file (ARPTABLE.txt) using FILE. FILE *f1; Step 3: First read the file contents using fopen() funtion. f1=fopen("/student/ARPTABLE.txt","r"); Step 4: Check if the file pointer value is null the display the error message. Otherwise read the MAC address from the user. Step 5: Check the MAC address is in correct format by using the test case. Step 6: Read the IP address and MAC address from ARP table by using fscanf() function. fscanf(f1,"%s%s",ip,mac) Step 7: Compare the user MAC address with ARP table MAC address by using strcmp() function. strcmp(inmac,mac) Step 8: If the MAC address matches with APR table then print the corresponding IP address of the MAC address. Step 9: Otherwise check file thoroughly by using feof() funtion. Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number 12 Name of the Experiment : Implementation of RARP
  • 83. 18CSL51 – Network Laboratory Computations to be Made: RARP: The Reverse Address Resolution Protocol (RARP) is an obsolete computer networking protocol used by a host computer to request its Internet Protocol (IPv4) address from an administrative host, when it has available its Link Layer or hardware address, such as a MAC address. RARP is described in Internet Engineering Task Force (IETF) publication RFC 903. It has been rendered obsolete by the Bootstrap Protocol (BOOTP) and the modern Dynamic Host Configuration Protocol (DHCP), which both support a much greater feature set than RARP. RARP requires one or more server hosts to maintain a database of mappings of Link Layer addresses to their respective protocol addresses. Media Access Control (MAC) addresses needed to be individually configured on the servers by an administrator. RARP was limited to serving only IP addresses. Reverse ARP differs from the Inverse Address Resolution Protocol (InARP) described in RFC 2390, which is designed to obtain the IP address associated with a local Frame Relay data link connection identifier. InARP is not used in Ethernet. The machine can get its physical address (by reading its NIC, for example), which is unique locally. It can then use the physical address to get the logical address by using the RARP protocol. A RARP request is created and broadcast on the local network. Another machine on the local network that knows all the IP addresses will respond with a RARP reply. The requesting machine must be running a RARP client program; the responding machine must be running a RARP server program. There is a serious problem with RARP: Broadcasting is done at the data link layer. The physical broadcast address, all is in the case of Ethernet, does not pass the boundaries of a network. This means that if an administrator has several networks or several subnets, it needs to assign a RARP server for each network or subnet. This is the reason that RARP is almost obsolete. Two protocols, BOOTP and DHCP, are replacing RARP. MAC Address Format:
  • 84. 18CSL51 – Network Laboratory BOOTP: In computer networking, the Bootstrap Protocol, or BOOTP, is a network protocol used by a network client to obtain an IP address from a configuration server. The BOOTP protocol was originally defined in RFC 951. BOOTP is usually used during the bootstrap process when a computer is starting up. A BOOTP configuration server assigns an IP address to each client from a pool of addresses. BOOTP uses the User Datagram Protocol (UDP) as a transport on IPv4 networks only. Historically, BOOTP has also been used for Unix-like diskless workstations to obtain the network location of their boot image in addition to an IP address, and also by enterprises to roll out a pre-configured client (e.g., Windows) installation to newly installed PCs. Originally requiring the use of a boot floppy disk to establish the initial network connection, manufacturers of network cards later embedded the protocol in the BIOS of the interface cards as well as system boards with on-board network adapters, thus allowing direct network booting. The Dynamic Host Configuration Protocol (DHCP) is a more advanced protocol for the same purpose and has superseded the use of BOOTP. Most DHCP servers also function as BOOTP servers. DHCP: The Dynamic Host Configuration Protocol (DHCP) is a network protocol used to configure devices that are connected to a network so they can communicate on that network using the Internet Protocol (IP). The protocol is implemented in a client-server model, in which DHCP clients request configuration data, such as an IP address, a default route, and one or more DNS server addresses from a DHCP server. An example of use of the protocol is in a residential local area network (LAN). In this case, a DHCP server is contained in the router while the clients are hosts, e.g., personal computers, smart phones, or printers on the local network. The router itself is a client within the network of the Internet service provider (ISP) and receives its configuration information upstream from the ISP's DHCP server. A DHCP server maintains a database of available IP addresses and configuration information. When the server receives a request from a client, the DHCP server determines the network to which the DHCP client is connected, and then allocates an IP address or prefix that is appropriate for the client, and sends configuration information appropriate for that client. DHCP servers typically grant IP addresses to clients only for a limited interval. DHCP clients are responsible for renewing their IP address before that interval has expired, and must stop using the address once the interval has expired, if they have not been able to renew it. DHCP is used for Internet Protocol version 4 (IPv4), as well as IPv6. While both versions serve the same purpose, the details of the protocol for IPv4 and IPv6 are sufficiently different that they may be considered separate protocols. Hosts that do not use DHCP for address configuration may still use it to obtain other configuration information. Alternatively, IPv6 hosts may use stateless address autoconfiguration. IPv4 hosts may use link-local addressing to achieve limited local connectivity.
  • 85. 18CSL51 – Network Laboratory Questions and problems for assessing the achievement of objective: • What are the protocols are used to map physical to logical address? • What is the problem with RARP protocol? • What is BOOTP? • What is DHCP? • What is InARP? In what ways this protocol is differs from ARP? • What is the advantage of DHCP protocol? • What is the use of FF:FF:FF:FF:FF:FF MAC address? • What is the protocol used to map MAC to IP in Wi-Fi? • Write an Example of the following ◦ Host Name or Host Addressing ◦ Port Address ◦ IP Address ◦ MAC Address • Find the odd man out ◦ ARP ◦ RARP ◦ BOOTP ◦ DHCP • In which layer the following protocols are used: ◦ ARP ◦ InARP ◦ RARP ◦ BOOTP ◦ DHCP Outcome of the Experiment / Practical work: • On completion of the experiment the students will be able to ◦ To map the IP address for the corresponding MAC address of the computer. ◦ To make use of the IP address and MAC address in their project work. ◦ To assign, modify and delete the ARP table in server.
  • 86. 18CSL51 – Network Laboratory Program: #include<stdio.h> #include<ctype.h> #include<string.h> main() { FILE *f1; int i,sp; char mac[100],ip[100],inmac[100]; f1=fopen("/root/ARPTABLE.txt","r"); printf("n*********** REVERSE ADDRESS RESOLUTION PROTOCOL**********nn"); if(f1==NULL) printf("nCann't open the file"); else { printf("nEnter the MAC Address of the Host:"); scanf("%s",inmac); for(i=0,sp=0;inmac[i]!='0';i++) { if(!isalnum(inmac[i])) sp++; if(islower(inmac[i])||((inmac[i]-65)>5)) break; } if(inmac[i]!='0'|| (sp!=5)) { } else { printf("nThe MAC address is not in exact formatn"); printf("nSo please enter correct MAC Address.n"); main(); while((fscanf(f1,"%s%s",ip,mac))==2) { if(strcmp(inmac,mac)==0) { printf("nThe Equivalent IP Address is: %snn",ip); break; } } if(feof(f1)) printf("nEquivalent IP address is not present in Database. So update your Databasen"); } } }
  • 87. 18CSL51 – Network Laboratory Sample Output:
  • 88. 18CSL51 – Network Laboratory Objectives of the Experiment / Practical work: Resource Required: Step-wise Experimental Procedure: On completion of the experiment the students will be able to • To know the responsibilities of network layer. • To understand how the packets are routed within the Autonomous System by using OSPF routing protocol. • To understand the Link State (LS) routing algorithm. • To know the use of Dijkstra's Algorithm. • To know the various routing protocols and its use. • OS : Linux / Windows • C Compiler : cc or gcc / Turbo C • Text Editor : vi or gedit / notepad Step 1: Read the number of nodes in the autonomous system. Step 2: Read the cost matrix values by using an array ( Note: use 999 for infinity symbol (∞)). Step 3: Display the cost matrix. Step 4: Find the shortest path by calling the dijkstra's algorithm lcost=dij(a,n,0,v2); Step 5: In dij() function, find the minimum cost path by calling the srch_min() function. j=srch_min(length,set,n); Step 6: Display the shortest path for all neighbor node from the source node. Course Code : 18CSL51 Course Name : Network Laboratory Experiment Number 13 Name of the Experiment : Implementation of OSPF Routing Protocol