[Free Script] NS-2 Multicast Scenario with Web Traffic | Wired MANETs


# Create scheduler

#Create an event scheduler wit multicast turned on

set ns [new Simulator -multicast on]

#$ns multicast

#Turn on Tracing

set tf [open output.tr w]

$ns trace-all $tf

# Turn on nam Tracing

set fd [open mcast.nam w]

$ns namtrace-all $fd

# Create 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]

set n6 [$ns node]

set n7 [$ns node]

# Create links

$ns duplex-link $n0 $n2 1.5Mb 10ms DropTail

$ns duplex-link $n1 $n2 1.5Mb 10ms DropTail

$ns duplex-link $n2 $n3 1.5Mb 10ms DropTail

$ns duplex-link $n3 $n4 1.5Mb 10ms DropTail

$ns duplex-link $n3 $n7 1.5Mb 10ms DropTail

$ns duplex-link $n4 $n5 1.5Mb 10ms DropTail

$ns duplex-link $n4 $n6 1.5Mb 10ms DropTail


$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 $n3 $n4 orient right
$ns duplex-link-op $n3 $n7 orient down
$ns duplex-link-op $n4 $n5 orient right-up
$ns duplex-link-op $n4 $n6 orient right-down



# Routing protocol: say distance vector

#Protocols: CtrMcast, DM, ST, BST

set mproto DM

set mrthandle [$ns mrtproto $mproto {}]

# Allocate cluster addresses

set cluster1 [Node allocaddr]

set cluster2 [Node allocaddr]

# UDP Transport agent for the traffic source

set www_UDP_agent [new Agent/UDP]

$ns attach-agent $n0 $www_UDP_agent

$www_UDP_agent set dst_addr_ $cluster1

$www_UDP_agent set dst_port_ 0

set www_CBR_source [new Application/Traffic/CBR]

$www_CBR_source attach-agent $www_UDP_agent
$www_CBR_source set packetSize_ 48

$www_CBR_source set interval_ 50ms

# Transport agent for the traffic source

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

$udp1 set dst_addr_ $cluster2

$udp1 set dst_port_ 0

set cbr2 [new Application/Traffic/CBR]

$cbr2 attach-agent $udp1

# Create receiver

set rcvr1 [new Agent/Null]

$ns attach-agent $n5 $rcvr1

$ns at 1.0 "$n5 join-cluster $rcvr1 $cluster1"

set rcvr2 [new Agent/Null]

$ns attach-agent $n6 $rcvr2

$ns at 1.5 "$n6 join-cluster $rcvr2 $cluster1"

set rcvr3 [new Agent/Null]

$ns attach-agent $n7 $rcvr3

$ns at 2.0 "$n7 join-cluster $rcvr3 $cluster1"

set rcvr4 [new Agent/Null]

$ns attach-agent $n5 $rcvr1

$ns at 2.5 "$n5 join-cluster $rcvr4 $cluster2"

set rcvr5 [new Agent/Null]

$ns attach-agent $n6 $rcvr2

$ns at 3.0 "$n6 join-cluster $rcvr5 $cluster2"

set rcvr6 [new Agent/Null]

$ns attach-agent $n7 $rcvr3

$ns at 3.5 "$n7 join-cluster $rcvr6 $cluster2"

$ns at 4.0 "$n5 leave-cluster $rcvr1 $cluster1"

$ns at 4.5 "$n6 leave-cluster $rcvr2 $cluster1"

$ns at 5.0 "$n7 leave-cluster $rcvr3 $cluster1"

$ns at 5.5 "$n5 leave-cluster $rcvr4 $cluster2"

$ns at 6.0 "$n6 leave-cluster $rcvr5 $cluster2"

$ns at 6.5 "$n7 leave-cluster $rcvr6 $cluster2"

# Schedule events

$ns at 0.5 "$www_CBR_source start"

$ns at 9.5 "$www_CBR_source stop"

$ns at 0.5 "$cbr2 start"

$ns at 9.5 "$cbr2 stop"

#post-processing

$ns at 10.0 "finish"

proc finish {} {

global ns tf

$ns flush-trace

close $tf

exec nam mcast.nam &

exit 0

}

# For nam

#Colors for packets from two mcast clusters

$ns color 10 red

$ns color 11 green

$ns color 30 purple

$ns color 31 green

# Manual layout: order of the link is significant!

#$ns duplex-link-op $n0 $n1 orient right

#$ns duplex-link-op $n0 $n2 orient right-up

#$ns duplex-link-op $n0 $n3 orient right-down

# Show queue on simplex link n0->n1

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

# Cluster 0 source

$www_UDP_agent set fid_ 10

$n0 color red

$n0 label "Source 1"

# Cluster 1 source

$udp1 set fid_ 11

$n1 color green

$n1 label "Source 2"

$n5 label "Receiver 1"

$n5 color blue

$n6 label "Receiver 2"

$n6 color blue

$n7 label "Receiver 3"

$n7 color blue

#$n2 add-mark m0 red

#$n2 delete-mark m0"

# Animation rate

$ns set-animation-rate 3.0ms

$ns run

No comments:

Post a Comment

A Compendium of Epigrams Vol:1

Buy From Amazon  Kindle Edition Sneak Peak of Second BOOK