Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 42

18MCA3PCNW: Computer Networks USN: 1BM19MCA15

INTRODUCTION
Ubuntu is a Linux distribution based on Debian and mostly composed of free and open-
source software. Ubuntu is officially released in three editions: Desktop, Server, and Core for
Internet of things devices and robots. All the editions can run on the computer alone, or in a
virtual machine.
NS2 is an open-source simulation tool that runs on Linux. It is a discreet event simulator
targeted at networking research and provides substantial support for simulation of routing,
multicast protocols and IP protocols, such as UDP, TCP, RTP and SRM over wired and
wireless (local and satellite) networks.

Installing Ubuntu in a VM on Windows


 Open VMware Player
 Click on “Create a New Virtual Machine”
 Click on “Browse” to select installer disc image
 After selecting the disc image click “Open” Click “Next”
 Enter all the details and click “Next”
 Supply machine name and Click “Next”
 Specify disk capacity and Click “Next”
 Click “Finish”
 Now installation procedure will start
 Now Ubuntu installation procedure will start
 After downloading VMware tools your Ubuntu desktop will get displayed.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 1


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

1) 1. Implement the working of User Datagram Protocol (UDP)traffic between two nodes with
Constant Bit Rate (CBR)Create two nodes which are connected through a point-topoint link with a
CBR traffic using the UDP. Set and display the details of the following parameters and identity the
same in the trace file:
a. Duplex Link
b. Packet size
c. Bandwidth of the link
d. Time of Simulation
#Experiment for sending UDP traffic.
# nodes are connected as n1-->n2

# Procedures used in the code.


proc finish { } { global ns nf tf
file_namtr
$ns flush-trace close
$nf close $tf exit 0
}
set file_namtr "simpleudp.nam" set
file_pkttr "simpleudp.tr" # create the ns
object and trace files set ns [ new Simulator
] set nf [ open $file_namtr w ] $ns
namtrace-all $nf set tf [ open $file_pkttr w ]
$ns trace-all $tf
# create the nodes and links for traffic set n1
[$ns node] set n2 [$ns node]

$n1 color "red"


$n2 color "blue"
$n1 label "sender"
$n2 label "receiver"
$ns duplex-link $n1 $n2 1Mb 100ms DropTail

DEPT. OF COMPUTER APPLICATIONS, BMSCE 2


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

# define node, and links colors for graph animation


$ns color 1 "green"

# Generate UDP traffic set udps


[new Agent/UDP] set udpr [new
Agent/Null]
$ns attach-agent $n1 $udps
$ns attach-agent $n2 $udpr

#Setup a CBR over UDP connection set cbr


[new Application/Traffic/CBR]
$cbr set packet_size_ 1000
$cbr set interval_ 50ms

$cbr attach-agent $udps


$ns connect $udps $udpr

#Schedule events for the CBR and FTP agents


$ns at 0.0 "$cbr start"
$ns at 1.0 "$cbr stop"

#Print CBR packet size and interval puts "CBR Packet


Size = [$cbr set packet_size_]" puts "CBR Rate = [$cbr
set rate_]"

puts "CBR Interval = [$cbr set interval_]" puts "CBR Max


Pkts = [$cbr set maxpkts_]" puts "CBR Random Behaviour =
[$cbr set random_]"

DEPT. OF COMPUTER APPLICATIONS, BMSCE 3


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

$ns at 2.0 "finish"


$ns run
#----------------------

DEPT. OF COMPUTER APPLICATIONS, BMSCE 4


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

DEPT. OF COMPUTER APPLICATIONS, BMSCE 5


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Trace File Explanation:


* Event gives you four possible symbols ‘+’ ‘-‘ ‘r’ ‘d’. These four symbols correspond
respectively to enqueued, dequeued, received and dropped.
* Time field gives the time at which the event occurs.
* From node field gives you the input node of the link at which the event occurs.
* To node field gives you the output node at which the event occurs.
* Packet type field shows the information about the packet type. i.e. whether the packet is
UDP or TCP.
* Packet size field gives the packet size.
* Flag field give information about some flags.
* Fid field is the flow id(fid) for IPv6 that a user can set for each flow in a tcl script. It is
also used for specifying the color of flow in NAM display.
* The ninth field is the source address.
* The tenth field is the destination address.
* The eleventh field is the network layer protocol’s packet sequence number.
* The last field shows the unique id of packet.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 6


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Program 2 : To implement 3nodes


