0% found this document useful (0 votes)
190 views68 pages

CN Lab Manual VTU

This document provides information about the Computer Networks Laboratory Manual for the Department of Information Science and Engineering at Sahyadri College of Engineering & Management in Mangaluru, India. It contains details about implementing computer network simulations using NS2/NS3 across wired and wireless network topologies. The laboratory manual covers topics such as point-to-point networks, Ethernet LANs, wireless LANs, GSM and CDMA networks. It also provides information on programming tasks related to error detection, shortest path algorithms, TCP/IP sockets, datagram sockets, RSA encryption and congestion control.

Uploaded by

Samarth Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
190 views68 pages

CN Lab Manual VTU

This document provides information about the Computer Networks Laboratory Manual for the Department of Information Science and Engineering at Sahyadri College of Engineering & Management in Mangaluru, India. It contains details about implementing computer network simulations using NS2/NS3 across wired and wireless network topologies. The laboratory manual covers topics such as point-to-point networks, Ethernet LANs, wireless LANs, GSM and CDMA networks. It also provides information on programming tasks related to error detection, shortest path algorithms, TCP/IP sockets, datagram sockets, RSA encryption and congestion control.

Uploaded by

Samarth Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

SAHYADRI

COLLEGE OF ENGINEERING & MANAGEMENT


MANGALURU
(Affiliated to VTU, Belagavi & Approved by AICTE, New Delhi)

DEPARTMENT OF INFORMATION
SCIENCE & ENGINEERING

COMPUTER NETWORKS
LABORATORY MANUAL
18CSL57

V Semester - BE

Prepared by
Mr. Naitik S T/Ms. Sangeetha H
Asst. Professors

Department of Information Science & Engineering


SAHYADRI College of Engineering & management Adyar, Mangaluru
575 007
COMPUTER NETWORK LABORATORY [18CSL57]

CONTENTS
PART A

Implement three nodes point – to – point network with duplex links between them. Set the queue
1
size, vary the bandwidth and find the number of packets dropped.

Implement transmission of ping messages/trace route over a network topology consisting of 6


2
nodes and find the number of packets dropped due to congestion.

Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion
3
window for different source / destination.

Implement simple ESS and with transmitting nodes in wire-less LAN by simulation and determine
4
the performance with respect to transmission of packets.

Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or equivalent
5
environment.

Implement and study the performance of CDMA on NS2/NS3 (Using stack called Call net) or
6
equivalent environment.

PART B

Implement the following in Java:

7 Write a program for error detecting code using CRC-CCITT (16- bits).

8 Write a program to find the shortest path between vertices using bellman-ford algorithm.

Using TCP/IP sockets, write a client – server program to make the client send the file name and to
9
make the server send back the contents of the requested file if present.

Write a program on datagram socket for client/server to display the messages on client side, typed
10
at the server side.

11 Write a program for simple RSA algorithm to encrypt and decrypt the data.

12 Write a program for congestion control using leaky bucket algorithm.

Department of ISE, SCEM Page 2


COMPUTER NETWORK LABORATORY [18CSL57]

Introduction to NS-2
 Widely known as NS2, is simply an event driven simulation tool.
 Useful in studying the dynamic nature of communication networks.
 Simulation of wired as well as wireless network functions and protocols (e.g., routing
algorithms, TCP, UDP) can be done using NS2. P
 In general, NS2 provides users with a way of specifying such network protocols and
simulating their corresponding behaviors.

Basic Architecture of NS2

Tcl scripting
• Tcl is a general purpose scripting language. [Interpreter]
• Tcl runs on most of the platforms such as Unix, Windows, and Mac.
• The strength of Tcl is its simplicity.
• It is not necessary to declare a data type for variable prior to the usage.

Basics of TCL
Syntax: command arg1 arg2 arg3
o Hello World!
puts stdout{Hello, World!}
Hello, World!

o Variables Command Substitution


set a 5 set len [string length foobar]
set b $a set len [expr [string length foobar] + 9]

o Simple Arithmetic
expr 7.2 / 4

Department of ISE, SCEM Page 3


COMPUTER NETWORK LABORATORY [18CSL57]

o Procedures
proc Diag {a b} {
set c [expr sqrt($a * $a + $b * $b)]
return $c }
puts “Diagonal of a 3, 4 right triangle is [Diag 3 4]”
Output: Diagonal of a 3, 4 right triangle is 5.0

o Loops
while{$i < $n} { for {set i 0} {$i < $n} {incr i} {
... ...
} }

Wired TCL Script Components


Create the event scheduler
Open new files & turn on the tracing
Create the nodes
Setup the links
Configure the traffic type (e.g., TCP, UDP, etc)
Set the time of traffic generation (e.g., CBR, FTP)
Terminate the simulation

NS Simulator Preliminaries.
1. Initialization and termination aspects of the ns simulator.
2. Definition of network nodes, links, queues and topology.
3. Definition of agents and of applications.
4. The nam visualization tool.
5. Tracing and random variables.

Initialization and Termination of TCL Script in NS-2


An ns simulation starts with the command
set ns [new Simulator]
Which is thus the first line in the tcl script? This line declares a new variable as using the set
command, you can call this variable as you wish, In general people declares it as ns because it is an
instance of the Simulator class, so an object the code[new Simulator] is indeed the installation of the
class Simulator using the reserved word new.

In order to have output files with data on the simulation (trace files) or files used for visualization
(nam files), we need to create the files using “open” command:

#Open the Trace file


set tracefile1 [open out.tr w]
$ns trace-all $tracefile1

Department of ISE, SCEM Page 4


COMPUTER NETWORK LABORATORY [18CSL57]

#Open the NAM trace file


set namfile [open out.nam w]
$ns namtrace-all $namfile

The above creates a dta trace file called ”out.tr” and a nam visualization trace file called ”out.nam”.
Within the tcl script, these files are not called explicitly by their names, but instead by pointers that
are declared above and called “tracefile1” and “namfile” respectively. Remark that they begins with
a # symbol. The second line open the file “out.tr” to be used for writing, declared with the letter “w”.
The third line uses a simulator method called trace-all that have as parameter the name of the file
where the traces will go. The last line tells the simulator to record all simulation traces in NAM input
format. It also gives the file name that the trace will be written to later by the command $ns flush-
trace.In our case,this will be the file pointed at by the pointer “$namfile”, i.e the file “out.tr”. The
termination of the program is done using a “finish” procedure.

#Define a ”finish” procedure


Proc finish { } {
global ns tracefile1 namfile
$ns flush-trace
Close $tracefile1
Close $namfile
Exec nam out.nam &
Exit 0
}

The word proc declares a procedure in this case called finish and without arguments. The word
global is used to tell that we are using variables declared outside the procedure.
The simulator method “flush-trace” will dump the traces on the respective files. The tcl
command “close” closes the trace files defined before and exec executes the nam program for
visualization. The command exit will ends the application and return the number 0 as status to the
system. Zero is the default for a clean exit. Other values can be used to say that is a exit because
something fails.
At the end of ns program we should call the procedure “finish” and specify at what time the
termination should occur. For example,
$ns at 125.0 “finish”
Above script will be used to call “finish” at time 125sec.Indeed,the at method of the simulator
allows us to schedule events explicitly.

The simulation can then begin using the command


$ns run

Definition of a network of links and nodes


The way to define a node is
set n0 [$ns node]
The node is created which is printed by the variable n0. When we shall refer to that node in the
script we shall thus write $n0.
Once we define several nodes, we can define the links that connect them. An example of a definition
of a link is:
$ns duplex-link $n0 $n2 10Mb 10ms DropTail

Department of ISE, SCEM Page 5


COMPUTER NETWORK LABORATORY [18CSL57]

Which means that $n0 and $n2 are connected using a bi-directional link that has 10ms of
propagation delay and a capacity of 10Mb per sec for each direction.

To define a directional link instead of a bi-directional one, we should replace “duplex-link” by


“simplex-link”. In NS, an output queue of a node is implemented as a part of each link whose input is
that node. The definition of the link then includes the way to handle overflow at that queue. In our
case, if the buffer capacity of the output queue is exceeded then the last packet to arrive is dropped.
Many alternative options exist, such as the RED (Random Early Discard) mechanism, the FQ (Fair
Queuing), the DRR (Deficit Round Robin), the stochastic Fair Queuing (SFQ) and the CBQ (which
including a priority and a round-robin scheduler).

In ns, an output queue of a node is implemented as a part of each link whose input is that node. We
should also define the buffer capacity of the queue related to each link. An example would be:
#set Queue Size of link (n0-n2) to 20
$ns queue-limit $n0 $n2 20

Agents and Applications


We need to define routing (sources, destinations) the agents (protocols) the application that use
them.

FTP over TCP


TCP is a dynamic reliable congestion control protocol. It uses Acknowledgements created by the
destination to know whether packets are well received.
There are number variants of the TCP protocol, such as Tahoe, Reno, NewReno, Vegas. The type of
agent appears in the first line:
set tcp [new Agent/TCP]

