0% found this document useful (0 votes)
97 views15 pages

Lab 7

The document describes experiments conducted on different network topologies to analyze performance, including a point-to-point topology using UDP to simulate network performance, a dumbbell topology to measure congestion using the congestion window in Xgraph, and a star topology with two flows, one TCP and one UDP, to analyze performance. Code snippets are provided for simulating each network scenario in NS2.

Uploaded by

abhijeet
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)
97 views15 pages

Lab 7

The document describes experiments conducted on different network topologies to analyze performance, including a point-to-point topology using UDP to simulate network performance, a dumbbell topology to measure congestion using the congestion window in Xgraph, and a star topology with two flows, one TCP and one UDP, to analyze performance. Code snippets are provided for simulating each network scenario in NS2.

Uploaded by

abhijeet
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/ 15

2019

ABHIJEET NAWALE
16BCE2126

CSE1004:L31+32

NETWORK AND COMMUNICATION

EXPERIMENT NO-7
1. Construct point-to-point topology in which the agent should be UDP.
Simulate the Network scenario and analyse the network
performance.

Code:
# create a simulator Object
set ns [new Simulator]

# open a file for writing Nam Trace data


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

set nt [open out.tr w]


$ns trace-all $nt

# finish procedure that closes the trace file and starts nam
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}

# two nodes with a connected link


set n0 [$ns node]
set n1 [$ns node]

# connection between the two nodes with bandwidth of 1 Megabits, delay of 10ms and a DropTail
queue
$ns duplex-link $n0 $n1 1Mb 10ms DropTail

#Create a UDP agent and attach it to node n0


set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0

# Create a CBR traffic source and attach it to udp0


set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0

set null0 [new Agent/Null]


$ns attach-agent $n1 $null0

$ns connect $udp0 $null0

$ns at 0.5 "$cbr0 start"


$ns at 4.5 "$cbr0 stop"

#after 5 simulation time execute the finish procedure


$ns at 5.0 "finish"

#Starts the simulation


$ns run

Output:
3. Construct Dumbell topology for measuring congestion in the
network. Measure Congestion window using Xgraph. Simulate the
Network scenario and analyse the network performance.

Code:
#Create a simulator object
set ns [new Simulator]

$ns color 1 Blue


$ns color 2 Red

#Open the nam trace file


set nf [open out.nam w]
set trace [open trace.tr w]
set wndt [open WindowVsTime w]

$ns namtrace-all $nf


$ns trace-all $trace

#Define a 'finish' procedure


proc finish {} {
global ns nf trace
$ns flush-trace
#Close the trace file
close $nf
close $trace
#Execute nam on the trace file
exec nam out.nam &
exit 0
}

#Create two nodes

for {set i 1} { $i<=6} {incr i} {


set n($i) [$ns node]
}

#Create a duplex link between the nodes


$ns duplex-link $n(1) $n(2) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(3) 1Mb 10ms DropTail

$ns duplex-link $n(4) $n(5) 1Mb 10ms DropTail


$ns duplex-link $n(4) $n(6) 1Mb 10ms DropTail

$ns duplex-link $n(1) $n(4) 1Mb 10ms DropTail

#Create TCP connection between nodes 2 and 6


#Create a TCP agent and attach it to node 2
set tcp1 [new Agent/TCP]
$ns attach-agent $n(2) $tcp1
$tcp1 set packetSize_ 500
$tcp1 set fid_ 1

# Create a CBR traffic source and attach it to tdp0


set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1

#Create a TCP sink agent (a traffic sink) and attach it to node n1


set sink1 [new Agent/TCPSink]
$ns attach-agent $n(6) $sink1

$ns connect $tcp1 $sink1

# Create TCP connection between nodes 3 and 5

#Create a TCP agent and attach it to node 5 and 3


set tcp2 [new Agent/TCP]
$ns attach-agent $n(3) $tcp2
$tcp2 set packetSize_ 500
$tcp2 set fid_ 2

# Create a CBR traffic source and attach it to tdp0


set ftp2 [new Application/FTP]
$ftp2 attach-agent $tcp2

#Create a Null agent (a traffic sink) and attach it to node n1