#Experiment for sending UDP traffic.
# nodes are connected as n1-->n2

# Procedures used in the code.


proc finish { } {

global ns nf tf file_namtr $ns


flush-trace close $nf close $tf
exit 0
}

set file_namtr "simple.nam" set


file_pkttr "simple.tr"

# create the ns object and trace files set ns


[ new Simulator ] set nf [ open $file_namtr
w ] $ns namtrace-all $nf set tf [ open
$file_pkttr w ]
$ns trace-all $tf

# create the nodes and links for traffic set n1


[$ns node]

set n2 [$ns node] set n3


[$ns node] $n1 color "red"
$n2 color "blue"

DEPT. OF COMPUTER APPLICATIONS, BMSCE 7


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

$n3 color "green"


$n1 label "sender"
$n2 label "receiver"
$n3 label "router"

$ns duplex-link $n1 $n2 1Mb 100ms DropTail $ns


duplex-link $n2 $n3 5Mb 500ms DropTail

# define node, and links colors for graph animation


$ns color 1 "green"

# Generate UDP traffic set udps


[new Agent/UDP] set udpr [new
Agent/Null] set udpro [new
Agent/UDP] $ns attach-agent $n1
$udps $ns attach-agent $n2 $udpr
$ns attach-agent $n3 $udpro

#Setup a CBR over UDP connection set cbr


[new Application/Traffic/CBR] $cbr set
packet_size_ 10000

$cbr set interval_ 500ms

$cbr attach-agent $udps


$ns connect $udps $udpr

DEPT. OF COMPUTER APPLICATIONS, BMSCE 8


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

$ns connect $udpr $udpro

#Schedule events for the CBR and FTP agents


$ns at 0.0 "$cbr start"
$ns at 1.0 "$cbr stop"

#Print CBR packet size and interval puts "CBR Packet Size =
[$cbr set packet_size_]" puts "CBR Rate = [$cbr set rate_]"
puts "CBR Interval = [$cbr set interval_]" puts "CBR Max
Pkts = [$cbr set maxpkts_]" puts "CBR Random Behaviour
= [$cbr set random_]"

$ns at 2.0 "finish"


$ns run
#---------------------

DEPT. OF COMPUTER APPLICATIONS, BMSCE 9


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

DEPT. OF COMPUTER APPLICATIONS, BMSCE 10


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Trace File Explanation:


 Event gives you four possible symbols ‘+’ ‘-‘ ‘r’ ‘d’. These four symbols
correspond respectively to enqueued, dequeued, received and dropped.
 Time field gives the time at which the event occurs.
 From node field gives you the input node of the link at which the event occurs.
 To node field gives you the output node at which the event occurs.
 Packet type field shows the information about the packet type. i.e. whether
the packet is
UDP or TCP.
 Packet size field gives the packet size.
 Flag field give information about some flags.
 Fid field is the flow id(fid) for IPv6 that a user can set for each flow in a tcl
script.
 It is also used for specifying the color of flow in NAM display.
 The ninth field is the source address.
 The tenth field is the destination address.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 11


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

 The eleventh field is the network layer protocol’s packet sequence number.
 The last field shows the unique id of packet.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 12


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

PROGRAM 3: Consider a scenario with consists of 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.

#Create a simulator object set ns