The command $ns attach-agent $n0 $tcp defines the source node of the tcp connection. The
command
set sink [new Agent /TCPSink]
Defines the behavior of the destination node of TCP and assigns to it a pointer called sink.

#Setup a UDP connection


set udp [new Agent/UDP]
$ns attach-agent $n1
$udp set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_2

#Setup a CBR over UDP connection


The below shows the definition of a CBR application using a UDP agent The command $ns attach-
agent $n4 $sink defines the destination node.
The command $ns connect $tcp $sink finally makes the TCP connection between the source and
destination nodes.
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetsize_ 100

Department of ISE, SCEM Page 6


COMPUTER NETWORK LABORATORY [18CSL57]

$cbr set rate_ 0.01Mb


$cbr set random_ false
TCP has many parameters with initial fixed defaults values that can be changed if mentioned
explicitly. For example, the default TCP packet size has a size of 1000bytes.This can be changed to
another value, say 552bytes, using the command $tcp set packetSize_ 552.
When we have several flows, we may wish to distinguish them so that we can identify them
with different colors in the visualization part. This is done by the command $tcp set fid_ 1 that
assigns to the TCP connection a flow identification of “1”.We shall later give the flow identification of
“2” to the UDP connection.

CBR over UDP


A UDP source and destination is defined in a similar way as in the case of TCP.
Instead of defining the rate in the command $cbr set rate_ 0.01Mb, one can define the time
interval between transmission of packets using the command.
$cbr set interval_ 0.005
The packet size can be set to some value using
$cbr set packetSize_ <packet size>

Scheduling Events
NS is a discrete event based simulation. The tcp script defines when event should occur. The
initializing command set ns [new Simulator] creates an event scheduler, and events are then
scheduled using the format:
$ns at <time><event>

The scheduler is started when running ns that is through the command $ns run. The beginning and
end of the FTP and CBR application can be done through the following command
$ns at 0.1 “$cbr start”
$ns at 1.0 “ $ftp start”
$ns at 124.0 “$ftp stop”
$ns at 124.5 “$cbr stop”

Department of ISE, SCEM Page 7


COMPUTER NETWORK LABORATORY [18CSL57]

Structure of Trace Files

When tracing into an output ASCII file, the trace is organized in 12 fields as follows in fig shown
below, The meaning of the fields are:

Event Time From To PKT PKT Flags Fid Src Dest Seq Pkt id
Node Node Type Size Addr Addr Num

1. The first field is the event type. It is given by one of four possible symbols r, +, -, d which
correspond respectively to receive (at the output of the link), enqueued, dequeued and
dropped.
2. The second field gives the time at which the event occurs.
3. Gives the input node of the link at which the event occurs.
4. Gives the output node of the link at which the event occurs.
5. Gives the packet type (eg CBR or TCP)
6. Gives the packet size
7. Some flags
8. This is the flow id (fid) of IPv6 that a user can set for each flow at the input OTcl script one
can further use this field for analysis purposes; it is also used when specifying stream color
for the NAM display.
9. This is the source address given in the form of ―node.port‖.
10. This is the destination address, given in the same form.
11. This is the network layer protocol‘s packet sequence number. Even though UDP
implementations in a real network do not use sequence number, ns keeps track of UDP
packet sequence number for analysis purposes
12. The last field shows the unique id of the packet.

Department of ISE, SCEM Page 8


COMPUTER NETWORK LABORATORY [18CSL57]

XGRAPH

The xgraph program draws a graph on an x-display given data read from either data file or from
standard input if no files are specified. It can display upto 64 independent data sets using different
colors and line styles for each set. It annotates the graph with a title, axis labels, grid lines or tick
marks, grid labels and a legend.
Syntax:

Xgraph [options] file-name


Options are listed here
/-bd <color> (Border)
This specifies the border color of the xgraph window.

/-bg <color> (Background)


This specifies the background color of the xgraph window.

/-fg<color> (Foreground)
This specifies the foreground color of the xgraph window.

/-lf <fontname> (LabelFont)


All axis labels and grid labels are drawn using this font.

/-t<string> (Title Text)


This string is centered at the top of the graph.

/-x <unit name> (XunitText)


This is the unit name for the x-axis. Its default is “X”.

/-y <unit name> (YunitText)


This is the unit name for the y-axis. Its default is “Y”.

Department of ISE, SCEM Page 9


COMPUTER NETWORK LABORATORY [18CSL57]

Awk- An Advanced

Awk is a programmable, pattern-matching, and processing tool available in UNIX. It works equally
well with text and numbers.
Awk is not just a command, but a programming language too. In other words, awk utility is a pattern
scanning and processing language. It searches one or more files to see if they contain lines that
match specified patterns and then perform associated actions, such as writing the line to the
standard output or incrementing a counter each time it finds a match.

Syntax:
awk option ‘selection_criteria {action}’ file(s)

Here, selection_criteria filters input and select lines for the action component to act upon. The
selection_criteria is enclosed within single quotes and the action within the curly braces. Both the
selection_criteria and action forms an awk program.
Example: $ awk „/manager/ {print}‟ emp.lst

Variables
Awk allows the user to use variables of there choice. You can now print a serial number, using the
variable kount, and apply it those directors drawing a salary exceeding 6700:
$ awk –F”|” „$3 == “director” && $6 > 6700 {
kount =kount+1
printf “ %3f %20s %-12s %d\n”, kount,$2,$3,$6 }‟ empn.lst

THE –f OPTION: STORING awk PROGRAMS IN A FILE


You should holds large awk programs in separate file and provide them with the awk extension for
easier identification. Let‘s first store the previous program in the file empawk.awk:
$ cat empawk.awk
Observe that this time we haven‘t used quotes to enclose the awk program. You can now use awk
with the –f filename option to obtain the same output:
Awk –F”|” –f empawk.awk empn.lst

THE BEGIN AND END SECTIONS


Awk statements are usually applied to all lines selected by the address, and if there are no
addresses, then they are applied to every line of input. But, if you have to print something before
processing the first line, for example, a heading, then the BEGIN section can be used gainfully.
Similarly, the end section useful in printing some totals after processing is over. The BEGIN and END
sections are optional and take the form
BEGIN {action}
END {action}
These two sections, when present, are delimited by the body of the awk program. You can use them
to print a suitable heading at the beginning and the average salary at the end.

BUILT-IN VARIABLES
Awk has several built-in variables. They are all assigned automatically, though it is also possible for
a user to reassign some of them. You have already used NR, which signifies the record number of the
current line. We‘ll now have a brief look at some of the other variable.

Department of ISE, SCEM Page 10


COMPUTER NETWORK LABORATORY [18CSL57]

The FS Variable: as stated elsewhere, awk uses a contiguous string of spaces as the default field
delimiter. FS redefines this field separator, which in the sample database happens to be the |. When
used at all, it must occur in the BEGIN section so that the body of the program knows its value before
it starts processing:
BEGIN {FS=”|”}
This is an alternative to the –F option which does the same thing.

The OFS Variable: when you used the print statement with comma-separated arguments, each
argument was separated from the other by a space. This is awk‘s default output field separator, and
can reassigned using the variable OFS in the BEGIN section: BEGIN { OFS=”~” }
When you reassign this variable with a ~ (tilde), awk will use this character for delimiting the print
arguments. This is a useful variable for creating lines with delimited fields.

The NF variable: NF comes in quite handy for cleaning up a database of lines that don‘t contain the
right number of fields. By using it on a file, say emp.lst, you can locate those lines not having 6 fields,
and which have crept in due to faulty data entry:
$awk „BEGIN {FS = “|”}
NF! =6 {
Print “Record No “, NR, “has”, “fields”}‟ empx.lst

Department of ISE, SCEM Page 11


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 01: Point to point network

1.1 Experiment Details 1.5 Results


1.2 Software Required 1.6 Pre- Experiment Questions
1.3 Pre-Requisite 1.7 Post- Experiment Questions
1.4 Procedure

1.1 Experiment Details:

Implement three nodes point – to – point network with duplex links between them. Set the
queue size, vary the bandwidth and find the number of packets dropped.

1.2 Softwares used:

Operating System: Ubuntu 16.04 LTS


Simulator: NS2

1.3 Pre-Requisite:

Basics of Networking, NS2 ,TCL script

1.4 Procedure:

set ns [new Simulator] /* Letter S is capital */


set nf [open lab1.nam w] /* open a nam trace file in write mode */
$ns namtrace-all $nf /* nf – nam file */

set tf [open lab1.tr w] /* tf- trace file */


$ns trace-all $tf

proc finish { } { /* provide space b/w proc and finish and all are in small case */
global ns nf tf
$ns flush-trace /* clears trace file contents */
close $nf
close $tf
exec nam lab1.nam &
exit 0
}
set n0 [$ns node] /* creates 4 nodes */
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
$ns duplex-link $n0 $n2 200Mb 10ms DropTail /*Letter M is capital Mb*/

