Tuesday 8 January 2013

multicast.tcl

 

 

#   Video               MyUdpSink
#   W(0) ------ HA------MH(0)
#  sorce -----> HA------MH

set opt(num_FA) 1

#loss_model: 0 for uniform distribution, 1 for GE model
set loss_model  0

#comm_type: 0 for broacdcast, 1 for unicast
set comm_type 0


set ns_ [new Simulator]


$ns_ node-config -addressType hierarchical


AddrParams set domain_num_ 2
lappend cluster_num 1 1
AddrParams set cluster_num_ $cluster_num
lappend eilastlevel 1 2
AddrParams set nodes_num_ $eilastlevel


set tracefd [open bsc_multicast.tr w]
$ns_ trace-all $tracefd


set opt(nnn) 1


set topo [new Topography]
$topo load_flatgrid 100 100

#create god
set god_ [create-god [expr $opt(nnn)+$opt(num_FA)]]

# wired nodes
set W(0) [$ns_ node 0.0.0]

# create channel
set chan_ [new Channel/WirelessChannel]


$ns_ node-config     -mobileIP ON \
                      -adhocRouting NOAH \
                  -llType LL \
                  -macType Mac/802_11 \
                  -ifqType Queue/DropTail/PriQueue \
                  -ifqLen 2000 \
                  -antType Antenna/OmniAntenna \
                          -propType Propagation/TwoRayGround \
                          -phyType Phy/WirelessPhy \
                  -channel $chan_ \
                         -topoInstance $topo \
                  -wiredRouting ON\
                          -agentTrace OFF \
                  -routerTrace OFF \
                  -macTrace OFF


set HA [$ns_ node 1.0.0]
set HAnetif_ [$HA set netif_(0)]
$HAnetif_ set-error-level 0 0 0 0 $loss_model


$ns_ node-config -wiredRouting OFF
set MH(0) [$ns_ node 1.0.1]
set MHnetif_(0) [$MH(0) set netif_(0)]

#Initially, set the error rate to 0
$MHnetif_(0) set-error-level 0 0 0 0 $loss_model

#At 10.0 second, set the error rate to 0.5
$ns_ at 10.0 "$MHnetif_(0) set-error-level 0 0 0.5 0 $loss_model"

#At 40.0 second, set the error rate to 0
$ns_ at 40.0 "$MHnetif_(0) set-error-level 0 0 0 0 $loss_model"


[$MH(0)  set regagent_] set home_agent_ [AddrParams addr2id [$HA node-addr]]


$HA set X_ 100.0
$HA set Y_ 100.0
$HA set Z_ 0.0

$MH(0) set X_ 80.0
$MH(0) set Y_ 80.0
$MH(0) set Z_ 0.0

$ns_ duplex-link $W(0) $HA 10Mb 10ms myfifo
set q1       [[$ns_ link $W(0) $HA] queue]

set udp [new Agent/mUDP]
#set the sender trace file name to sd
$udp set_filename sd
$ns_ attach-agent $W(0) $udp

set forwarder_ [$HA  set forwarder_]
puts [$forwarder_ port]
$ns_ connect $udp $forwarder_
$forwarder_ dst-addr [AddrParams addr2id [$MH(0) node-addr]]
$forwarder_ comm-type $comm_type

set null [new Agent/mUdpSink]
#set the receiver filename to rd
$null set_filename rd
$ns_ attach-agent $MH(0) $null
$ns_ connect $udp $null

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

$ns_ at 0.0 "$cbr start"
$ns_ at 50.0 "$cbr stop"
$ns_ at 50.1 "$MH(0) reset";
$ns_ at 50.0001 "$W(0) reset"
$ns_ at 50.0002 "stop "
$ns_ at 50.0003  "$ns_  halt"

proc stop {} {
    global ns_
    global tracefd
   
    close $tracefd
}

$ns_ run

 

No comments:

Post a Comment