[new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red
#Open the NAM trace file
set nf [open q1.nam w]
$ns namtrace-all
$nf set nt [open q1.tr w]
$ns trace-all $nt
#Define a 'finish' procedure proc
finish { } { global ns nf nt
#exec q1.nam & $ns
flush-trace close $nf
close $nt 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 6Mb 20ms DropTail


#$ns duplex-link $n1 $n2 6Mb 10ms DropTail

DEPT. OF COMPUTER APPLICATIONS, BMSCE 13


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

#$ns duplex-link $n2 $n3 4Mb 5ms DropTail


#$ns duplex-link $n0 $n2 4Mb 10ms DropTail #$ns
duplex-link $n1 $n2 4Mb 10ms DropTail
#$ns duplex-link $n2 $n3 4Mb 10ms DropTail
$ns duplex-link $n0 $n2 2Mb 10ms DropTail $ns
duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1.7Mb 20ms DropTail
#Set Queue Size of link (n2-n3) to 10
$ns queue-limit $n2 $n3 10
#$ns queue-limit $n1 $n2 10
#Give node position (for NAM)
$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 link (n2-n3). (for NAM)
$ns duplex-link-op $n2 $n3 queuePos 1.5
#Setup a TCP connection set tcp [new
Agent/TCP] $tcp set class_ 2 $ns attach-agent
$n0 $tcp set sink [new Agent/TCPSink] $ns
attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
#Setup a FTP over TCP connection set ftp
[new Application/FTP]
$ftp attach-agent $tcp

DEPT. OF COMPUTER APPLICATIONS, BMSCE 14


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

$ftp set type_ FTP #Setup a UDP


connection set udp [new
Agent/UDP] $ns attach-agent
$n1 $udp set null [new
Agent/Null]
$ns attach-agent $n3 $null
$ns connect $udp $null
$udp set fid_ 2
#Setup a CBR over UDP connection set cbr
[new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1mb
$cbr set random_ false
#Schedule events for the CBR and FTP agents
$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"
#Detach tcp and sink agents (not really necessary)
$ns at 4.5 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink" #Call the finish
procedure after 5 seconds of simulation time
$ns at 5.0 "finish"
#Print CBR packet size and interval puts "CBR packet
size = [$cbr set packet_size_]" puts "CBR interval =
[$cbr set interval_]"
DEPT. OF COMPUTER APPLICATIONS, BMSCE 15
18MCA3PCNW: Computer Networks USN: 1BM19MCA15

#Run the simulation


$ns run

DEPT. OF COMPUTER APPLICATIONS, BMSCE 16


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Trace File Explanation:


 Event gives you four possible symbols ‘+’ ‘-‘ ‘r’ ‘d’. These four symbols
correspond respectively to enqueued, dequeued, received and dropped.
 Time field gives the time at which the event occurs.
 From node field gives you the input node of the link at which the event occurs.
 To node field gives you the output node at which the event occurs.
 Packet type field shows the information about the packet type. i.e. whether the
packet is
UDP or TCP.
 Packet size field gives the packet size.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 17


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

 Flag field give information about some flags.


 Fid field is the flow id(fid) for IPv6 that a user can set for each flow in a tcl
script. It is also used for specifying the color of flow in NAM display.
 The ninth field is the source address.
 The tenth field is the destination address.
 The eleventh field is the network layer protocol’s packet sequence number.
 The last field shows the unique id of packet.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 18


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Program 4:
Implement the ping application for a 6 nodes communication. The communication set
is as follows:
• Build topology shown in the figure 1
• Fix the node positions
• Let the bandwidth (BW) of all the links except the one between C and D
be 1 Mbps
• Let the link bandwidth between C and D be 1.5 Mbps
• Propagation delay of all links be 1ms
• Let the queue size be 3
•Packet size be 750 bytes
• Send Ping traffic from A to E one packet every 7 ms
• Send UDP traffic from B to F one packet every 7ms

DEPT. OF COMPUTER APPLICATIONS, BMSCE 19


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Program 4:
#Create a simulator object
set ns [new Simulator]
#Define different colors for data flows (for NAM)
$ns color 1 Red
#$ns color 2 Blue
#Open the NAM trace file
set nf [open pingn.nam w]
$ns namtrace-all $nf
set nt [open pingn.tr w]
$ns trace-all $nt
#Define a 'finish' procedure
proc finish { } {
global ns nf nt
$ns flush-trace
close $nf
close $nt
exec xgraph file11.dat
exec xgraph PACKETS DROPPED -x TIME -y
exit 0
}
#Create 6 Nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
$ns duplex-link $n0 $n2 1Mb 1ms DropTail
$ns duplex-link $n1 $n2 1Mb 1ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 1ms DropTail
$ns duplex-link $n3 $n4 1Mb 1ms DropTail
$ns duplex-link $n3 $n5 1Mb 1ms DropTail
#Set Queue Size of link (n1-n2) to 3
$ns queue-limit $n0 $n2 3
$ns queue-limit $n1 $n2 3
$ns queue-limit $n3 $n4 3

DEPT. OF COMPUTER APPLICATIONS, BMSCE 20


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

$ns queue-limit $n3 $n5 3


#Give node position (for NAM)
$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-op $n4 $n3 orient left-down
$ns duplex-link-op $n5 $n3 orient left-up
#Monitor the queue for link (n2-n3). (for NAM)
$ns duplex-link-op $n0 $n2 queuePos 1.5
$ns duplex-link-op $n1 $n2 queuePos 1.5
$ns duplex-link-op $n3 $n4 queuePos 1.5
$ns duplex-link-op $n3 $n5 queuePos 1.5
#Define a 'recv' function for the class 'Agent/Ping'
Agent/Ping instproc recv {from rtt} {
$self instvar node_
puts "node [$node_ id] received ping answer from \
$from with round-trip-time $rtt ms."
}

#Create two ping agents and attach them to the nodes n0,n2,n3 and n4
set p0 [new Agent/Ping]
$ns attach-agent $n0 $p0

#set p2 [new Agent/Ping]


#$ns attach-agent $n2 $p2

#set p3 [new Agent/Ping]


#$ns attach-agent $n3 $p3

set p4 [new Agent/Ping]


$ns attach-agent $n4 $p4

#Connect the two agents


$ns connect $p0 $p4
#$ns connect $p1 $p2
#$ns connect $p2 $p3

DEPT. OF COMPUTER APPLICATIONS, BMSCE 21


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

#Schedule events
$ns at 0.2 "$p0 send"
$ns at 0.4 "$p0 send"
$ns at 0.6 "$p0 send"
$ns at 0.8 "$p0 send"
$ns at 1.0 "$p0 send"
$ns at 1.2 "$p0 send"
$ns at 1.4 "$p0 send"
$ns at 1.6 "$p0 send"
$ns at 2.0 "$p0 send"
$ns at 2.5 "$p0 send"
$ns at 3.5 "$p0 send"
#Generate UDP traffic
set udps [new Agent/UDP]
set udpi [new Agent/UDP]
set udpr [new Agent/Null]
$ns attach-agent $n0 $udps
$ns attach-agent $n4 $udpr
$udps set fid_ 1
#Setup a CBR over UDP connection
set cbr [new Application/Traffic/CBR]
$cbr set packet_size_ 4000
$cbr set interval_ 7ms
$cbr attach-agent $udps
$ns connect $udps $udpr
#Schedule events for the CBR and FTP agents
$ns at 1.1 "$cbr start"
$ns at 3.0 "$cbr stop"
#Print CBR packet size and interval
puts "CBR Packet Size = [$cbr set packet_size_]"
puts "CBR Rate = [$cbr set rate_]"
puts "CBR Interval = [$cbr set interval_]"
puts "CBR Max Pkts = [$cbr set maxpkts_]"
puts "CBR Random Behaviour = [$cbr set random_]"

$ns at 4.0 "finish"


$ns run

DEPT. OF COMPUTER APPLICATIONS, BMSCE 22


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Awk File
BEGIN{
pingDrop=0;
time=0;

}
{
if( $1 == "d")
{
time= $2;
printf(" %d %f \n",pingDrop,time);
pingDrop++;
}
}
END {
printf("");
}

DEPT. OF COMPUTER APPLICATIONS, BMSCE 23


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

DEPT. OF COMPUTER APPLICATIONS, BMSCE 24


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Trace File Explanation:


 Event gives you four possible symbols ‘+’ ‘-‘ ‘r’ ‘d’. These four symbols
correspond respectively to enqueued, dequeued, received and dropped.
 Time field gives the time at which the event occurs.
 From node field gives you the input node of the link at which the event occurs.
 To node field gives you the output node at which the event occurs.
 Packet type field shows the information about the packet type. i.e. whether the
packet is
UDP or TCP.
 Packet size field gives the packet size.
 Flag field give information about some flags.
 Fid field is the flow id (fid) for IPv6 that a user can set for each flow in a tcl
script. It is also used for specifying the colour of flow in NAM display.
 The ninth field is the source address.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 25


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

 The tenth field is the destination address.


 The eleventh field is the network layer protocol’s packet sequence number.
 The last field shows the unique id of packet.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 26


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Program 5
Simulate the communication between the mobile nodes using wireless
medium adapting the Ad Hoc Distance Vector (AODV) protocol in ns-2.

#Demonstrate the working of wireless networks for a given network scenario


#Sample Code:
#simple-wireless.tcl
# A simple example for wireless simulation
# Define options
#=====================================================================
=
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) 3 ;# number of mobilenodes
set val(rp) DSDV ;# routing protocol
set val(x) 500
set val(y) 500
# Main Program#
#=====================================================================
=
#
# Initialize Global Variables
#
set ns_ [new Simulator]
set tracefd [open wireless.tr w]
$ns_ trace-all $tracefd
set namtrace [open wireless.nam w] ;# for nam tracing
$ns_ namtrace-all-wireless $namtrace $val(x) $val(y)
# set up topography object
set topo [new Topography]
$topo load_flatgrid 500 500

DEPT. OF COMPUTER APPLICATIONS, BMSCE 27


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

#
# Create God
#
create-god $val(nn)
#
# Create the specified number of mobilenodes [$val(nn)] and "attach" them
# to the channel.
# Here two nodes are created : node(0) and node(1)
# configure node
$ns_ node-config \
-addressingType flat \
-adhocRouting DSDV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue \
-ifqLen 50 \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround \
-phyType Phy/WirelessPhy \
-channelType Channel/WirelessChannel \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace OFF \
-movementTrace ON
for {set i 0} {$i < $val(nn) } {incr i} {
set node_($i) [$ns_ node]
$node_($i) random-motion 1 ;# disable random motion
}
#
# Provide initial (X,Y, for now Z=0) co-ordinates for mobilenodes
#
$node_(0) set X_ 5.0
$node_(0) set Y_ 5.0
#$node_(0) set Z_ 0.0
$node_(1) set X_ 400.0
$node_(1) set Y_ 400.0

DEPT. OF COMPUTER APPLICATIONS, BMSCE 28


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

#$node_(1) set Z_ 0.0


$node_(2) set X_ 100.0
$node_(2) set Y_ 450.0
#$node_(2) set Z_ 0.0
#
# Now produce some simple node movements
# Node_(1) starts to move towards node_(0)
#
# This means at time 10.0 msec, node n will start to move toward destination
#from postion x=20.0 and y=20.0 at a speed 1.0m/s
$ns_ at 10.0 "$node_(0) setdest 20.0 20.0 1.0"
$ns_ at 20.0 "$node_(1) setdest 50.0 40.0 5.0"
$ns_ at 30.0 "$node_(2) setdest 200.0 400.0 20.0"
# Node_(1) then starts to move away from node_(0)
$ns_ at 100.0 "$node_(1) setdest 300.0 300.0 25.0"
# Setup traffic flow between nodes
# TCP connections between node_(0) and node_(1)
set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns_ attach-agent $node_(0) $tcp
$ns_ attach-agent $node_(1) $sink
$ns_ connect $tcp $sink
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns_ at 10.0 "$ftp start"
#
# Tell nodes when the simulation ends
#
for {set i 0} {$i < $val(nn) } {incr i} {
$ns_ at 150.0 "$node_($i) reset";
}
$ns_ at 150.0 "stop"
$ns_ at 150.01 "puts \"NS EXITING...\" ; $ns_ halt"
proc stop {} {
global ns_ tracefd namtrace
$ns_ flush-trace

DEPT. OF COMPUTER APPLICATIONS, BMSCE 29


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

close $tracefd
close $namtrace
}
puts "Starting Simulation..."
$ns_ run

DEPT. OF COMPUTER APPLICATIONS, BMSCE 30


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Trace File Explanation:


 Event gives you four possible symbols ‘+’ ‘-‘ ‘r’ ‘d’. These four symbols
correspond respectively to enqueued, dequeued, received and dropped.
 Time field gives the time at which the event occurs.
 From node field gives you the input node of the link at which the event occurs.
 To node field gives you the output node at which the event occurs.
 Packet type field shows the information about the packet type. i.e. whether the
packet is
UDP or TCP.
 Packet size field gives the packet size.
 Flag field give information about some flags.
 Fid field is the flow id(fid) for IPv6 that a user can set for each flow in a tcl
script. It is also used for specifying the color of flow in NAM display.
 The ninth field is the source address.
 The tenth field is the destination address.
 The eleventh field is the network layer protocol’s packet sequence number.
 The last field shows the unique id of packet.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 31


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Program 6
Simulate the working of the Distance Vector Routing algorithm for a
wired network in ns-2

#Create a simulator object


set ns [new Simulator]
#Tell the simulator to use Distance Vector Routing
$ns rtproto DV
#Open the trace file
set tracefd [open vector.tr w]
$ns trace-all $tracefd
#Open the nam trace file
set nf [open vector.nam w]
$ns namtrace-all $nf
#Define a 'finish' procedure
proc finish {} {
global ns nf tracefd
$ns flush-trace
#Close the trace file
close $nf
close $tracefd
#Execute nam on the trace file
exec nam vector.nam &
exit 0
}
#Create seven nodes
for {set i 0} {$i<7} {incr i} {
set n($i) [$ns node]
}
#Create links between the nodes
for {set i 0} {$i<7} {incr i} {
$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail
}
#Create a UDP agent and attach it to node n(0)
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0

DEPT. OF COMPUTER APPLICATIONS, BMSCE 32


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

# 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 n(3)
set null0 [new Agent/Null]
$ns attach-agent $n(3) $null0

#Connect the traffic source with the traffic sink


$ns connect $udp0 $null0
#Schedule events for the CBR agent and the network dynamics
$ns at 0.5 "$cbr0 start"
$ns rtmodel-at 1.0 down $n(1) $n(2)
$ns rtmodel-at 2.0 up $n(1) $n(2)
$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

DEPT. OF COMPUTER APPLICATIONS, BMSCE 33


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

DEPT. OF COMPUTER APPLICATIONS, BMSCE 34


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

DEPT. OF COMPUTER APPLICATIONS, BMSCE 35


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

Gephi( 0.9.2)
Gephi is an open-source software for network visualization and analysis. It helps data
analysts to intuitively reveal patterns and trends, highlight outliers and tells stories
with their
data. It uses a 3D render engine to display large graphs in real-time and to speed up
the
exploration. Gephi combines built-in functionalities and flexible architecture to:
 Explore
 Analyse
 Spatialize
 Filter
 Cluster
 Manipulate
 Export all types of networks.
Gephi is based on a visualize-and-manipulate paradigm which allow any user to
discover
networks and data properties. Moreover, it is designed to follow the chain of a case
study,
from data file to nice printable maps.
Gephi is a  free/libre software  distributed under the  GPL 3  (&quot;GNU General
Public License&quot;).
Tags: network, network science, infovis, visualization, visual analytics, exploratory
data
analysis, graph, graph viz, graph theory, complex network, software, open source,
science

Features
Gephi is a tool for data analysts and scientists keen to explore and understand graphs.
Like
Photoshop™ but for graph data, the user interacts with the representation,
manipulate the
structures, shapes and colors to reveal hidden patterns. The goal is to help data
analysts to
make hypothesis, intuitively discover patterns, isolate structure singularities or faults
during
data sourcing. It is a complementary tool to traditional statistics, as visual thinking
with

DEPT. OF COMPUTER APPLICATIONS, BMSCE 36


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

interactive interfaces is now recognized to facilitate  reasoning . This is a software


for  Exploratory Data Analysis , a paradigm appeared in the  Visual Analytics  field of
research.

7. Work on network visualization tool – Gephi to visualize the following data sets:
* Astro physics dataset
* Fiction novel dataset - Les Miserable
* Dolphin dataset
* Create your dataset and visualize using Gephi.

Les Miserable:

DEPT. OF COMPUTER APPLICATIONS, BMSCE 37


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

 Dolphin dataset

DEPT. OF COMPUTER APPLICATIONS, BMSCE 38


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

DEPT. OF COMPUTER APPLICATIONS, BMSCE 39


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

 Astro physics dataset

DEPT. OF COMPUTER APPLICATIONS, BMSCE 40


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

DEPT. OF COMPUTER APPLICATIONS, BMSCE 41


18MCA3PCNW: Computer Networks USN: 1BM19MCA15

 Create your dataset and visualize using Gephi.

DEPT. OF COMPUTER APPLICATIONS, BMSCE 42

You might also like