Department of ISE, SCEM Page 12


COMPUTER NETWORK LABORATORY [18CSL57]

$ns duplex-link $n1 $n2 100Mb 5ms DropTail /*D and T are capital*/
$ns duplex-link $n2 $n3 1Mb 1000ms DropTail

$ns queue-limit $n0 $n2 10


$ns queue-limit $n1 $n2 10

set udp0 [new Agent/UDP] /* Letters A,U,D and P are capital */


$ns attach-agent $n0 $udp0

set cbr0 [new Application/Traffic/CBR] /* A,T,C,B and R are capital*/


$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

set udp1 [new Agent/UDP]


$ns attach-agent $n1 $udp1

set cbr1 [new Application/Traffic/CBR]


$cbr1 attach-agent $udp1

set udp2 [new Agent/UDP]


$ns attach-agent $n2 $udp2

set cbr2 [new Application/Traffic/CBR]


$cbr2 attach-agent $udp2

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


$ns attach-agent $n3 $null0

$ns connect $udp0 $null0


$ns connect $udp1 $null0

$ns at 0.1 "$cbr0 start"


$ns at 0.2 "$cbr1 start"
$ns at 1.0 "finish"

$ns run

Department of ISE, SCEM Page 13


COMPUTER NETWORK LABORATORY [18CSL57]

AWK file

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

Steps for execution:

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

2. Open gedit editor and type awk program. Program name should have the extension “.awk “
[root@localhost ~]# gedit lab1.awk

3. Run the simulation program


[root@localhost~]# ns lab1.tcl

4. Here “ns” indicates network simulator. We get the topology shown in the snapshot. Now press the
play button in the simulation window and the simulation will begins.

5. After simulation is completed run awk file to see the output


[root@localhost~]# awk –f lab1.awk lab1.tr

6. To see the trace file contents open the file as ,


[root@localhost~]# gedit out.tr

7. Change Bandwidth, Queue limit in the TCL file. Repeat the steps

Department of ISE, SCEM Page 14


COMPUTER NETWORK LABORATORY [18CSL57]

Topology:

Department of ISE, SCEM Page 15


COMPUTER NETWORK LABORATORY [18CSL57]

1.5 Results:

1.6 Pre – Experiment Questions:

1. What is computer network?


2. What is topology?
3. Which are the types of topology?
4. How many layers are there in TCP/IP model?

1.7 Post- Experiment Questions

1. What is bandwidth?
2. What is Queue size?
3. How to modify the no of packets dropped?
4. Why awk is used?

Department of ISE, SCEM Page 16


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 02: Ping msg transmission


2.1 Experiment Details 2.5 Results
2.2 Softwares Required 2.6 Pre- Experiment Questions
2.3 Pre-Requisite 2.7 Post- Experiment Questions
2.4 Procedure

2.1 Experiment Details:

Implement transmission of ping messages/trace route over a network topology consisting of


6 nodes and find the number of packets dropped due to congestion.

2.2 Softwares used:

Operating System: Ubuntu 16.04 LTS


Simulator: NS2

2.3 Pre-Requisite:

Basics of Networking, NS2 ,TCL script

2.4 Procedure:

set ns [ new Simulator ]


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

set n0 [$ns node]


set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]

$n4 shape box


$ns duplex-link $n0 $n4 1005Mb 1ms DropTail
$ns duplex-link $n1 $n4 50Mb 1ms DropTail
$ns duplex-link $n2 $n4 2000Mb 1ms DropTail

Department of ISE, SCEM Page 17


COMPUTER NETWORK LABORATORY [18CSL57]

$ns duplex-link $n3 $n4 200Mb 1ms DropTail


$ns duplex-link $n4 $n5 1Mb 1ms DropTail

set p1 [new Agent/Ping]


$ns attach-agent $n0 $p1
$p1 set packetSize_ 50000
$p1 set interval_ 0.0001
set p2 [new Agent/Ping]
$ns attach-agent $n1 $p2
set p3 [new Agent/Ping]
$ns attach-agent $n2 $p3
$p3 set packetSize_ 30000
$p3 set interval_ 0.00001
set p4 [new Agent/Ping]
$ns attach-agent $n3 $p4
set p5 [new Agent/Ping]
$ns attach-agent $n5 $p5
$ns queue-limit $n0 $n4 5
$ns queue-limit $n2 $n4 3
$ns queue-limit $n4 $n5 2

Agent/Ping instproc recv {from rtt} {


$self instvar node_
puts "node [$node_ id] received answer from $from with round trip time $rtt msec"
}
# please provide space between $node_ and id. No space between $ and from. No
#space between and $ and rtt */
$ns connect $p1 $p5
$ns connect $p3 $p4
proc finish { } {
global ns nf tf
$ns flush-trace
close $nf
close $tf
exec nam lab2.nam &
exit 0
}

$ns at 0.1 "$p1 send"


$ns at 0.2 "$p1 send"
$ns at 0.3 "$p1 send"
$ns at 0.4 "$p1 send"

Department of ISE, SCEM Page 18


COMPUTER NETWORK LABORATORY [18CSL57]

$ns at 0.5 "$p1 send"


$ns at 0.6 "$p1 send"
$ns at 0.7 "$p1 send"
$ns at 0.8 "$p1 send"
$ns at 0.9 "$p1 send"
$ns at 1.0 "$p1 send"
$ns at 1.1 "$p1 send"
$ns at 1.2 "$p1 send"
$ns at 1.3 "$p1 send"
$ns at 1.4 "$p1 send"
$ns at 1.5 "$p1 send"
$ns at 1.6 "$p1 send"
$ns at 1.7 "$p1 send"
$ns at 1.8 "$p1 send"
$ns at 1.9 "$p1 send"
$ns at 2.0 "$p1 send"
$ns at 2.1 "$p1 send"
$ns at 2.2 "$p1 send"
$ns at 2.3 "$p1 send"
$ns at 2.4 "$p1 send"
$ns at 2.5 "$p1 send"
$ns at 2.6 "$p1 send"
$ns at 2.7 "$p1 send"
$ns at 2.8 "$p1 send"
$ns at 2.9 "$p1 send"
$ns at 0.1 "$p3 send"
$ns at 0.2 "$p3 send"
$ns at 0.3 "$p3 send"
$ns at 0.4 "$p3 send"
$ns at 0.5 "$p3 send"
$ns at 0.6 "$p3 send"
$ns at 0.7 "$p3 send"
$ns at 0.8 "$p3 send"
$ns at 0.9 "$p3 send"
$ns at 1.0 "$p3 send"
$ns at 1.1 "$p3 send"
$ns at 1.2 "$p3 send"
$ns at 1.3 "$p3 send"
$ns at 1.4 "$p3 send"
$ns at 1.5 "$p3 send"
$ns at 1.6 "$p3 send"
$ns at 1.7 "$p3 send"
$ns at 1.8 "$p3 send"

Department of ISE, SCEM Page 19


COMPUTER NETWORK LABORATORY [18CSL57]

$ns at 1.9 "$p3 send"


$ns at 2.0 "$p3 send"
$ns at 2.1 "$p3 send"
$ns at 2.2 "$p3 send"
$ns at 2.3 "$p3 send"
$ns at 2.4 "$p3 send"
$ns at 2.5 "$p3 send"
$ns at 2.6 "$p3 send"
$ns at 2.7 "$p3 send"
$ns at 2.8 "$p3 send"
$ns at 2.9 "$p3 send"
$ns at 3.0 "finish"
$ns run

AWK file

BEGIN{
drop=0;
}
{
if($1=="d")
{
drop++;
}
}
END{
printf("Total number of %s packets dropped due to congestion =%d\n",$5,drop);
}

Steps for execution:


1. Open gedit editor and type program. Program name should have the extension “.tcl “
[root@localhost ~]# gedit lab2.tcl

2. Open gedit editor and type awk program. Program name should have the extension “.awk “
[root@localhost ~]# gedit lab2.awk

3. Run the simulation program


[root@localhost~]# ns lab2.tcl

4. Here “ns” indicates network simulator. We get the topology shown in the snapshot. Now press the
play button in the simulation window and the simulation will begins.

5. After simulation is completed run awk file to see the output


[root@localhost~]# awk –f lab2.awk lab2.tr

Department of ISE, SCEM Page 20


COMPUTER NETWORK LABORATORY [18CSL57]

6. To see the trace file contents open the file as ,


[root@localhost~]# gedit out.tr

To see the trace file contents open the file as ,


[root@localhost~]# gedit lab2.tr

Topology:

Department of ISE, SCEM Page 21


COMPUTER NETWORK LABORATORY [18CSL57]

1.5 Results:

Department of ISE, SCEM Page 22


COMPUTER NETWORK LABORATORY [18CSL57]