set sink2 [new Agent/TCPSink]
$ns attach-agent $n(5) $sink2

$ns connect $tcp2 $sink2

proc throughput {totbytsent1 totbytsent2} {


global ns slot wndt tcp1 tcp2

set bytesperslot1 [expr 0.000008*([$tcp1 set ndatabytes_]-$totbytsent1)/$slot]; # bytes sent by


tcp1 per slot in Megabits per second
set totbytsent1 [$tcp1 set ndatabytes_]; # update total bytes sent by tcp1

set bytesperslot2 [expr 0.000008*([$tcp2 set ndatabytes_]-$totbytsent2)/$slot]; # bytes sent by


tcp2 per slot in megabits per seconds
set totbytsent2 [$tcp2 set ndatabytes_]; # update total bytes sent by tcp2

puts $wndt "[$ns now] [$tcp1 set cwnd_] $bytesperslot1 [$tcp2 set cwnd_] $bytesperslot2"

$ns at [expr [$ns now]+$slot] "throughput $totbytsent1 $totbytsent2"


}

set slot 0.2


#Schedule events for the CBR agent

$ns at 0 "$ftp1 start"


$ns at 1 "$ftp2 start"

$ns at 0 "throughput 0 0"


#Call the finish procedure after 5 seconds of simulation time

$ns at 5 "finish"

#Run the simulation


$ns run

Output:
2. Construct STAR Topology and create 2 flows where, one flow should
be using TCP, another flow using UDP. Simulate the Network
scenario and analyse the network performance

Code:
#simple.tcl

#create scheduler
set ns [new Simulator]

#choose colors
$ns color 0 blue
$ns color 1 red
$ns color 2 green

#turn tracing on
set f [open simple.tr w]
$ns trace-all $f
set nf [open simple.nam w]
$ns namtrace-all $nf

#create topology
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n2 5Mb 2ms DropTail


$ns duplex-link $n1 $n2 5Mb 2ms DropTail
$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
#limit queue size (otherwise unlimited)
#$ns queue-limit $n2 $n3 5

#adjust nam orientation


$ns duplex-link-op $n0 $n2 orient right-up
$ns duplex-link-op $n1 $n2 orient right-down
$ns duplex-link-op $n2 $n3 orient right

#turn nam visualization for n2-n3 queue


$ns duplex-link-op $n2 $n3 queuePos 0.5

#create udp agenet


set udp0 [new Agent/UDP]
#attach agent to node
$ns attach-agent $n0 $udp0
#select packet color for nam
$udp0 set class_ 0
#create a cbr application
set cbr0 [new Application/Traffic/CBR]
#attach application to agent
$cbr0 attach-agent $udp0

#create another udp/cbr agent/application


set udp1 [new Agent/UDP]
$ns attach-agent $n3 $udp1
$udp1 set class_ 1
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1

#create and attach null agents


set null0 [new Agent/Null]
$ns attach-agent $n3 $null0

set null1 [new Agent/Null]


$ns attach-agent $n1 $null1

$ns connect $udp0 $null0


$ns connect $udp1 $null1

#schedule the start of cbr traffic


$ns at 1.0 "$cbr0 start"
$ns at 1.1 "$cbr1 start"

#create and attach a TCP agent source/sink


set tcp [new Agent/TCP]
$tcp set class_ 2
set sink [new Agent/TCPSink]
$ns attach-agent $n0 $tcp
$ns attach-agent $n3 $sink
$ns connect $tcp $sink

#attach an ftp application to the TCP agent


set ftp [new Application/FTP]
$ftp attach-agent $tcp

#schedule start of ftp application


$ns at 1.2 "$ftp start"

#schedule end of ftp application


$ns at 5.0 "$ftp stop"

#$ns at 5.0 "$ns detach-agent $n0 $tcp ; $ns detach-agent $n3 $sink"

#print the (default) cbr values


puts [$cbr0 set packetSize_]
puts [$cbr0 set interval_]

$ns at 6.0 "finish"


proc finish {} {
global ns f nf
$ns flush-trace
close $f
close $nf

#puts "running nam..."


exec nam simple.nam &
exit 0
}

$ns run

Output:

You might also like