#create links between wired and BS nodes
$ns_ duplex-link $W(0) $W(1) 5Mb 3ms DropTail
$ns_ duplex-link $W(1) $W(2) 5Mb 4ms DropTail
$ns_ duplex-link $W(2) $BS(0) 5Mb 2ms DropTail
$ns_ duplex-link $W(0) $BS(1) 5Mb 2ms DropTail

$ns_ duplex-link-op $W(0) $W(1) orient right
$ns_ duplex-link-op $W(1) $W(2) orient right
$ns_ duplex-link-op $W(2) $BS(0) orient right
$ns_ duplex-link-op $W(0) $BS(1) orient up


####################################################################
# setup UDP connections
set udp1 [new Agent/UDP]
$udp1 set fid_ 2222
set lm [new Agent/LossMonitor]
$ns_ attach-agent $node_(0) $udp1
$ns_ attach-agent $node_(1) $lm
$ns_ connect $udp1 $lm

# Mandatory
$node_(0) 2222 speech rate_ $opt(rate)

set cbr1 [new Application/Traffic/CBR]
$cbr1 set rate_ $opt(rate)
$cbr1 attach-agent $udp1

$ns_ color 2222 blue
$ns_ at $opt(start) "$cbr1 start"
#$ns_ at 1.5 "$ns_ detach-agent $node_(0) $udp1"

####################################################################
## setup UDP connections
set udp2 [new Agent/UDP]
$udp2 set fid_ 3333
set lm2 [new Agent/LossMonitor]
$ns_ attach-agent $W(1) $udp2
$ns_ attach-agent $node_(1) $lm2
$ns_ connect $udp2 $lm2

# Mandatory
$W(1) 3333 http rate_ $opt(rate2)

set cbr2 [new Application/Traffic/CBR]
$cbr2 set rate_ $opt(rate2)
$cbr2 attach-agent $udp2

$ns_ color 3333 red
$ns_ at $opt(start) "$cbr2 start"
#$ns_ at 1.7 "$ns_ detach-agent $W(1) $udp2"

####################################################################
## setup UDP connections
set udp3 [new Agent/UDP]
$udp3 set fid_ 4444
set lm3 [new Agent/LossMonitor]
$ns_ attach-agent $node_(0) $udp3
$ns_ attach-agent $W(1) $lm3
$ns_ connect $udp3 $lm3

# Mandatory
$node_(0) 4444 mail rate_ $opt(rate3)

set cbr3 [new Application/Traffic/CBR]
$cbr3 set rate_ $opt(rate3)
$cbr3 attach-agent $udp3

$ns_ color 4444 purple
$ns_ at [expr $opt(start)+0.05]  "$cbr3 start"
#$ns_ at 1.4 "$ns_ detach-agent $node_(1) $udp3"

####################################################################