2.6 Pre-experiment questions:


1. What is PING?
2. Expand ICMP.
3. What is point to point network?

2.7 Post experiment questions:


1. What is RTT?
2. What is congestion?
3. What is Traceroute?
4. Explain Ping statistics.

Department of ISE, SCEM Page 23


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 03: Ethernet LAN


3.1 Experiment Details 3.5 Results
3.2 Softwares Required 3.6 Pre-Experiment Questions
3.3 Pre-Requisite 3.7 Post-Experiment Questions
3.4 Procedure

3.1 Experiment Details:

Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot
congestion window for different source / destination.

3.2 Softwares Required:

Operating System: Ubuntu 16.04 LTS


Simulator: NS2

3.3 Pre-Requisite:
Basics of Networking, NS2 ,TCL script

3.4 Procedure:

set ns [new Simulator]


set tf [open lab3.tr w]
$ns trace-all $tf
set nf [open lab3.nam w]
$ns namtrace-all $nf

set n0 [$ns node]


$n0 color "magenta"
$n0 label "src1"

set n1 [$ns node]


set n2 [$ns node]
$n2 color "magenta"
$n2 label "src2"

set n3 [$ns node]


$n3 color "blue"

Department of ISE, SCEM Page 24


COMPUTER NETWORK LABORATORY [18CSL57]

$n3 label "dest2"

set n4 [$ns node]


set n5 [$ns node]
$n5 color "blue"
$n5 label "dest1"

$ns make-lan "$n0 $n1 $n2 $n3 $n4" 100Mb 100ms LL Queue/DropTail Mac/802_3
/* should come in single line */
$ns duplex-link $n4 $n5 1Mb 1ms DropTail

set tcp0 [new Agent/TCP]


$ns attach-agent $n0 $tcp0
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ftp0 set packetSize_ 500
$ftp0 set interval_ 0.0001
set sink5 [new Agent/TCPSink]
$ns attach-agent $n5 $sink5
$ns connect $tcp0 $sink5
set tcp2 [new Agent/TCP]
$ns attach-agent $n2 $tcp2
set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2
$ftp2 set packetSize_ 600
$ftp2 set interval_ 0.001
set sink3 [new Agent/TCPSink]
$ns attach-agent $n3 $sink3
$ns connect $tcp2 $sink3
set file1 [open file1.tr w]
$tcp0 attach $file1
set file2 [open file2.tr w]
$tcp2 attach $file2

$tcp0 trace cwnd_ /* must put underscore ( _ ) after cwnd and no space between them*/
$tcp2 trace cwnd_

proc finish { } {
global ns nf tf
$ns flush-trace close $tf
close $nf
exec nam lab3.nam &
exit 0

Department of ISE, SCEM Page 25


COMPUTER NETWORK LABORATORY [18CSL57]

$ns at 0.1 "$ftp0 start"


$ns at 5 "$ftp0 stop"
$ns at 7 "$ftp0 start"
$ns at 0.2 "$ftp2 start"
$ns at 8 "$ftp2 stop"
$ns at 14 "$ftp0 stop"
$ns at 10 "$ftp2 start"
$ns at 15 "$ftp2 stop"
$ns at 16 "finish"
$ns run

AWK file

cwnd:- means congestion window

BEGIN {
}
{
if($6=="cwnd_") /* don’t leave space after writing cwnd_ */
printf("%f\t%f\t\n",$1,$7); /* you must put \n in printf */
}
END {
}

Steps for execution :

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

2. Open gedit editor and type awk program. Program name should have the extension “.awk

[root@localhost ~]# gedit lab3.awk

3. Run the simulation program


[root@localhost~]# ns lab3.tcl

4. After simulation is completed run awk file to see the output ,


[root@localhost~]# awk –f lab3.awk f1.tr >a1
[root@localhost~]# awk –f lab3.awk f2.tr >a2

[root@localhost~]# xgraph a1 a2
Here we are using the congestion window trace files i.e. file1.tr and file2.tr and we are
redirecting the contents of those files to new files say a1 and a2 using output redirection
operator (>).
Department of ISE, SCEM Page 26
COMPUTER NETWORK LABORATORY [18CSL57]

5. To see the trace file contents open the file as ,


[root@localhost~]# gedit out.tr

6. Change Bandwidth, Queue limit in the TCL file. Repeat the steps

1.5 Results:

Department of ISE, SCEM Page 27


COMPUTER NETWORK LABORATORY [18CSL57]

Xgraph Result:

3.6 Pre-experiment questions:


1. Expand LAN.
2. Explain types of LAN.
3. Describe the causes for congestion.
4. Difference between wired and wireless network?

3.7. Post experiment questions:


1. What is congestion window?
2. What is SSH?
3. What is AIMD in TCP congestion control?
4. How to reduce congestion in network?

Department of ISE, SCEM Page 28


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 04: Simple ESS


4.1 Experiment Details 4.5 Results
4.2 Softwares Required 4.6 Pre-Experiment Questions
4.3 Pre-Requisite 4.7 Post-Experiment Questions
4.4 Procedure

4.1 Experiment Details

Implement simple ESS and with transmitting nodes in wire-less LAN by simulation
and determine the performance with respect to transmission of packets.

3.1 Experiment Details:

Implement an Ethernet LAN using n nodes and set multiple traffic nodes and plot congestion
window for different source / destination.

3.2 Softwares Required:

Operating System: Ubuntu 16.04 LTS


Simulator: NS2

3.3Pre-Requisite:
Basics of Networking, NS2 ,TCL script

3.4 Procedure:

set ns [new Simulator]


set tf [open lab4.tr w]
$ns trace-all $tf
set topo [new Topography]
$topo load_flatgrid 1000 1000
set nf [open lab4.nam w]
$ns namtrace-all-wireless $nf 1000 1000
$ns node-config -adhocRouting DSDV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail \
-ifqLen 50 \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-propType Propagation/TwoRayGround \
-antType Antenna/OmniAntenna \

Department of ISE, SCEM Page 29


COMPUTER NETWORK LABORATORY [18CSL57]

-topoInstance $topo \
-agentTrace ON \
-routerTrace ON
create-god 3
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

$n0 label "tcp0"


$n1 label "sink1/tcp1"
$n2 label "sink2"

$n0 set X_ 50
$n0 set Y_ 50
$n0 set Z_ 0
$n1 set X_ 100
$n1 set Y_ 100
$n1 set Z_ 0
$n2 set X_ 600
$n2 set Y_ 600
$n2 set Z_ 0

$ns at 0.1 "$n0 setdest 50 50 15"


$ns at 0.1 "$n1 setdest 100 100 25"
$ns at 0.1 "$n2 setdest 600 600 25"

set tcp0 [new Agent/TCP]


$ns attach-agent $n0 $tcp0

set ftp0 [new Application/FTP]


$ftp0 attach-agent $tcp0

set sink1 [new Agent/TCPSink]


$ns attach-agent $n1 $sink1
$ns connect $tcp0 $sink1
set tcp1 [new Agent/TCP]
$ns attach-agent $n1 $tcp1
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
set sink2 [new Agent/TCPSink]
$ns attach-agent $n2 $sink2
$ns connect $tcp1 $sink2
$ns at 5 "$ftp0 start"

Department of ISE, SCEM Page 30


COMPUTER NETWORK LABORATORY [18CSL57]

$ns at 5 "$ftp1 start"


$ns at 100 "$n1 setdest 550 550 15"
$ns at 190 "$n1 setdest 70 70 15"
proc finish { } {
global ns nf tf
$ns flush-trace
exec nam lab4.nam &
close $tf
exit 0
}
$ns at 250 "finish"
$ns run

AWK file
BEGIN{
count1=0
count2=0
pack1=0
pack2=0
time1=0
time2=0
}
{
if($1=="r"&& $3=="_1_"&& $4=="AGT")
{
count1++
pack1=pack1+$8
time1=$2
}
if($1=="r"&& $3=="_2_"&& $4=="AGT")
{
count2++
pack2=pack2+$8
time2=$2
}
}
END{
printf("The Throughput from n0 to n1: %f Mbps\n",((count1*pack1*8)/(time1*1000000)));
printf("The Throughput from n1 to n2: %f Mbps", ((count2*pack2*8)/(time2*1000000)));
}

Department of ISE, SCEM Page 31


COMPUTER NETWORK LABORATORY [18CSL57]

Steps for execution:

1. Open gedit editor and type program. Program name should have the extension “.tcl “
[root@localhost ~]# gedit lab4.tcl

2. Open gedit editor and type awk program. Program name should have the extension “.awk “
[root@localhost ~]# gedit lab4.awk

3. Run the simulation program


[root@localhost~]# ns lab4.tcl

4. Here “ns” indicates network simulator. We get the topology shown in the snapshot. Now press the
play button in the simulation window and the simulation will begins.

5. After simulation is completed run awk file to see the output


[root@localhost~]# awk –f lab4.awk lab4.tr

6. To see the trace file contents open the file as ,


[root@localhost~]# gedit out.tr

7. To see the trace file contents open the file as ,


[root@localhost~]# vi lab4.tr

Department of ISE, SCEM Page 32


COMPUTER NETWORK LABORATORY [18CSL57]

4.5 Results:

Trace file

Department of ISE, SCEM Page 33


COMPUTER NETWORK LABORATORY [18CSL57]

Output:

4.6 Pre-experiment questions:


1. What is ESS?
2. Expand ESS.
3. What is the role of ESS in Cellular network?

4.7 Post experiment questions:


1. What is throughput?
2. What is node?
3. How to increase throughput in ESS

Department of ISE, SCEM Page 34


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 05: GSM performance

5.1 Experiment Details 5.5 Results


5.2 Softwares Required 5.6 Pre- Experiment Questions
5.3 Pre-Requisite 5.7 Post- Experiment Questions
5.4 Procedure

5.1 Experiment Details:


Implement and study the performance of GSM on NS2/NS3 (Using MAC layer) or equivalent
environment.

5.2 Softwares Required:

Operating System: Ubuntu 16.04 LTS


Simulator: NS2
Scenario: nsg2.1

5.3 Pre-Requisite:
Basics of Networking, NS2 ,TCL script

5.4 Procedure

5.tcl:
# This script is created by NSG2 beta1
# <http://wushoupong.googlepages.com/nsg>
#===================================
# Simulation parameters setup
#===================================
set val(chan) Channel/WirelessChannel ;# channel type
set val(prop) Propagation/TwoRayGround ;# radio-propagation model
set val(netif) Phy/WirelessPhy ;# network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# interface queue type
set val(ll) LL ;# link layer type
set val(ant) Antenna/OmniAntenna ;# antenna model
set val(ifqlen) 50 ;# max packet in ifq
set val(nn) 8 ;# number of mobilenodes
set val(rp) AODV ;# routing protocol
set val(x) 1184 ;# X dimension of topography
set val(y) 640 ;# Y dimension of topography
set val(stop) 10.0 ;# time of simulation end
#===================================
# Initialization
#===================================
#Create a ns simulator
set ns [new Simulator]

Department of ISE, SCEM Page 35


COMPUTER NETWORK LABORATORY [18CSL57]

#Setup topography object


set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
create-god $val(nn)
#Open the NS trace file
set tracefile [open 5.tr w]
$ns trace-all $tracefile
#Open the NAM trace file
set namfile [open 5.nam w]
$ns namtrace-all $namfile
$ns namtrace-all-wireless $namfile $val(x) $val(y)
set chan [new $val(chan)];#Create wireless channel
#===================================
# Mobile node parameter setup
#===================================
$ns node-config -adhocRouting $val(rp) \

-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channel $chan \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
#===================================
# Nodes Definition
#===================================
#Create 8 nodes
set n0 [$ns node]
$n0 set X_ 149
$n0 set Y_ 219
$n0 set Z_ 0.0
$ns initial_node_pos $n0 20
set n1 [$ns node]
$n1 set X_ 321
$n1 set Y_ 321
$n1 set Z_ 0.0
$ns initial_node_pos $n1 20
set n2 [$ns node]
$n2 set X_ 474
$n2 set Y_ 426
$n2 set Z_ 0.0

Department of ISE, SCEM Page 36


COMPUTER NETWORK LABORATORY [18CSL57]

$ns initial_node_pos $n2 20


set n3 [$ns node]
$n3 set X_ 668
$n3 set Y_ 540
$n3 set Z_ 0.0
$ns initial_node_pos $n3 20
set n4 [$ns node]
$n4 set X_ 770
$n4 set Y_ 344
$n4 set Z_ 0.0
$ns initial_node_pos $n4 20
set n5 [$ns node]
$n5 set X_ 720
$n5 set Y_ 144
$n5 set Z_ 0.0
$ns initial_node_pos $n5 20
set n6 [$ns node]

$n6 set X_ 894


$n6 set Y_ 259
$n6 set Z_ 0.0
$ns initial_node_pos $n6 20
set n7 [$ns node]
$n7 set X_ 1084
$n7 set Y_ 268
$n7 set Z_ 0.0
$ns initial_node_pos $n7 20
$ns at .1 "$n7 set dest 300 300 50"
$ns at .3 "$n7 set dest 600 600 60"
#===================================
# Agents Definition
#===================================
#Setup a UDP connection
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set null1 [new Agent/Null]
$ns attach-agent $n7 $null1
$ns connect $udp0 $null1
$udp0 set packetSize_ 1500
#===================================
# Applications Definition
#===================================
#Setup a CBR Application over UDP connection
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 1000
$cbr0 set rate_ 1.0Mb
$cbr0 set random_ null
$ns at 1.0 "$cbr0 start"
$ns at 9.0 "$cbr0 stop"

Department of ISE, SCEM Page 37


COMPUTER NETWORK LABORATORY [18CSL57]

$ns at 10.0 “finish”


#===================================
# Termination
#===================================
#Define a 'finish' procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam 5.nam &
exit 0
}
{set i 0} {$i < $val(nn) } { incr i } {
$ns at $val(stop) "\$n$i reset"
}
$ns at $val(stop) "$ns nam-end-wireless $val(stop)"
$ns at $val(stop) "finish"
$ns at $val(stop) "puts \"done\" ; $ns halt"
$ns run

5.awk
BEGIN{
count1=0;
pack1=0;
time1=0;
}
{
if($1=="r"&& $3=="_7_"&& $4=="AGT")
{
count1++;
pack1= pack1+$8;
time1=$2;
}
}
END{
printf("The throughput from n0 to n7: %f Mbps\n",((count1*pack1*8)/(time1*1000000)));
}
Execution:
student@student-OptiPlex-330:~/ns2$ java -jar nsg2.1.jar
student@student-OptiPlex-330:~/ns2$ ns 5.tcl
student@student-OptiPlex-330:~/ns2$ gedit 5.awk
student@student-OptiPlex-330:~/ns2$ awk –f 5.awk 5.tr
The throughput from n0 to n7: 5.478273 Mbps

Department of ISE, SCEM Page 38


COMPUTER NETWORK LABORATORY [18CSL57]

5.5 Results:

Department of ISE, SCEM Page 39


COMPUTER NETWORK LABORATORY [18CSL57]

Nam file window:

5.6 Pre-experiment questions:


1. Expand GSM.
2. Difference between CDMA and GSM.
3. Why GSM is popular than CDMA?

5.7 Post experiment questions:


1. How to evaluate performance of GSM?
2. Expand AODV.
3. What is GOD in wireless network?
4. Why Agent trace should be ON?

Department of ISE, SCEM Page 40


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 06: CDMA performance

6.1 Experiment Details 6.5 Results


6.2 Softwares Required 6.6 Pre- Experiment Questions
6.3 Pre-Requisite 6.7 Post- Experiment Questions
6.4 Procedure

6.1 Experiment Details:


Implement and study the performance of CDMA on NS2/NS3 (Using stack called Call
net) or equivalent environment.

6.2 Softwares Required:

Operating System: Ubuntu 16.04 LTS


Simulator: NCTUNS

6.3 Pre-Requisite:
Basics of Networking, NCTUNS GUI working ,commands

Department of ISE, SCEM Page 41


COMPUTER NETWORK LABORATORY [18CSL57]

6.4 Procedure:

Steps in Draw (D) Mode:


Step 1: Select GPRS Mobile Phone, GPRS Base Station (BS), SGSN, Pseudo Switch, GGSN, Router and
Host. Place on the working place to make required topology.
Step 2: Connect GPRS BS SGSN Pseudo Switch GGSN Router Host using Point-to-Point link.
Step 3: provide a moving path for the GPRS Phone around the Base Station.
Step 4: Create a subnet between GPRS Phone and Base Station.

Steps in Edit(E) Mode:


Step 5: Go to N_Tools GPRS Network GPRS BS Assign frequency channels for Base Station.
Step 6: Double Click on GPRS Phone and open ‘Action’ window to attach the phone to BS at 1.00
Step7: Double Click on GPRS Phone and open ‘Application’ window and add the following command
to send packets to the receiver.
stcp –p 3000 -l 1024 1.0.2.1
Where 3000 is the port number, 1024 is the packet length and 1.0.2.1 is the receiving phone‘s IP
Address.

NOTE: Application Start time should be greater than attach time


Step 8: Double click on Host and open ‘Application’ window and add the following command to
receive the packets from the sender.
rtcp -p 3000 -l 1024
Step 9: Open the Node Editor of the Host and set Incoming__throughput statistics.
Step 10: Double Click on Router, Open “Node Editor” and doube click on MAC8023 layer. Enable the
log statistics and set Incoming_throughput and Outgoing_throughput.
Step 11: Run the Simulation in Run(R) Mode
Step 12: See the Output in Play Back (P) Mode.
Step13 : Go to G_Tools in menubar and select “Plot Graph” to plot the required Outgoing and
Incoming throughput.

Department of ISE, SCEM Page 42


COMPUTER NETWORK LABORATORY [18CSL57]

6.5 Results:

Department of ISE, SCEM Page 43


COMPUTER NETWORK LABORATORY [18CSL57]

6.6 Pre-experiment questions:


1. Expand CDMA.
2. What is the difference between CDMA and GSM?
3. Why NCTUNS simulator is used for experiment 6?

6.7 Post experiment questions


1. What is Mobile IP?
2. What is care of address?
3. What is wireless interface?
4. How to configure router?

Department of ISE, SCEM Page 44


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 07: CRC

7.1 Experiment Details 7.5 Results


7.2 Softwares Required 7.6 Pre- Experiment Questions
7.3 Pre-Requisite 7.7 Post- Experiment Questions
7.4 Procedure

7.1 Experiment Details:

Write a program for error detecting code using CRC-CCITT (16- bits).

7.2 Softwares Required:


Operating system: Ubuntu 16.04 LTS
Editor: JDK installed G-editor

7.3 Pre-Requisites:

Whenever digital data is stored or interfaced, data corruption might occur. Since the beginning of
computer science, developers have been thinking of ways to deal with this type of problem. For
serial data they came up with the solution to attach a parity bit to each sent byte. This simple
detection mechanism works if an odd number of bits in a byte changes, but an even number of false
bits in one byte will not be detected by the parity check. To overcome this problem developers have
searched for mathematical sound mechanisms to detect multiple false bits. The CRC calculation or
cyclic redundancy check was the result of this. Nowadays CRC calculations are used in all types of
communications. All packets sent over a network connection are checked with a CRC. Also each data
block on your hard disk has a CRC value attached to it. Modern computer world cannot do without
these CRC calculations. So let's see why they are so widely used. The answer is simple; they are
powerful, detect many types of errors and are extremely fast to calculate especially when dedicated
hardware chips are used.
The idea behind CRC calculation is to look at the data as one large binary number. This number is
divided by a certain value and the remainder of the calculation is called the CRC. Dividing in the CRC
calculation at first looks to cost a lot of computing power, but it can be performed very quickly if we
use a method similar to the one learned at school. We will as an example calculate the remainder for
the character 'm'—which is 1101101 in binary notation— by dividing it by 19 or 10011. Please note
that 19 is an odd number. This is necessary as we will see further on. Please refer to your
schoolbooks as the binary calculation method here is not very different from the decimal method
you learned when you were young. It might only look a little bit strange. Also notations differ
between countries, but the method is similar.

101
----------------
10011 / 1 1 0 1 1 0 1
10011| |
--------- –---| |
10000|
Department of ISE, SCEM Page 45
COMPUTER NETWORK LABORATORY [18CSL57]

00000|
-------------- |
100001
10011
-----------------
1 1 1 0 = 14 remainder

 The message bits are appended with c zero bits; this augmented message is the dividend
 A predetermined c+1-bit binary sequence, called the generator polynomial, is the divisor
 The checksum is the c-bit remainder that results from the division operation

With decimal calculations you can quickly check that 109 divided by 19 gives a quotient of 5 with 14
as the remainder. But what we also see in the scheme is that every bit extra to check only costs one
binary comparison and in 50% of the cases one binary subtraction. You can easily increase the
number of bits of the test data string—for example to 56 bits if we use our example value
"Lammert"—and the result can be calculated with 56 binary comparisons and an average of 28
binary subtractions. This can be implemented in hardware directly with only very few transistors
involved. Also software algorithms can be very efficient.
All of the CRC formulas you will encounter are simply checksum algorithms based on modulo-2
binary division where we ignore carry bits and in effect the subtraction will be equal to an exclusive
or operation. Though some differences exist in the specifics across different CRC formulas, the basic
mathematical process is always the same:
Table 1 lists some of the most commonly used generator polynomials for 16- and 32-bit CRCs.
Remember that the width of the divisor is always one bit wider than the remainder.
So, for example, you‘d use a 17-bit generator polynomial whenever a 16-bit checksum is required.

CRC - CCITT CRC – 16 CRC - 32


Checksum
16 bits 16 bits 32 bits
Width
Generator
10001000000100001 11000000000000101 100000100110000010001110110110111
Polynomial

International Standard CRC Polynomials

7.4 Procedure:

Source Code:

import java.io.*;
import java.util.Scanner;

class crc
{
public static void main(String args[])

Department of ISE, SCEM Page 46


COMPUTER NETWORK LABORATORY [18CSL57]

{
int i,j,n,g,check,flag,s,a;
int arr[]=new int[30],gen[]=new int[20],b[]=new int[20],q[]=new int[20],x[]=new int[20];
check = 0;
flag=0;
System.out.println("\t****** CYCLIC REDUNDANCY CHECK ******");
System.out.println("Transmitter side:");
System.out.println("Enter no. of data bits:");
Scanner in = new Scanner(System.in);
n= in.nextInt();
System.out.println(" Enter the data to be sent:");
for(i=0;i<n;i++)
arr[i]=in.nextInt();
System.out.println(" Enter the no. of divisor bits : ");
g = in.nextInt();
do
{
System.out.println("Enter the generator data");
for(j=0;j<g;j++)
gen[j] = in.nextInt();
}while(gen[0]!=1);
System.out.print("\t The divisor is: ");
for(j=0;j<g;j++)
System.out.print(gen[j]);
System.out.println();
a=n+(g-1);
System.out.print("\t The transmitter side data is: ");
for(i=0;i<j;i++)
arr[n+i] =0;
for(i=0;i<a;i++)
System.out.print(arr[i]);
System.out.println();
for(i=0;i<n;i++)
q[i]=arr[i];
for(i=0;i<n;i++)
{
if(arr[i]==0)
{
for(j=i;j<g;j++)
arr[j]=arr[j]^0;
}
else
{

Department of ISE, SCEM Page 47


COMPUTER NETWORK LABORATORY [18CSL57]

for(int k=0;k<17;k++)
{
arr[i+k]=arr[i+k]^gen[k];
}

}
}
System.out.print("\t The CRC is:");
for(i=n;i<a;i++)
System.out.print(arr[i]);
for(i=n;i<a;i++)
q[i]=arr[i];
//for(i=0;i<a;i++)
//System.out.print(q[i]);
System.out.println();
System.out.println(" Reciever side:");
System.out.println(" Enter no. of data bits recieved:");
n=in.nextInt();
System.out.println("Enter the data recieved");
for(i=0;i<n;i++)
arr[i]=in.nextInt();
for(i=n;i<a;i++)
for(j=g-1;j<0;j--)
arr[i]=q[j];
System.out.print(" The reciever side data is: ");
for(i=0;i<a;i++)
System.out.print(arr[i]);
for(i=0;i<n;i++)
q[i]=arr[i];
for(i=0;i<n;i++)
{
if(arr[i]==0)
{
for(j=i;j<g+i;j++)
arr[j]=arr[j]^0;
}
else
{
for(int k=0;k<17;k++)
{
arr[i+k]=arr[i+k]^gen[k];
}
}

Department of ISE, SCEM Page 48


COMPUTER NETWORK LABORATORY [18CSL57]

}
System.out.println();
System.out.print(" The CRC at the reciever is:");
for(i=n;i<a;i++)
System.out.print(arr[i]);
for(i=n;i<a;i++)
{
if(arr[i]==1)
{
flag=1;
break;
}
else
check=0;
}
System.out.println();
System.out.print(" Result of CRC error detection is: ");
if(flag==0 && check==0)
System.out.println(" Data is accepted successfully");
else
System.out.println(" Resend the data again");
}
}

Department of ISE, SCEM Page 49


COMPUTER NETWORK LABORATORY [18CSL57]

7.5 Results:

7.6 Pre-experiment questions:


1. Expand CRC.
2. What is checksum?
3. What is the role of data link layer?

7.7 Post experiment questions:


1. How find error in data stream using CRC?
2. Why remainder at Receiver should be zero?
3. What is application of CRC?
4. Expand CCITT.

Department of ISE, SCEM Page 50


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 08: BelmanFord Routing algorithm

8.1 Experiment Details 8.5 Results


8.2 Softwares Required 8.6 Pre- Experiment Questions
8.3 Pre-Requisite 8.7 Post- Experiment Questions
8.4 Procedure

8.1 Experiment Details:

Write a program to find the shortest path between vertices using bellman-ford algorithm

8.2 Softwares Required:


Operating system: Ubuntu 16.04 LTS
Editor: JDK installed G-editor

8.3 Pre-Requisite:
Distance Vector Algorithm is a decentralized routing algorithm that requires that each router simply
inform its neighbours of its routing table. For each network path, the receiving routers pick the
neighbour advertising the lowest cost, then add this entry into its routing table for re-advertisement.
To find the shortest path, Distance Vector Algorithm is based on one of two basic algorithms:
Bellman-Ford and Dijkstra algorithms. Routers that use this algorithm have to maintain the distance
tables (which is a one- dimension array -- "a vector"), which tell the distances and shortest path to
sending packets to each node in the network. The information in the distance table is always up date
by exchanging information with the neighbouring nodes. The number of data in the table equals to
that of all nodes in networks (excluded itself). The columns of table represent the directly attached
neighbours whereas the rows represent all destinations in the network. Each data contains the path
for sending packets to each destination in the network and distance/or time to transmit on that path
(we call this as "cost"). The measurements in this algorithm are the number of hops, latency, the
number of outgoing packets, etc. The Bellman–Ford algorithm is an algorithm that computes
shortest paths from a single source vertex to all of the other vertices in a weighted digraph. It is
slower than Dijkstra's algorithm for the same problem, but more versatile, as it is capable of
handling graphs in which some of the edge weights are negative numbers. Negative edge weights
are found in various applications of graphs, hence the usefulness of this algorithm. If a graph
contains a "negative cycle" (i.e. a cycle whose edges sum to a negative value) that is reachable from
the source, then there is no cheapest path: any path that has a point on the negative cycle can be
made cheaper by one more walk around the negative cycle. In such a case, the Bellman–Ford
algorithm can detect negative cycles and report their existence.

Department of ISE, SCEM Page 51


COMPUTER NETWORK LABORATORY [18CSL57]

8.4 Procedure:
Source Code:

import java.util.Scanner;
public class BellmanFord
{
private int distances[];
private int numberofvertices;
public static final int MAX_VALUE = 999;
public BellmanFord(int numberofvertices)
{
this.numberofvertices= numberofvertices;
distances = new int[numberofvertices+1];
}
public void BellmanFordEvaluation(int source,int adjacencymatrix[][])
{
for(int node=1;node<=numberofvertices;node++)
{
distances[node]=MAX_VALUE;
}
distances[source]=0;
for(int node=1;node<=numberofvertices-1;node++)
{
for(int sourcenode=1;sourcenode<=numberofvertices;sourcenode++)
{
for(int destinationnode=1;destinationnode<=numberofvertices;
destinationnode++)
{
if(adjacencymatrix[sourcenode][destinationnode]!=MAX_VALUE)
{
if(distances[destinationnode]>distances[sourcenode] +
adjacencymatrix[sourcenode][destinationnode])
distances[destinationnode]=distances[sourcenode]+adjacencymatrix[sourcenode]
[destinationnode];
}
}
}
}
for (int sourcenode=1;sourcenode<=numberofvertices;sourcenode++)
{
for(int destinationnode=1;destinationnode<=numberofvertices;
destinationnode++)
{
if(adjacencymatrix[sourcenode][destinationnode]!=MAX_VALUE)
{
if(distances[destinationnode]>distances[sourcenode] +
adjacencymatrix[sourcenode][destinationnode])
System.out.println("The graph contains negative edge cycle");

Department of ISE, SCEM Page 52


COMPUTER NETWORK LABORATORY [18CSL57]

}
}
}
for(int vertex=1;vertex<=numberofvertices;vertex++)
{
System.out.println("Distance of source "+source+" to "+vertex+" is
"+distances[vertex]);
}
}
public static void main(String args[])
{
int numberofvertices=0;
int source,destination;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of vertices");
numberofvertices=scanner.nextInt();
int adjacencymatrix[][]= new int[numberofvertices+1][numberofvertices+1];
System.out.println("Enter the adjacency matrix");
for(int sourcenode=1;sourcenode<=numberofvertices;sourcenode++)
{
for(int destinationnode=1;destinationnode<=numberofvertices;
destinationnode++)
{
adjacencymatrix[sourcenode][destinationnode]=scanner.nextInt();
if(sourcenode==destinationnode)
{
adjacencymatrix[sourcenode][destinationnode]=0;
continue;
}
if(adjacencymatrix[sourcenode][destinationnode]==0)
{
adjacencymatrix[sourcenode][destinationnode]=MAX_VALUE;
}
}
}
System.out.println("Enter the source vertex");
source=scanner.nextInt();
BellmanFord bellmanford = new BellmanFord(numberofvertices);
bellmanford.BellmanFordEvaluation(source,adjacencymatrix);
}
}

Department of ISE, SCEM Page 53


COMPUTER NETWORK LABORATORY [18CSL57]

8.5 Results:

8.6 Pre-experiment questions:


1. What is routing?
2. Which layer will work for routing?
3. What is IP address?

8.7 Post experiment questions:


1. What is the limitation of distance vector routing?
2. What is negative edge cycle?
3. Define dynamic routing.
4. What is adjacency matrix?

Department of ISE, SCEM Page 54


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 09: TCP Socket

9.1 Experiment Details 9.5 Results


9.2 Softwares Required 9.6 Pre- Experiment Questions
9.3 Pre-Requisite 9.7 Post- Experiment Questions
9.4 Procedure

9.1 Experiment Details:


Using TCP/IP sockets, write a client – server program to make the client send the file name
and to make the server send back the contents of the requested file if present.

9.2 Softwares Required:


Operating system: Ubuntu 16.04 LTS

Editor: jdk installed g-editor

9.3 Pre-requisite:
Socket is an interface which enables the client and the server to communicate and pass on
information from one another. Sockets provide the communication mechanism between two
computers using TCP. A client program creates a socket on its end of the communication and
attempts to connect that socket to a server. When the connection is made, the server creates a
socket object on its end of the communication. The client and the server can now communicate by
writing to and reading from the socket.

9.4 Procedure:
Source Code:

Server Program:

import java.net.*;
import java.io.*;
public class Cserver
{
public static void main(String args[]) throws Exception
{
ServerSocket sersock = new ServerSocket(4000);
System.out.println("Server ready for connection ");
Socket sock = sersock.accept();
System.out.println("Connection is successful and waiting for chatting");
InputStream istream = sock.getInputStream();
BufferedReader fileRead = new BufferedReader (new InputStreamReader(istream));
String fname = fileRead.readLine();
BufferedReader contentRead = new BufferedReader (new FileReader(fname));

Department of ISE, SCEM Page 55


COMPUTER NETWORK LABORATORY [18CSL57]

OutputStream ostream = sock.getOutputStream();


PrintWriter pwrite = new PrintWriter (ostream,true);
String str;
while((str=contentRead.readLine())!=null)
{
pwrite.println(str);
}
sock.close();
sersock.close();
pwrite.close();
fileRead.close();
contentRead.close();
}
}

Client Program:

import java.io.*;
import java.net.*;

public class Client


{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1",4000);
System.out.println("Enter the file name");
BufferedReader keyRead = new BufferedReader(new InputStreamReader(System.in));
String fname = keyRead.readLine();
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream,true);
pwrite.println(fname);
InputStream istream = sock.getInputStream();
BufferedReader socketRead = new BufferedReader(new InputStreamReader
(istream));
String str;
while((str=socketRead.readLine())!=null)
{
System.out.println(str);
}
pwrite.close();
socketRead.close();
keyRead.close();
}
}

Department of ISE, SCEM Page 56


COMPUTER NETWORK LABORATORY [18CSL57]

9.5 Results:

Server Side

Client Side:

Department of ISE, SCEM Page 57


COMPUTER NETWORK LABORATORY [18CSL57]

9.6 Pre-experiment questions:


1. What is Socket?
2. What is IPC?
3. How many types of Socket are there?
4. How client communicates to server?

9.7 Post experiment questions:


1. What is the use of bufferedreader?
2. How read and write operations takes place using socket?
3. What is ephemeral port?
4. Expand INET.

Department of ISE, SCEM Page 58


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 10: Datagram socket

10.1 Experiment Details 10.5 Results


10.2 Softwares Required 10.6 Pre- Experiment Questions
10.3 Pre-Requisite 10.7 Post- Experiment Questions
10.4 Procedure

10.1 Experiment Details:


Write a program on datagram socket for client/server to display the messages on client side,
typed at the server side.

10.2 Softwares Required:


Operating system: Ubuntu 16.04 LTS
Editor: jdk installed g-editor

10.3 Pre-requisite:

A datagram socket is the one for sending or receiving point for a packet delivery service. Each packet
sent or received on a datagram socket is individually addressed and routed. Multiple packets sent
from one machine to another may be routed differently, and may arrive in any order.

10.4 Procedure:
Source Code:

import java.net.*;
class WriteServer
{
public static int serverPort = 1150;
public static int clientPort = 1160;
public static int buffer_size =1024;
public static DatagramSocket ds;
public static byte buffer[] = new byte[buffer_size];
public static void TheServer() throws Exception
{
int pos=0;
while(true)
{
int c = System.in.read();
switch(c)
{
case -1: System.out.println("Server Quits");
return;
case '\r':break;

Department of ISE, SCEM Page 59


COMPUTER NETWORK LABORATORY [18CSL57]

case '\n':ds.send(new
DatagramPacket(buffer,pos,InetAddress.getLocalHost(),clientPort));
pos=0;
break;
default:buffer[pos++]=(byte) c;
}
}
}
public static void TheClient() throws Exception
{
while(true)
{
DatagramPacket p = new DatagramPacket(buffer,buffer.length);
ds.receive(p);
System.out.println(new String (p.getData(),0,p.getLength()));
}
}
public static void main(String args[]) throws Exception
{
if(args.length==1)
{
ds = new DatagramSocket(serverPort);
TheServer();
}
else
{
ds = new DatagramSocket(clientPort);
TheClient();
}
}
}

Department of ISE, SCEM Page 60


COMPUTER NETWORK LABORATORY [18CSL57]

10.5 Results:

10.6 Pre-experiment questions:


1. What is datagram?
2. Expand UDP.
3. Why UDP is connectionless?

10.7 Post experiment questions:


1. Define datagram socket.
2. What is the use of datagram socket class?
3. Why datagram packet class is used?

Department of ISE, SCEM Page 61


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 11: RSA algorithm

11.1 Experiment Details 11.5 Results


11.2 Softwares Required 11.6 Pre- Experiment Questions
11.3 Pre-Requisite 11.7 Post- Experiment Questions
11.4 Procedure

11.1 Experiment Details:

Write a program for simple RSA algorithm to encrypt and decrypt the data.

11.2 Softwares Required:


Operating system: Ubuntu 16.04 LTS
Editor: jdk installed g-editor

11.3 Pre-Requisite:

RSA is an example of public key cryptography. It was developed by Rivest, Shamir and Adelman. The
RSA algorithm can be used for both public key encryption and digital signatures. Its security is based
on the difficulty of factoring large integers. The RSA algorithm's efficiency requires a fast method for
performing the modular exponentiation operation. A less efficient, conventional method includes
raising a number (the input) to a power (the secret or public key of the algorithm, denoted e and d,
respectively) and taking the remainder of the division with N. A straight-forward implementation
performs these two steps of the operation sequentially: first, raise it to the power and second, apply
modulo. The RSA algorithm comprises of three steps, which are depicted below:

Key Generation Algorithm


1. Generate two large random primes, p and q, of approximately equal size such that their product n
= p*q
2. Compute n = p*q and Euler‘s totient function (φ) phi(n) = (p-1)(q-1).
3. Choose an integer e, 1 < e < phi, such that gcd(e, phi) = 1.
4. Compute the secret exponent d, 1 < d < phi, such that e*d ≡ 1 (mod phi).
5. The public key is (e, n) and the private key is (d, n). The values of p, q, and phi should also be kept
secret.

Encryption
Sender A does the following:-
1. Using the public key (e,n)
2. Represents the plaintext message as a positive integer M
3. Computes the cipher text C = M^e mod n. 4. Sends the cipher text C to B (Receiver).

Decryption
Recipient B does the following:-
1. Uses his private key (d, n) to compute M = C^d mod n.
2. Extracts the plaintext from the integer representative m.

Department of ISE, SCEM Page 62


COMPUTER NETWORK LABORATORY [18CSL57]

11.4 Procedure :

Source Code:
import java.util.*;
import java.io.*;
class rsa
{
static int mult(int x,int y,int n)
{
int k=1;
int j;
for (j=1; j<=y; j++)
k = (k * x) % n;
return ( int) k;
}
public static void main (String arg[])throws Exception
{
Scanner s=new Scanner(System.in);
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
String msg1;
int pt[]=new int[100];
int ct[]=new int[100];
int a,b, n, d, e,Z, p, q, i,temp,et;
System.out.println("Enter prime No.s p,q :");
p=s.nextInt();
q=s.nextInt();
n = p*q;
Z=(p-1)*(q-1);
System.out.println("\nSelect e value:");
e=s.nextInt();
System.out.printf("Enter message : ");
msg1=br.readLine();
char msg[]=msg1.toCharArray();
for(i=0;i<msg.length;i++)
pt[i]=msg[i];
for(d=1;d<Z;++d)
if(((e*d)%Z)==1) break;
System.out.println("p="+""+p+"\tq="+q+"\tn="+n+"\tz="+Z+"\te="+e+"
\td="+d);
System.out.println("\nCipher Text = ");
for(i=0; i<msg.length; i++)
ct[i] = mult(pt[i], e,n);
for(i=0; i<msg.length; i++)
System.out.print("\t"+ct[i]);
System.out.println("\nPlain Text = ");
for(i=0; i<msg.length; i++)
pt[i] = mult(ct[i], d,n) ;
for(i=0; i<msg.length; i++)

Department of ISE, SCEM Page 63


COMPUTER NETWORK LABORATORY [18CSL57]

System.out.print((char)pt[i]);
}
}

11.5 Results:

11.6 Pre-experiment questions:


1. What is cryptography?
2. What is plaintext?
3. What is key?
4. What is encryption?

11.7 Post experiment questions:


1. What is Ciphertext?
2. Why Euler totient is used?
3. Why prime nos are used in RSA?
4. How to get the public and private keys?

Department of ISE, SCEM Page 64


COMPUTER NETWORK LABORATORY [18CSL57]

EXPERIMENT No. 12: Congestion control

12.1 Experiment Details 12.5 Results


12.2 Softwares Required 12.6 Pre- Experiment Questions
12.3 Pre-Requisite 12.7 Post- Experiment Questions
12.4 Procedure

12.1 Experiment Details:

Write a program for congestion control using leaky bucket algorithm.

12.2 Softwares Required:


Operating system: Ubuntu 16.04 LTS
Editor: jdk installed g-editor

12.3 Pre-requisite:
The main concept of the leaky bucket algorithm is that the output data flow remains constant
despite the variant input traffic, such as the water flow in a bucket with a small hole at the bottom.
In case the bucket contains water (or packets) then the output flow follows a constant rate, while if
the bucket is full any additional load will be lost because of spill over. In a similar way if the bucket is
empty the output will be zero. From network perspective, leaky bucket consists of a finite queue
(bucket) where all the incoming packets are stored in case there is space in the queue, otherwise the
packets are discarded. In order to regulate the output flow, leaky bucket transmits one packet from
the queue in a fixed time (e.g. at every clock tick). In the following figure we can notice the main
rationale of leaky bucket algorithm, for both the two approaches (e.g. leaky bucket with water (a)
and with packets (b)).

Department of ISE, SCEM Page 65


COMPUTER NETWORK LABORATORY [18CSL57]

While leaky bucket eliminates completely bursty traffic by regulating the incoming data flow its
main drawback is that it drops packets if the bucket is full. Also, it doesn‘t take into account the idle
process of the sender which means that if the host doesn‘t transmit data for some time the bucket
becomes empty without permitting the transmission of any packet.

12.4 Procedure:
Source Code:

import java.io.*;
import java.util.Scanner;
class Leaky
{
public static int min(int x,int y)
{
if(x<y)
return x;
else
return y;
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int drop=0,mini,n,cap,count=0,i;

Department of ISE, SCEM Page 66


COMPUTER NETWORK LABORATORY [18CSL57]

int inp[ ]= new int[25];


int process;
System.out.println("Enter The Bucket Size\n");
cap=sc.nextInt();
System.out.println("Enter The Output Rate\n");
process=sc.nextInt();
System.out.println("Enter the number of packets\n");
n=sc.nextInt();
System.out.println("Enter the size of packets to be sent:");
for(i=0;i<n;i++)
{
inp[i]=sc.nextInt();
}
System.out.println("\nSecond|Packet Recieved|Packet Sent|PacketLeft|Packet
Dropped|\n");
System.out.println("--------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
count+=inp[i];
if(count>cap)
{
drop=count-cap;
count=cap;
}
System.out.print(i+1);
System.out.print("\t" +inp[i]);
mini=min(count,process);
System.out.print("\t\t" + mini);
count=count-mini;
System.out.print("\t\t" +count);
System.out.println("\t\t"+ drop);
drop=0;
}
for(;count!=0;i++)
{
if(count>cap)
{
drop=count-cap;
count=cap;
}
System.out.print(i+1);
System.out.print("\t0");
mini=min(count,process);
System.out.print("\t\t" +mini);
count=count-mini;
System.out.print("\t\t" +count);
System.out.println("\t\t" +drop);
}
}

Department of ISE, SCEM Page 67


COMPUTER NETWORK LABORATORY [18CSL57]

12.5 Results:

12.6 Pre-experiment questions:


1. What is congestion?
2. What is Policing?
3. What is packet?
4. Why leaky bucket concept?

12.7 Post experiment questions:


1. What is traffic shaping?
2. How congestion is controlled?
3. What is LCT?
4. Describe the applications of leaky bucket?

Department of ISE, SCEM Page 68

You might also like